【问题标题】:elastic search 5.1 why stored_fields does not return asked field?elastic search 5.1 为什么stored_fields 不返回询问字段?
【发布时间】:2017-05-12 18:46:15
【问题描述】:

在 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
         }
      ]
   }
}

任何人都可以解释我这样做以及它是如何工作的吗?

【问题讨论】:

  • 如果您在查询中添加"_source": true,您会看到源代码吗?
  • 不,也许是答案
  • 我很困惑,因为您在问题中提到了stored_fields,但我在您的查询中没有看到任何地方。
  • 也许我检查错了
  • 对不起,我复制粘贴错误:(,这很愚蠢,很愚蠢,谢谢你告诉我

标签: elasticsearch sense


【解决方案1】:

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

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

您可以改用source filtering 并在查询中指定"_source": ["first_name"],这样就可以了。

【讨论】:

  • 对于查询字符串,它看起来像:&_source=field_1,field_2
猜你喜欢
  • 2021-02-02
  • 1970-01-01
  • 2017-04-01
  • 2016-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-07
相关资源
最近更新 更多