2016-07-29 139 views
2

我想只獲取嵌套字段,但不能,因爲它不是葉字段。Elasticsearch - 獲取嵌套字段

GET index/_search 
{ 
    "size": 10, 
    "fields": [ 
     "nested_fields" 
    ] 
} 

ERROR : "reason": "field [nested_fields] isn't a leaf field"

下面我試過,但不能在嵌套的對象每個ID和名稱相匹配。

GET index/_search 
    { 
     "size": 10, 
     "fields": [ 
      "nested_fields.id", 
      "nested_fields.name" 
     ] 
    } 

結果:

"fields": { 
       "events.id": [ 
        "13342", 
        "24232", 
        "25534", 
        "63454" 
       ], 
       "events.name": [ 
        "R1413", 
        "R1414", 
        "R1415", 
        "R1416", 
       ] 
      } 

這是我期望的結果:

fields" : { 
    "evets" : { 
     "id" : "234234", 
     "name" : "RP1524" 
    }, 
    .... so on 
} 

回答

4

如果不具備一定的查詢應該以某種方式相匹配的嵌套字段,你可以做到這一點像這樣:

GET /index/_search 
{ 
    "size": 10, 
    "_source": ["nested_fields.id", "nested_fields.name"] 
} 

如果你也有一個nested查詢,並要返回匹配的嵌套的文檔,你可以做這樣的(與inner_hits):

{ 
    "query": { 
    "nested": { 
     "path": "nested_fields", 
     "query": {"match_all": {}}, 
     "inner_hits": {} 
    } 
    } 
} 
+0

第一個爲我工作。謝謝 :) –