BuffaloDev
BuffaloDev

Reputation: 483

Elasticsearch agg filter using an array of values

{ "colors":["red","black","blue"] }
{ "colors":["red","black"] }
{ "colors":["red"] }
{ "colors":["orange, green"] }
{ "colors":["purple"] }

How can I run an agg that filters for specific values contained in the array field? For example, I only want the count of "red" and wish to exclude its other siblings from the aggregation result.

Note: I cannot use an "include" pattern for "red". This example is simplistic, the real-world example has a long list of string values that are unique.

I would like to filter the agg using an array of string values.

Upvotes: 1

Views: 791

Answers (1)

jaspreet chahal
jaspreet chahal

Reputation: 9109

From docs

For matching based on exact values the include and exclude parameters can simply take an array of strings that represent the terms as they are found in the index:

{
  "aggs": {
    "colors": {
      "terms": {
        "field": "colors",
        "include": [ "red","black" ]
      }
    }
  }
}

Upvotes: 1

Related Questions