Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
910 views
in Technique[技术] by (71.8m points)

elasticsearch - 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"
    }
  }
,...
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...