Elasticsearch Aggregation Query with multiple excludes Elasticsearch Aggregation Query with multiple excludes elasticsearch elasticsearch

Elasticsearch Aggregation Query with multiple excludes


The exclude parameter is a regular expression, so you could use a regular expression that exhaustively lists all choices:

"exclude" :    "corporation|inc\\.|inc|co|company|the|industries|incorporated|international"

Doing this generically, it's important to escape values (e.g., .). If it is not generically generated, then you could simplify some of these by grouping them (e.g., inc\\.? covers inc\\.|inc, or the more complicated: co(mpany|rporation)?). If this is going to run a lot, then it's probably worth testing how the added complexity effects performance.

There are also optional flags that can be applied, which are the options that exist in Java Pattern. The one that might come in handy is CASE_INSENSITIVE.

"exclude" : {    "pattern" : "...expression as before...",    "flags" : "CASE_INSENSITIVE"}


this is old question, but newer answer: array currently supported for exclude exact match of list items

thus the array syntax in the OP is now valid and works as expected (in addition to valid regular expression answer too)

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_filtering_values_with_exact_values