Fetch only filtered nested objects from index in elasticsearch

半世苍凉 提交于 2019-11-27 16:21:28

You need to use the nested inner_hits feature like below.

{
  "_source": [
    "title"
  ],
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "title": "title 1"
          }
        },
        {
          "nested": {
            "path": "books",
            "query": {
              "term": {
                "books.year": 2014
              }
            },
            "inner_hits": {}
          }
        }
      ]
    }
  }
}

In the output you'll get exactly what you expect, namely the title field and the matching book from the nested books array.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!