如何仅查询location_id为null
或 location.country_id在一组给定ID中的文档?这是当前查询,但是什么也不会返回。...如果我从查询中删除了location_id,它将起作用并至少返回与国家ID匹配的文档。
{
"bool":{
"must":[
{
"bool":{
"must_not":[
{
"exists":{
"field":"location_id"
}
}
],
"must":[
{
"terms":{
"locations.country_id":[
18
]
}
}
]
}
}
]
}
}
最佳答案
在Elasticsearch中,Must为AND,且行为类似于OR
您的查询翻译为locationId为null ANDlocations.country_id在[ID集]中。
必须用应替换。
查询:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"exists": {
"field": "location_id"
}
}
]
}
},
{
"terms": {
"locations.country_id": [
18
]
}
}
],
"minimum_should_match": 1
}
}
}
关于php - Elastic Search/Elasica php-包含NULL的字段的OR查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61658459/