【问题标题】:Elasticsearch post_filter on nested types not filtering on aggregations嵌套类型上的 Elasticsearch post_filter 不过滤聚合
【发布时间】:2017-07-08 05:39:27
【问题描述】:

您好 Elasticsearch 专家,我需要您的帮助! 我们正在使用 Elasticsearch v5.4 和 我在 elasticsearch 中有多种嵌套类型,形式为:

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

我正在尝试将名称显示为过滤器中的复选框选项。

我试图使用 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" }}
         ]
            }
        }
      }
    }
    }     
    }
  ]
 }
}

如果我没记错的话,我认为 post_filter 所做的是在发送搜索请求之前为每个聚合应用过滤器,您可以通过在单击一个后查看搜索过滤器的请求有效负载来观察这一点过滤器复选框。

但是,我无法让 post_filter 将过滤器应用于聚合,只是没有应用过滤器。为什么会这样?不支持嵌套类型的 post_filter 吗?

我们将不胜感激任何提示或指导。谢谢!

【问题讨论】:

    标签: elasticsearch elasticsearch-5


    【解决方案1】:

    注意:我没有任何 searchkit 经验。

    Elasticsearch 请求中的post_filter 在计算聚合后执行,以进一步减少命中结果。请参阅有关 post_filter 的文档。

    这背后的想法是,在分面搜索(即想象按类别过滤)中,您仍然希望检索聚合中所有类别的类别计数,但您希望在您的您正在搜索的文档。

    所以从 Elasticsearch 的角度来看,这是预期的行为。

    【讨论】:

      猜你喜欢
      • 2018-01-30
      • 2014-12-31
      • 2019-05-22
      • 2015-11-14
      • 2017-04-15
      • 1970-01-01
      • 2017-09-13
      • 2021-04-19
      • 1970-01-01
      相关资源
      最近更新 更多