[英]Elasticsearch javascript search field in array
這直接來自elasticsearch文檔。
client.search({
index: 'myindex',
body: {
query: {
match: {
title: 'test'
}
}
}
}, function (error, response) {
// ...
});
我想要達到的目標是相同的,但是要搜索多個標題。
if title in ['title1', 'title2', 'title3']
但是title: ['title1', 'title2', 'title3']
作為查詢字符串給出了錯誤。
還有一個建議使用過濾器,但似乎沒有任何效果。 任何建議將不勝感激。
正確的方法是將所有標題值附加到查詢字符串中,因為它將被分析,因此title
字段將與每個標記匹配。
client.search({
index: 'myindex',
body: {
query: {
match: {
title: 'title1 title2 title3'
}
}
}
}, function (error, response) {
// ...
});
更新
如果搜索未分析的值,則應優先使用terms
查詢:
client.search({
index: 'myindex',
body: {
query: {
terms: {
title: ['title1', 'title2', 'title3']
}
}
}
}, function (error, response) {
// ...
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.