2017-07-07 106 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觀點的預期行爲。