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

Viv*_*ipo 6 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"
                       }
                   }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我填充:

  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
    }
Run Code Online (Sandbox Code Playgroud)

我提出的要求是:

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

}
Run Code Online (Sandbox Code Playgroud)

如果没有请求的字段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
         }
      ]
   }
}
Run Code Online (Sandbox Code Playgroud)

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

Val*_*Val 11

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

因此,由于没有存储,因此"stored_fields": ["first_name"]将无法返回该first_name字段.

您可以使用源过滤,"_source": ["first_name"]在查询中指定,这将起作用.