ElasticSearch聚合:每个聚合排除一个过滤器 [英] ElasticSearch aggregation: exclude one filter per aggregation

查看:154
本文介绍了ElasticSearch聚合:每个聚合排除一个过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想过滤掉字段A等于a的文档,我想同时打开字段A,不包括以前的过滤器。
我知道你可以把过滤器'外部'查询,以获得没有应用过滤器的方面,如:



ElasticSearch

  {
query:{match_all:{}},
filter:{term:{ A:a}},
facets:{
A:{terms:{field:A}} //这应该排除过滤器A :a
}
}

SOLR

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

这是非常好的,但如果我有多个过滤器和面,每个应该排除彼此?
示例:

  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

就是说,对于facet AI,要保留除A:a之外的所有过滤器,除B外:b,等等。
最明显的方法是做n个查询(每个n面都有一个),但是我想远离这个。

解决方案

全局范围提供对每个文档的访问,然后可以添加用于主查询的相同过滤器。



此相关主题全球范围的示例



您是否可以就post_filter提供有关性能问题的反馈?


I want to filter out documents whose field 'A' is equal to 'a', and I want to facet the field 'A' at the same time, excluding of course the previous filter. I know that you can put the filter 'outside' the query in order to get the facets without that filter applied, like:

ElasticSearch

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

SOLR

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

This is very nice, but what happens if i have multiple filters and facets that each one 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 facet A I want to keep all filters except A:a, for facet B all except B:b, and so on. The most obvious way would be to do n queries (one per each of the n facets), but I'd like to stay away from that.

解决方案

The global scope provides access to every document, you can then add the same filters you used for the main query.

I gave an example with global scope in this related topic

Could you give any feedback about performance issue with post_filter ?

这篇关于ElasticSearch聚合:每个聚合排除一个过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆