2016-08-08 10 views
0

私の応答は、私はフィールド_index、_typeと_scoreは各hits.hits要素から削除する場合は、この削除メタデータは、検索APIから

{ 
    "took":88, 
    "timed_out":false, 
    "_shards":{ 
     "total":3, 
     "successful":3, 
     "failed":0 
    }, 
    "hits":{ 
     "total":2, 
     "max_score":1.0, 
     "hits":[ 
      { 
       "_index":"myindex", 
       "_type":"mytype", 
       "_id":"first", 
       "_score":1.0, 
       "fields":{ 
        "name":[ "John Smith" ] 
       } 
      }, 
      { 
       "_index":"myindex", 
       "_type":"mytype", 
       "_id":"second", 
       "_score":1.0, 
       "fields":{ 
        "name":[ "John Doe" ] 
       } 
      } 
     ] 
    } 
} 

のように見えますhits.hits。 どうすればいいですか?

+0

どのようにクエリを送信しますか? – Val

+0

@Val:検索API(POST) – musicsquad

答えて

2

次のようなクエリ文字列にfilter_pathパラメータを指定することでresponse filteringを使用することができます。

curl -XPOST 'localhost:9200/_search?pretty&fields=name&filter_path=hits.hits.fields' -d '{ 
    "query": { 
     "match": { 
      "name": "john" 
     } 
    } 
}' 

またはソースフィルタリングを使用して代わりに

curl -XPOST 'localhost:9200/_search?pretty&_source=name&filter_path=hits.hits._source' -d '{ 
    "query": { 
     "match": { 
      "name": "john" 
     } 
    } 
}' 

あなたの応答ではなく、次のようになります。

{ 
    "hits":{ 
     "hits":[ 
      { 
       "fields":{ 
        "name":[ "John Smith" ] 
       } 
      }, 
      { 
       "fields":{ 
        "name":[ "John Doe" ] 
       } 
      } 
     ] 
    } 
} 
+0

これは検索API(POST)のためにうまくいきません – musicsquad

+0

もちろん、試してみてください。 – Val

+0

いいえ、リクエストURLはPOSTのようにloksします。http:// /myindex/mytype/_search?filterPath=hits.hits.fields&fields=nameでも、それぞれのヒット要素にはまだ_index、_type、および_scoreがあります。 btw、なぜ "名前"は自動的に文字列の配列になりますか? – musicsquad

関連する問題