gpt4 book ai didi

elasticsearch - Elasticsearch bool查询必须匹配单个字段单个术语,另一个字段带有OR术语

转载 作者:行者123 更新时间:2023-12-02 22:48:59 24 4
gpt4 key购买 nike

我想找到一个带有名称的文档,该文档包含'Bob',并且其位置位于'paducah'或'smyrna'中。

这是我现在拥有的:

query: {
bool: {
must: [
{ match: { name: 'bob' } },
{ match: { location: ['paducah', 'smyrna'] } }
],
},
},

我知道问题出在 位置数组中,因为如果我将其更改为没有数组的单个元素,查询就可以正常工作。

This is the closest answer i could find

它不起作用,我收到以下错误:

[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]

最佳答案

您可以尝试以下查询:

{
"query": {
"bool": {
"must": [
{ "match": { "name": "bob" } }
],
"should": [
{ "match": { "location": "paducah" }},
{ "match": { "location": "smyrna" }}
],
"minimum_should_match": 1
}
}
}

关于elasticsearch - Elasticsearch bool查询必须匹配单个字段单个术语,另一个字段带有OR术语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45266655/

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