gpt4 book ai didi

elasticsearch - 如何在 Elasticsearch 查询中组合 "must"和 "should"?

转载 作者:行者123 更新时间:2023-12-02 23:58:02 26 4
gpt4 key购买 nike

我需要在 Elasticsearch 查询 DSL 中“翻译”这个伪 SQL 查询:

select from invoice where invoiceType = 'REGULAR' and receiver = 'CUSTOMER' and (invoiceStatus = 'DISPATCHED' or invoiceStatus = 'PAYED')



我有这个:
{
"query": {
"bool": {
"must": [
{ "match": { "invoiceType": "REGULAR" }},
{ "match": { "receiver": "CUSTOMER" }},
{ "bool" : {
"should": [
{"match" : {"invoiceStatus": "DISPATCHED"}},
{"match" : {"invoiceStatus": "PAYED"}}
]
}
}
]
}
}
}

该查询返回 0 个结果,但我知道有很多结果与我要搜索的内容相匹配。 AFAIK, must就像'AND'和 should像“或”。我错过了什么?

最佳答案

不确定它是否适合您,但您可以尝试一下,看看会得到什么?虽然我做了一些改变 matchterm .希望这会帮助你。

GET /invoice/_search
{
"query" : {
"constant_score" : {
"filter" : {
"bool" : {
"must" : [
{ "term" : {"invoiceType" : "REGULAR"}},
{ "term": { "receiver": "CUSTOMER" }},
{ "bool" : {
"should" : [
{"terms": {"invoiceStatus": ["DISPATCHED","PAYED"]}}
]
}}
]
}
}
}
}
}


GET /invoice/_search
{
"query" : {
"constant_score" : {
"filter" : {
"bool" : {
"must" : [
{ "term" : {"invoiceType" : "REGULAR"}},
{ "term": { "receiver": "CUSTOMER" }},
{ "bool" : {
"should" : [
{"term": {"invoiceStatus": "DISPATCHED"}},
{"term": {"invoiceStatus": "PAYED"}}
]
}}
]
}
}
}
}
}

关于elasticsearch - 如何在 Elasticsearch 查询中组合 "must"和 "should"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51616794/

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