2016-12-28 2 views
5

Elastic Search 5.1私は、特定のフィールドの値を取得するために、stored_fields本体引数(古いフィールドの引数の新しい名前)を使用して基本要求を行っています。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せずに私のanswereを与える:

{ 
    "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"]と指定すると動作します。

関連する問題