2016-04-29 101 views
-1

我有一個彈性的文檔,結構化[簡化]是這樣的:彈性搜索次列表篩選

{ 
"Contest": { 
    "Name": "Room1", 
    "Participants": [ 
    { 
    "PlayerID": "tester1", 
    "Score": "30" 
    }, 
    { 
     "PlayerID": "tester2", 
     "Score": "40" 
    }, 
    { 
     "PlayerID": "tester3", 
     "Score": "10" 
    } 
    ] 
} 

}

我怎樣才能查詢此,並得到一個結果,比賽中,只有參與者對象的分數超過35?

當我查詢對象並使用過濾器時,我找回了參與者的整個列表,這不是我所需要的;我只需要符合搜索條件的對象列表。我是否必須使用嵌套文檔進行重構?

回答

0

使用inner_hits像:

{ 
"query": { 
    "nested": { 
    "path": "Participants", 
    "query": { 
     "range": { 
     "Participants.score": { 
      "from": 35 
     } 
     } 
    }, 
    "inner_hits" : {} 
    } 
    } 
} 

讀取所需的結果從inner_hits

+0

謝謝你,這就是我發現的,但只是作爲一個註釋:輸出使結構非規格化,我發現它不夠理想。 – Andy

+0

你有沒有發現任何其他解決方案不會使結構不規範? –