弹性搜索5.1为什么stored_fields不返回问域?

时间:2016-12-28 13:09:47

标签: elasticsearch sense

在弹性搜索5.1中,我使用stored_fields body参数(旧字段参数的新名称)进行基本请求,以检索特定字段的值。

但是除了_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
         }
      ]
   }
}

任何人都可以解释我这样做以及它如何运作?

1 个答案:

答案 0 :(得分:10)

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

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

您可以改为使用source filtering并在查询中指定"_source": ["first_name"],这将有效。