弹性搜索子列表过滤器

时间:2016-04-29 23:32:11

标签: elasticsearch

我有一个弹性文档,结构如此简化:

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

}

如何查询并获取比赛结果,以及只有得分超过35的参与者对象?

当我查询对象并使用过滤器时,我会找回整个参与者列表,这不是我需要的;我只需要一个符合搜索条件的对象列表。我是否必须使用嵌套文档进行重组?

1 个答案:

答案 0 :(得分:0)

使用inner_hits之类的:

 <form id="search-form" method="POST" action=".">
  <p>
<label for="id_j_title">Enter a keyword for the job title for the new application:</label>
<input id="id_j_title" maxlength="20" name="j_title" type="text" />
</p>
And Please enter a keyword to search for
<input type="submit" value="Select" />
<button>Back</button>
</form>

{ "query": { "nested": { "path": "Participants", "query": { "range": { "Participants.score": { "from": 35 } } }, "inner_hits" : {} } } } 获取所需的结果。