2015-01-09 49 views
1

如何在elasticsearch中加入父母和子女? 例如我的映射:如何在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" 

} 

當然,對於單個元素,我可以在應用程序中加入類型,但是如何處理大型列表? 謝謝!

回答

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