如何在elasticsearch中加入父母和孩子? 例如我的映射:
{
"street":{
"properties":{
"street_name":{
"type":"string"
}
}
}
}
和
{
"address":{
"_parent":{
"type":"street"
},
"properties":{
"house_number":{
"type":"string"
}
}
}
}
数据:
{"_type":"street","_id":"AUrLQH9ZcB6int_hskH3","_source":{"street_name":"Street"}}
{"_type":"address","_id":"AUrLQH_XcB6int_hskH4","_source":{"house_number":"10"}}
如何在一个查询中获得类似的结果:
{
"_type":"address",
"_id":"AUrLQH_XcB6int_hskH4",
"house_number":"10",
"street_name":"Street"
}
当然,对于单个元素,我可以在应用程序中加入类型,但是如何处理大型列表? 谢谢!
答案 0 :(得分:2)
也许这样的事情,不要认为有一种方法可以很好地对它们进行分组:
GET /postal_codes/street/_search?search_type=count
{
"aggs": {
"street": {
"terms": {
"field": "street_name"
},
"aggs": {
"addresses": {
"children": {
"type": "address"
},
"aggs": {
"number": {
"terms": {
"field": "address.house_number"
}
}
}
}
}
}
}
}