我想用在 jboss 服务器上运行的 java 7 应用程序更改弹性搜索中的数据。在弹性搜索索引中有两个字段,分别是 city_id 和 country_id。通过新的实现,我需要搜索 city_name is null 或 country_name null 记录并用相关的 city_name 和 country_name 更新它们。
POST index/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"timestamp": {
"gte": "2023-02-27 06:40:00"
}
}
}
],
"must_not": [
{
"exists": {
"field": "city_name"
}
},
{
"exists": {
"field": "country_name"
}
}
]
}
},
"size": 3,
"sort": [{
"timestamp": {
"order": "asc"
}
}
]
}
我正在使用这个搜索查询。但是通过这个搜索 city_name 和 country_name 都是 null 记录。我想为此获得OR(city_name OR country_name null)条件。
有人可以帮我解决这个问题吗?
谢谢。
由于 should 大致等同于布尔值 OR,根据 this,您可以尝试使用嵌套的
should
-> bool
-> must_not
子句。例子:
{
"query": {
"bool": {
"should": [{
"bool": {
"must_not": {
"exists": {
"field": "city_name"
}
}
}
},
{
"bool": {
"must_not": {
"exists": {
"field": "country_name"
}
}
}
}
]
}
}
}