我对Search 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
元素中删除字段_index,_type和_score。
我该怎么做?
答案 0 :(得分: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" ]
}
}
]
}
}