Elasticsearch return 嵌套 objects 没有 parents

Elasticsearch return nested objects without their parents

我有一个如下所示的索引:

{
    "mappings":{
        "authors":{
            "properties":{
                "books":{
                    "type":"nested",
                    "properties":{
                        "title":{"type":"string"},
                        "firstSentence":{"type":"string"},
                        "isbn":{"type":"string"},
                        "publishDate":{"type":"date"},
                    }
                },
                "firstName":{"type":"string"},
                "lastName":{"type":"string"}, 
                "birthday":{"type":"date"},
                }
           }
}

我正在通过 Java 客户端查询该索引。对于这个查询,我不关心作者;我只想拿回书。例如,我想找到所有在标题和第一句中都包含单词 "Hello" 的书。

目前,我使用 return 一个作者列表的嵌套查询,然后我手动解析该列表以获取书籍。有没有办法让 Elasticsearch 直接 return 一个图书列表?我正在使用 Elasticsearch 1.5.2 版和 Jest 0.1.6

不,结果是您注入的文件。您可以使用源过滤来限制返回文档的字段,这样您就只能返回嵌套文档。但是这些将始终在嵌套父级的范围内。因此,如果您找到两位作者各有几本书,您会得到两个带有嵌套文档的结果。

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html#search-request-source-filtering