我有以下映射:过滤深嵌套项目
PUT /test
{
"mappings": {
"test": {
"properties": {
"parent": {
"type": "nested",
"properties": {
"@id": {
"type": "string",
"index": "not_analyzed"
},
"@type": {
"type": "string"
},
"child": {
"type": "nested",
"properties": {
"@id": {
"type": "string",
"index": "not_analyzed"
},
"subchild": {
"type": "nested",
"properties": {
"@id": {
"type": "string",
"index": "not_analyzed"
},
"hasA": {
"type": "nested",
"properties": {
"@value": {
"type": "string"
}
}
},
"hasB": {
"type": "nested",
"properties": {
"@id": {
"type": "string",
"index": "not_analyzed"
}
}
},
"hasC": {
"type": "nested",
"properties": {
"@id": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
}
}
}
}
}
}
而且下列文件:
POST /test/test/1
{
"parent": {
"@id": "12345",
"@type": "test",
"child": [
{
"@id": "1",
"subchild": [
{
"@id": "1.1",
"hasA": {
"@value": "hasA value"
},
"hasB": {
"@id": "hasB_1"
},
"hasC": {
"@id": "hasC_1"
}
}
]
},
{
"@id": "2",
"subchild": [
{
"@id": "2.1",
"hasA": {
"@value": "hasA value"
},
"hasB": {
"@id": "hasB_2"
},
"hasC": {
"@id": "hasC_2"
}
}
]
}
]
}
}
而下面的查询:
POST test/test/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"path": "parent.child.subchild.hasB",
"filter": {
"bool": {
"must": [
{
"term": {
"[email protected]": "hasB_2"
}
}
]
}
},
"_cache": false
}
}
}
}
}
我无法将路径设置为parent.child.subchild,以便我可以在hasB和hasC上匹配,似乎我只能在at处选择一个嵌套项我。这是我想什么能够做到:
POST test/test/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"path": "parent.child.subchild",
"filter": {
"bool": {
"must": [
{
"term": {
"[email protected]": "hasB_2"
}
},
{
"term": {
"[email protected]": "hasC_2"
}
}
]
}
},
"_cache": false
}
}
}
}
}
@AndreiStefan我发现你重新格式化我的JSON,我可以在将来使用哪个工具来确保我的JSON格式正确? –