php - Elastic Search / Elasica php - 对包含 NULL 的字段的 OR 查询不起作用
问题描述
如何仅查询 location_idnull
或locations.country_id 在一组给定 ID 中的文档?这是当前的查询,但它根本没有返回任何内容......如果我从查询中删除 location_id 它可以工作并至少返回与国家 ID 匹配的文档。
{
"bool":{
"must":[
{
"bool":{
"must_not":[
{
"exists":{
"field":"location_id"
}
}
],
"must":[
{
"terms":{
"locations.country_id":[
18
]
}
}
]
}
}
]
}
}
解决方案
在弹性搜索中,必须是 AND 并且应该表现得像 OR 您的查询转换为 locationId 是 null AND locations.country_id 在 [id 集] 中。必须需要替换为应该。
询问:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"exists": {
"field": "location_id"
}
}
]
}
},
{
"terms": {
"locations.country_id": [
18
]
}
}
],
"minimum_should_match": 1
}
}
}
推荐阅读
- python - 我使用熊猫附加到 DataFrame 的数据(数字)
- sql - 设计具有良好数据结构的调查构建器?
- reactjs - 具有 Redux 集成的 ag-Grid 服务器端行模型
- swift - unwind segue 冻结 UI
- rest - 刷新从 HTTP 请求中提取的 SwiftUI 视图中的数据
- c++ - Visual Studio 不更新项目内的文件夹
- react-native - 如何在博览会中启用自动重新加载?
- python - 不了解 Django 表单并使用,有没有办法忽略它们并仍然保存表单中上传的文件?
- ios - 为什么物体检测会导致找到多个物体?
- api - 在 react-native 中集成 Easypaisa