如何在 elasticsearch 中加入 parent 和 child

How join parent and child in elasticsearch

如何在elasticsearch中加入parent和child? 例如我的映射:

{  
   "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"

}

当然,对于单个元素,我可以在应用程序中加入类型,但是对于大列表怎么办? 谢谢!

可能是这样的,别以为有什么好的分组方法:

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"
              }
            }
          }
        }
      }
    }
  }
}