[英]Elasticsearch: Multi-level nested query not working
My mapping is as follows: 我的映射如下:
{
"mappings": {
"person": {
"properties": {
"lastUpdated": {
"type": "long"
},
"isDeleted": {
"type": "boolean"
},
"person": {
"properties": {
"car": {
"type": "nested",
"properties": {
"model": {
"type": "string"
},
"make": {
"type": "string"
}
}
},
"last_name": {
"type": "string"
},
"first_name": {
"type": "string"
}
}
}
}
}
}
}
I have two documents: 我有两个文件:
{
"person": {
"first_name": "Bob",
"last_name": "Doe",
"car": [
{
"make": "Saturn",
"model": "Imprezza"
},
{
"make": "Honda",
"model": "Accord"
}
]
},
"isDeleted": false,
"lastUpdated": 1433257051959
}
and 和
{
"person": {
"first_name": "Zach",
"last_name": "Foobar",
"car": [
{
"make": "Saturn",
"model": "SL"
},
{
"make": "Subaru",
"model": "Imprezza"
}
]
},
"isDeleted": false,
"lastUpdated": 1433257051959
}
I wanted to query the car.make
field and so, I wrote the following query: 我想查询car.make
字段,因此,我编写了以下查询:
{
"query": {
"nested": {
"path": "person.person.car",
"query": {
"match": {
"car.make": "Saturn"
}
},
"inner_hits": {}
}
}
}
However, I am not getting anything back results back in return. 但是,我没有得到任何回报。 When I remove the person
level object and try to search, then it works. 当我删除person
级别的对象并尝试搜索时,它就会起作用。 Any idea how to go about doing multi-level nested queries? 任何想法如何去做多层次的嵌套查询?
EDIT: On the other hand, when I structure my data like this and query then it works. 编辑:另一方面,当我像这样构造我的数据并查询时,它就可以工作。
{
"mappings": {
"person": {
"properties": {
"car": {
"type": "nested",
"properties": {
"model": {
"type": "string"
},
"make": {
"type": "string"
}
}
},
"last_name": {
"type": "string"
},
"first_name": {
"type": "string"
}
}
}
}
}
{
"first_name": "Zach",
"last_name": "Foobar",
"car": [
{
"make": "Saturn",
"model": "SL"
},
{
"make": "Subaru",
"model": "Imprezza"
}
]
}
{
"first_name": "Bob",
"last_name": "Doe",
"car": [
{
"make": "Saturn",
"model": "Imprezza"
},
{
"make": "Honda",
"model": "Accord"
}
]
}
{
"query": {
"nested": {
"path": "person.car",
"query": {
"match": {
"car.make": "Honda"
}
},
"inner_hits": {}
}
}
}
This way the query works. 这种查询方式。 I feel like this has something to do with multi-level nesting. 我觉得这与多层嵌套有关。 Multi-level nesting is not working. 多级嵌套不起作用。
The nested path attribute needs to be "person.car". 嵌套的路径属性需要为“ person.car”。
Add "type": "nested", above the (2nd level) person properties line if you wish person to be a nested field type, which is required for Nested Query searches. 如果希望人员为嵌套字段类型,则在(第二级)人员属性行上方添加“类型”:“嵌套”,这是嵌套查询搜索所必需的。 The default field type is object field. 默认字段类型是对象字段。
The naming you are using is confusing, try to rename your mapping not to use person twice. 您使用的命名令人困惑,请尝试重命名您的映射,以免使用人员两次。
{
"query": {
"nested": {
"path": "person.car",
"query": {
"match": {
"make": "Saturn"
}
},
"inner_hits": {}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.