1

Is there any way I can hide some of the common fields which are being returned as a response by ES.

e.g if I get the response as below:

{
  "took": 74,
  "timed_out": false,
  "_shards": {
    "total": 15,
    "successful": 15,
    "failed": 0
  },
  "hits": {
    "total": 24,
    "max_score": 0.15932977,
    "hits": [
      {
        "_index": "prashant",
        "_type": "session",
        "_id": "LeIDrUNmSKGC5Sl9Y8O0Zw",
        "_score": 0.15932977,
        "fields": {
          "Time": [
            "2014-01-08T15:01:26"
          ]
        }
      },
      {
        "_index": "prashant",
        "_type": "session",
        "_id": "dlpQGXk_TOyfNnUEG6skeQ",
        "_score": 0.14296037,
        "fields": {
          "Time": [
            "2014-01-08T15:01:26"
          ]
        }
      }
    ]
  }
}

Now I want the ES to respond without took, timed_out, _shards,total, successful, failed value as well I don't want the Name of the _index, _type as I am executing the query to particular index and type.

So is there a way to filter the ES response in that way?

Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
Prashant
  • 17
  • 1
  • 4

2 Answers2

3

Use the "filter_path" query parameter. In your example, to only include the _source and _id fields for all results (and thereby exclude all the other metadata in the response) use:

http://your-es-cluster?filter_path=hits.hits._source,hits.hits._id

Its been in the rest api since 1.6 I think.

To further filter and limit the fields in the _source, use the normal _source parameter filtering. For example:

http://your-es-cluster?filter_path=hits.hits._source,hits.hits._id&_source=Time

hubbardr
  • 3,153
  • 1
  • 21
  • 27
1

You can limit the search response by specifying the fields to be returned in the search query part of your request.

"search_request": {
  "fields": [ "title", "content" ],
  "query": ...
},

This is a standard field filter of Elasticsearch, it's not clustering-specific. Remember that you must include the fields that will be used for clustering later on. See the plugin's documentation ("A bit more about field mapping").

dawid.weiss
  • 168
  • 6
  • Is there any way to filter the common return fields like _index, _type which is same for all records if I am running the query to particular index and type – Prashant Mar 19 '14 at 13:04