elasticsearch - elastic search 5.1 为什么stored_fields 不返回请求的字段?

标签 elasticsearch sense

在 Elastic Search 5.1 中,我使用 stored_fields 正文参数(旧字段参数的新名称)发出基本请求以检索特定字段的值。

但是除了_index, _type, _id 和 _score 之外,我的请求没有给出任何字段值

我给你上下文示例:

我创建索引和映射:

 PUT /base_well
    {
        "mappings": {
            "person": {
                   "properties": {
                       "first_name":{
                           "type": "string"
                       },
                         "last_name":{
                           "type": "string"
                       },
                       "age":{
                           "type": "long"
                       }
                   }
            }
        }
    }

我填充:

  POST /base_well/person
        {
            "first_name":"James",
            "last_name" : "Mopo",
            "Age" : 21
        }

    POST /base_well/person
    {
        "first_name":"Polo",
        "last_name" : "Rodriguez",
        "Age" : 36
    }

    POST /base_well/person
    {
        "first_name":"Marc Aurelien",
        "last_name" : "Poisson",
        "Age" : 26
    }

    POST /base_well/person
    {
        "first_name":"Mustapha",
        "last_name" : "Bulutu M'Bo",
        "Age" : 47
    }

我的请求是:

    POST  /base_well/person/_search
{
   "stored_fields": ["first_name"]

}

它给了我一个没有请求字段 fiest_person 的答案:

{
   "took": 4,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 8,
      "max_score": 1,
      "hits": [
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFYzihcR_Z5VPUXUCL",
            "_score": 1
         },
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFiv3acR_Z5VPUXUCa",
            "_score": 1
         },
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFiwUKcR_Z5VPUXUCb",
            "_score": 1
         },
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFYx2LcR_Z5VPUXUCI",
            "_score": 1
         },
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFYyhScR_Z5VPUXUCJ",
            "_score": 1
         },
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFYzIJcR_Z5VPUXUCK",
            "_score": 1
         },
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFivgzcR_Z5VPUXUCZ",
            "_score": 1
         },
         {
            "_index": "base_well",
            "_type": "person",
            "_id": "AVlFiw2qcR_Z5VPUXUCc",
            "_score": 1
         }
      ]
   }
}

请问有谁能解释一下如何做以及它是如何工作的吗?

最佳答案

默认情况下,不存储文档字段,即在您的映射中,您没有为每个字段指定 store: true

因此,"stored_fields": ["first_name"] 将无法返回 first_name 字段,因为它未存储。

您可以使用 source filtering相反,在您的查询中指定 "_source": ["first_name"] 即可。

关于elasticsearch - elastic search 5.1 为什么stored_fields 不返回请求的字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41362817/

相关文章:

elasticsearch - 如何在elasticsearch simple_query_string中包含除空格以外的所有字符?

elasticsearch - 从 ElasticSearch 获取最后一个文档

elasticsearch - Elasticsearch 嵌套对象映射和查询查询

elasticsearch - 无法为 Kibana 安装 sense 插件

regex - Elasticsearch 正则表达式从右边获取最后7位数字

c# - 带有Kibana的ElasticSearch云上的Serilog接收器未收到消息

elasticsearch - Logstash/ Elasticsearch : guesses wrong for datatype for field

elasticsearch - 跨多个 Elasticsearch 类型查询

lucene - 嵌套可枚举对象(i18n)的ElasticSearch映射

curl - Elasticsearch文档TTL无法正常工作