简体   繁体   English

嵌套类型上的Elasticsearch post_filter不对聚合进行过滤

[英]Elasticsearch post_filter on nested types not filtering on aggregations

Hello Elasticsearch gurus, I need your help! 您好Elasticsearch专家,我需要您的帮助! We're using Elasticsearch v5.4 and I have multiple nested types in elasticsearch in the form of: 我们使用的是Elasticsearch v5.4,而我在Elasticsearch中有多种嵌套类型,其形式为:

"testLookup" : [
  {
    "id": 1001,
    "name": "test1"
  },
  {
    "id": 1002,
    "name": "test2"
  }
]

which I'm trying to display the names as checkbox options in a filter. 我正在尝试将名称显示为过滤器中的复选框选项。

I was trying to use the post_filter top level element to basically filter the aggregations so I can update and display ONLY the affected filter options, kinda like how it is being used on this demo site: http://demo.searchkit.co 我试图使用post_filter顶级元素来基本过滤聚合,因此我只能更新和显示受影响的过滤器选项,有点像在此演示站点上的使用方式: http : //demo.searchkit.co

  "post_filter": {
    "bool":{
      "must": [
     {    
      "nested" : {
        "path" : "testLookup",
        "query": {
          "bool": {
            "filter":{ 
              "bool":{
                "should":[
                        { "term":  { "perTestLookup.name.keyword": "Adele"}}
         ]
            }
        }
      }
    }
    }
     },
              {    
    "nested" : {
      "path" : "testLookup2",
      "query": {
        "bool": {
          "filter":{ 
            "bool":{
              "should":[         
                { "term":  { "perTestLookup2.name.keyword": "Gene" }}
         ]
            }
        }
      }
    }
    }     
    }
  ]
 }
}

If i'm not mistaken I think what the post_filter does is apply the filter for each of the aggregations before the search request is sent, which you can observe that by looking into the request payload of the search filter after you click one of the filter checkboxes. 如果我没记错的话,我认为post_filter的作用是在发送搜索请求之前将过滤器应用于每个聚合,您可以通过在单击其中一个过滤器后查看搜索过滤器的请求有效负载来观察到这一点复选框。

However, I can not get the post_filter to apply the filters to the aggregations, the filters are just not being applied. 但是,我无法获取post_filter将筛选器应用于聚合,只是未应用筛选器。 Why is this the case? 为什么会这样呢? is post_filter for nested types not supported? 不支持嵌套类型的post_filter吗?

Any tips or guidance will be greatly appreciated. 任何提示或指导将不胜感激。 Thank you! 谢谢!

Note: I do not have any searchkit experience. 注意:我没有任何Searchkit经验。

The post_filter in an Elasticsearch request is executed after the aggregations are calculated to reduce the hits result further. 在计算聚合以进一步减少命中结果之后,将执行Elasticsearch请求中的post_filter See the docs about post_filter . 请参阅有关post_filter的文档。

The idea behind this is the fact that in a faceted search (ie imagine filtering by category), you still want to retrieve that category counts for all categories in your aggregations, but you want to filter for that clicked category in your the documents you are searching. 其背后的想法是,在多面搜索(即按类别过滤)中,您仍然希望检索聚合中所有类别的类别计数,但是您想为文档中的单击类别进行过滤搜索。

So this is expected behaviour from the Elasticsearch perspective. 因此,这是从Elasticsearch角度来看的预期行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM