1
我试图完成在ElasticSearch嵌套文档中布尔值AND
的结果。假设我有以下两个文件。在ElasticSearch中匹配嵌套文档中的多个属性
{
"id": 1,
"secondLevels": [
{
"thirdLevels": [
{
"isActive": true,
"user": "[email protected]"
}
]
},
{
"thirdLevels": [
{
"isActive": false,
"user": "[email protected]"
}
]
}
]
}
{
"id": 2,
"secondLevels": [
{
"thirdLevels": [
{
"isActive": true,
"user": "[email protected]"
}
]
}
]
}
在这种情况下,我想只匹配文件(在这种情况下,ID:2)有两个isActive: true
和user: [email protected]
一个嵌套的文件。
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "secondLevels.thirdLevels",
"query": {
"bool": {
"must": [
{
"term": {
"secondLevels.thirdLevels.isActive": true
}
},
{
"term": {
"secondLevels.thirdLevels.user": "[email protected]"
}
}
]
}
}
}
}
]
}
}
}
然而,似乎是发生的是,我的查询变成了两份文件,因为文件头有一个thirdLevel
有isActive: true
和另一thirdLevel
具有适当的用户。
有什么办法可以在查询/过滤时严格执行此操作,还是必须在脚本中执行此操作?
您正在使用什么版本的弹性?我创建了一个索引并在本地测试了您的查询,并且我只返回id = 2的用户。我要求的原因是,我相信“必须”分组应该是默认为AND,除非您可能以某种方式默认为OR – Miek