【问题标题】:Elasticsearch return nested objects without their parentsElasticsearch 返回没有父对象的嵌套对象
【发布时间】:2016-07-15 22:41:38
【问题描述】:

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

{
    "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”一词的所有书籍。

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

【问题讨论】:

    标签: java elasticsearch nested elasticsearch-jest


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多