要想能用父子级联查询 首先 index得设置成 nested 类型,如
PUT my_index
{
“mappings”: {
“_doc”: {
"properties": {
"manager": {
"properties": {
"age": { "type": "integer" },
"name": { "type": "text" }
}
},
"employees": {
“type”: “nested”,
“properties”: {
“age”: { “type”: “integer” },
“name”: { “type”: “text” }
}
}
}
}
}
}
查询的时候 即可使用
GET my_index/_search
{
“query”: {
“match”: {
“manager.name”: “Alice White”
}
},
“aggs”: {
“Employees”: {
“nested”: {
“path”: “employees”
},
“aggs”: {
“Employee Ages”: {
“histogram”: {
“field”: “employees.age”,
“interval”: 5
}
}
}
}
}
}