Husmus
Husmus

Reputation: 951

Elasticsearch - Making a field aggregatable but not searchable

My elasticsearch data has a large number of fields that I don't need to search by. But I would like to get aggregations like percentiles, median, count, avg. etc. on these fields.

Is there a way to disable searchability of a field but let it still be aggregatable?

Upvotes: 1

Views: 1668

Answers (2)

Nishant
Nishant

Reputation: 7874

Most of the fields are indexed by default and hence make them searchable. If you want to make a field non-searchable all you have to do is set its index param as false and doc_values to true. As per elastic documentation:

All fields which support doc values have them enabled by default.

So you need not explicitly set "doc_values": true for such fields.

For e.g.

{
  "mappings": {
    "_doc": {
      "properties": {
        "only_agg": {
          "type": "keyword",
          "index": false
        }
      }
    }
  }
}

If you try to search on field only_agg in above example, elastic will throw exception with reason as below:

Cannot search on field [only_agg] since it is not indexed.

Upvotes: 1

LeBigCat
LeBigCat

Reputation: 1770

yeah take a look at doc_value: https://www.elastic.co/guide/en/elasticsearch/reference/current/doc-values.html

Upvotes: 0

Related Questions