【问题标题】:I can't get nested stored_fields我无法获得嵌套的存储字段
【发布时间】:2017-03-22 01:10:02
【问题描述】:

全部。 我正在使用 ElasticSearch 5.0,我有下一个映射:

{
    "mappings": {
        "object":{
            "properties":{
                "attributes":{
                    "type":"nested",
                    "properties":{
                        "name": { "type": "keyword", "store":true},
                        "value": { "type": "text", "store":true },
                        "converted": {"type": "double", "store":true},
                        "datetimestamp": { "type": "date", "store":true}
                    }
                }
            }
        }
    }
}

然后我添加一个文档:

{
    "attributes":[
        {"name":"attribute_string", "value":"string_value","converted":null,"datetimestamp":null},
        {"name":"attribute_double", "value":"1234.567","converted":1234.567,"datetimestamp":null},
        {"name":"attribute_datetime", "value":"2015-01-01T12:10:30Z","converted":null,"datetimestamp":"2015-01-01T12:10:30Z"}
        ]    
}

当我使用“stored_fields”查询时,结果中没有字段:

_search
{
    "stored_fields":["attributes.converted"]
}

结果:

{
    "_index": "test_index",
    "_type": "object",
    "_id": "1",
    "_score": 1
 }

但是当我使用 "_source":["attributes.converted"] 时,我得到了结果:

 {
    "_index": "test_index",
    "_type": "object",
    "_id": "1",
    "_score": 1,
    "_source": {
       "attributes": [
          { "converted": null  },
          { "converted": 1234.567  },
          { "converted": null     }
       ]
    }
 }

使用stored_fields 的正确方法是什么? 与“stored_fields”方法相比,“_source”的使用会影响性能吗?

如果 "_source" 方法和 "stored_fields" 一样快,我应该删除字段的 "store":true 吗?

谢谢。

【问题讨论】:

    标签: elasticsearch elasticsearch-net


    【解决方案1】:

    您使用的是nested types,所以请使用inner_hits

    在嵌套情况下,根据嵌套内部对象中的匹配返回文档。

    文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html

    【讨论】:

      【解决方案2】:

      根据elasticsearch-docs

      就其本身而言,stored_fields 不能用于加载嵌套对象中的字段 — 如果字段在其路径中包含嵌套对象,则不会为该存储字段返回任何数据。要访问嵌套字段,stored_fields 必须在 inner_hits 块中使用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-12-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多