2017-05-28 127 views
1

例如,我試圖在elasticsearch 5.1中構建查詢 - 給我所有作者在預定義作者列表中的書籍。使用單筆者在工作時,而是傳遞一個數組的時候 - 我沒有得到任何結果Elasticsearch - 搜索數組中的值的一部分的記錄

let query = JSON.stringify({ 
     "size": 10000, 
     "query": { 
      "bool": { 
       "must": [{ 
         "term": { 
          "recordtype": "Book" 
         } 
        }, 
        { 
         "term": { 
          "recordLocation": "library" 
         } 
        } 
       ], 
       "filter": { 
        "term": { 
         "author": authors 
        } 
       } 
      } 
     } 
    }); 

其中作者們let authors = ['a', 'b', 'c', 'd']

什麼我錯過?

+2

替換項查詢的條款查詢如下圖所示' 「術語」:{ 「作者」:作者 }'和' 「術語」:{ 「作者」:['a','b','c','d'] }' – avr

+0

謝謝 - 它解決了它 –

+0

很高興!它幫助你:) – avr

回答

0

查找多個關鍵字時使用Terms Query

更換你的過濾器的查詢,如下圖所示:

"filter": { 
    "terms": { 
     "author":["a", "b, "c"] 
     } 
}