2017-07-07 107 views
0

你好Elasticsearch大师,我需要你的帮助! 我们使用Elasticsearch V5.4和 我有多个嵌套类型在elasticsearch的形式:Elasticsearch post_filter对嵌套类型没有过滤聚合

"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?

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

回答

0

注意:我没有任何搜索包体验。

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

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

所以这是Elasticsearch观点的预期行为。