elasticsearch如何搜索嵌套内容

语言: CN / TW / HK

第一步 字段类型设置为nested

{
    "book": {
        "properties": {
            "title":{"type":"string"},
            "chapters":{
                "type":"nested",
                "properties":{
                    "title":{"type":"string"},
                    "length":{"type":"long"}
                }
            }
        }
    }
}

第二步 用inner_hits来查询

POST /bookindex/book/_search

{
  "_source": false,
  "query": {
    "nested": {
      "path": "chapters",
      "query": {
        "match": {
          "chapters.title": "epilogue"
        }
      },
      "inner_hits": {}
    }
  }
}

参考链接:http://stackoverflow.com/questions/16788553/returning-a-partial-nested-document-in-elasticsearch