gpt4 book ai didi

javascript - Elasticsearch javascript 数组中的搜索字段

转载 作者:行者123 更新时间:2023-12-03 06:12:09 25 4
gpt4 key购买 nike

这直接来自elasticsearch documentation.

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) {
// ...
});

关于javascript - Elasticsearch javascript 数组中的搜索字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39270808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com