gpt4 book ai didi

elasticsearch - Elasticsearch将2个过滤器上下文查询与OR组合在一起

转载 作者:行者123 更新时间:2023-12-03 01:15:38 24 4
gpt4 key购买 nike

我有以下查询,它可以正确查找具有NAME字段但没有NEW_NAME字段的文档:

"query": {
"bool": {
"filter": {
"exists": {
"field": "NAME"
}
},
"must_not": {
"exists": {
"field": "NEW_NAME"
}
}
}
}
我想用另一个查询扩展这个查询(通过或),以便它也查找具有DOB字段但不具有NEW_DOB字段的文档,例如
"query": {
"bool": {
"filter": {
"exists": {
"field": "DOB"
}
},
"must_not": {
"exists": {
"field": "NEW_DOB"
}
}
}
}
所以我的查询是这样的:
(NAME exists AND NEW_NAME !exist) OR (DOB exists AND NEW_DOB !exist)
我想我需要使用应该结合以上两个查询,只是不确定确切如何,这不起作用:
"query": {
"bool": {
"should": [
{
"filter": {
"exists": {
"field": "NAME"
}
},
"must_not": {
"exists": {
"field": "NEW_NAME"
}
}
},
{
"filter": {
"exists": {
"field": "DOB"
}
},
"must_not": {
"exists": {
"field": "NEW_DOB"
}
}
}
]
}
}

最佳答案

{
"query": {
"bool": {
"should": [
{
"bool": {
"filter": {
"exists": {
"field": "NAME"
}
},
"must_not": {
"exists": {
"field": "NEW_NAME"
}
}
}
},
{
"bool": {
"filter": {
"exists": {
"field": "DOB"
}
},
"must_not": {
"exists": {
"field": "NEW_DOB"
}
}
}
}
]
}
}
}
我只是结合了必须和应该。
必须= AND
应该= OR

关于elasticsearch - Elasticsearch将2个过滤器上下文查询与OR组合在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62674987/

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