benbo benbo - 1 month ago 11
JSON Question

Elastic Search - exclude index and type from json response

When I execute a query over an index like this:

{
"_source":["bar"] , "size":100,
"query": {
"match_all": {}
},
"filter": {
"type" : {
"value" : "foo"
}
}
}


the response includes index, type, etc. But I already know the index and type because I specified it. This information just bloats up the size of the json data. Is there a way to exclude these from the response?

This is what I get:

{
"took": 31,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 364024,
"max_score": 1,
"hits": [
{
"_index": "foo_bar",
"_type": "foo",
"_id": "asdjj123123",
"_score": 1,
"_source": {
"bar": "blablablabla"
}
}
,...


What I want is something like this, so a response without type,score,index:

{
"took": 31,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 364024,
"max_score": 1,
"hits": [
{
"_id": "asdjj123123",
"_source": {
"bar": "blablablabla"
}
}
,...

Val Val
Answer

Yes, as of ES 1.6, you can use response filtering and using the filter_path parameter in the query enumerate only what you need in the response:

curl -XGET 'localhost:9200/foo_bar/foo/_search?pretty&filter_path=hits.total,hits.max_score,hits.hits._id,hits.hits._source'
Comments