Search 弹性搜索:匹配不同嵌套对象中的字段
我是弹性搜索新手,这是我的用户索引:Search 弹性搜索:匹配不同嵌套对象中的字段,search,Search,我是弹性搜索新手,这是我的用户索引: { "user": { "properties": { "branches": { "type": "nested" }, "lists": { "type": "nested" }, "events": { "type": "nested" }, "optOuts": { "type": "nested" } } } } 在这里,分支、事件和列表将包含字段id(int)、countryIso
{
"user": {
"properties": {
"branches": {
"type": "nested"
},
"lists": {
"type": "nested"
},
"events": {
"type": "nested"
},
"optOuts": {
"type": "nested"
}
}
}
}
在这里,分支、事件和列表将包含字段id(int)、countryIso(String)
例如,我需要找到拥有属于countryIso“XX”的电子邮件的用户
{
"query": {
"bool": {
"must": [
{
"exists": {
"field": "email"
}
},
{
"match": {
"prog_id": 3
}
},
{
"nested": {
"path": [
"branches"
],
"query": {
"query_string": {
"fields": [
"branches.countryIso"
],
"query": "AE KW"
}
}
}
}
]
}
}
}
这样,如果他们的分支对象中有那个国家,我就可以得到它们。我想要的是,countryIso存在于分支、列表或事件中。
注意:其中任何一个可能是空的,即分支可能不存在或列表不存在等,或者列表可能不存在
我试过这个:
{
"query": {
"bool": {
"must": [
{
"exists": {
"field": "email"
}
},
{
"match": {
"prog_id": 3
}
},
{
"nested": {
"path": [
"branches"
],
"query": {
"query_string": {
"fields": [
"branches.countryIso"
],
"query": "AE KW"
}
}
}
},
{
"nested": {
"path": [
"lists"
],
"query": {
"query_string": {
"fields": [
"lists.countryIso"
],
"query": "AE KW"
}
}
}
}
]
}
}
}
及
但两者都不起作用
{
"query": {
"bool": {
"must": [
{
"exists": {
"field": "email"
}
},
{
"match": {
"prog_id": 3
}
},
{
"nested": {
"path": [
"branches",
"lists"
],
"query": {
"query_string": {
"fields": [
"branches.countryIso",
"lists.countryIso"
],
"query": "AE KW"
}
}
}
}
]
}
}
}