2016-12-28 48 views
5

在彈性搜索5.1中,我正在使用stored_fields主體參數(舊字段參數的新名稱)進行基本請求,以檢索特定字段的值。彈性搜索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"] 

} 

它給我的answere沒有請求字段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 
     } 
     ] 
    } 
} 

任何人都可以解釋我這樣做,它是如何工作的嗎?

+0

如果向查詢中添加'_source「:true',你會看到源代碼嗎? – Val

+0

不,也許這是答案 –

+0

我很困惑,因爲你在你的問題中提到'stored_fields',但我沒有看到你的查詢中的任何地方。 – Val

回答

7

默認情況下,文檔字段不存儲,即在您的映射中,您沒有爲每個文檔指定store: true

因此,"stored_fields": ["first_name"]將不能返回first_name字段,因爲它沒有存儲。

您可以使用source filtering來代替並在您的查詢中指定"_source": ["first_name"],這將起作用。