ElasticSearch Aggregation: Exclude one filter for aggregation

I want to filter documents whose field "A" is equal to "a", and I want an aspect of field "A" at the same time, excluding, of course, the previous filter. I know that you can put a filter β€œoutside” the query to get faces without applying this filter, for example:

Elasticsearch

{ "query : { "match_all" : { } }, "filter" : { "term : { "A" : "a" } }, "facets" : { "A" : { "terms" : { "field" : "A" } } //this should exclude the filter A:a } } 

GUMZ

 &q=:*:* &fq={!tag=Aa}A:a &facet=true&facet.field={!ex=Aa}A 

This is very nice, but what happens if I have several filters and faces that each should exclude each other? Example:

 filter=A:a filter=B:b filter=C:c facet={exclude filter A:a}A facet={exclude filter B:b}B facet={exclude filter C:c}C 

That is, for face A, I want to save all filters except A: a, for facet B, except B: b, and so on. The most obvious way would be to make n queries (one for each of the n aspects), but I would like to avoid this.

+5
source share
1 answer

The global area provides access to each document, then you can add the same filters that you used for the main request.

I gave an example with a global scope in this related topic

Could you give any feedback on performance with post_filter?

+1
source

Source: https://habr.com/ru/post/1204809/


All Articles