henry blake
henry blake

Reputation: 63

How to aggregate and search on the same field in elasticsearch?

I made the field on which aggregation is to be done as "not_analyzed". But now the search is not working on the field. How can I make aggregation working in the field and also searchable?

Upvotes: 2

Views: 60

Answers (1)

Val
Val

Reputation: 217564

You simply need to map your field as a string multi field with an analyzed part (for search) and a non analyzed part (for aggregations). Basically like this:

{
    "my_field": {
        "type": "string",
        "fields": {
            "raw": {
                "type": "string",
                "index": "not_analyzed"
            }
        }
    }
}

Your query would then search on the my_field field, and aggregate on the my_field.raw sub-field.

Upvotes: 2

Related Questions