36

Is there a way to tell elasticsearch to not return any metadata? Currently I can select which fields I want to be returned in source. But I only want fields in source. I would prefer to not have the metadata returned as I dont need it and would save some unnecessary parsing and transport etc.

I found Elasticsearch - how to return only data, not meta information? older question where somebody commented that it wasnt possible to do it then. Wondering if this functionality has been added or is still missing?

Community
  • 1
  • 1
bagi
  • 627
  • 1
  • 8
  • 20
  • 1
    As far as I know, this functionality _still_ does not exist. However, you can create a plugin to do this [as shown here](https://github.com/imotov/elasticsearch-just-source/blob/master/src/main/java/org/elasticsearch/examples/justsource/rest/action/RestJustSourceAction.java). – pickypg Apr 25 '14 at 02:41
  • thanks! wondering why ES doesn't have this functionality. Maybe just doesn't have a priority high enough. – bagi Apr 30 '14 at 01:25
  • I suppose that some things could become quite difficult without the metadata, particularly paging. – pickypg Apr 30 '14 at 03:20
  • 1
    but that information doesn't need to be provided to the end user necessarily. – bagi Apr 30 '14 at 23:36

4 Answers4

37

response_filtering

All REST APIs accept a filter_path parameter that can be used to reduce the response returned by elasticsearch. This parameter takes a comma separated list of filters expressed with the dot notation:

curl -XGET 'localhost:9200/_search?pretty&filter_path=took,hits.hits._id,hits.hits._score'
{
  "took" : 3,
  "hits" : {
    "hits" : [
      {
        "_id" : "3640",
        "_score" : 1.0
      },
      {
        "_id" : "3642",
        "_score" : 1.0
      }
    ]
  }
}

In python

def get_all( connection, index_name, type_name ):

    query = {
        "match_all":{}
    }

    result = connection.search( index_name, type_name,
             {"query": query},
             filter_path= ["took", "hits.hits._id", "hits.hits.score"])

    return result

If you want to filter _source fields, you should consider combining the already existing _source parameter (see Get API for more details) with the filter_path parameter like this:

curl -XGET 'localhost:9200/_search?pretty&filter_path=hits.hits._source&_source=title'
{
  "hits" : {
    "hits" : [ {
      "_source":{"title":"Book #2"}
    }, {
      "_source":{"title":"Book #1"}
    }, {
      "_source":{"title":"Book #3"}
    } ]
  }
}
Cory Klein
  • 51,188
  • 43
  • 183
  • 243
The Demz
  • 7,066
  • 5
  • 39
  • 43
9

It's not that difficult if we know it :)

http://localhost:9200/***{index_name}***/***{type}***/_search?pretty&filter_path=took,hits.hits._id,hits.hits._score,**hits.hits._source**
Sufiyan Ghori
  • 18,164
  • 14
  • 82
  • 110
4

I do not know options like this in a query. It is possible to do this in a get by Id request.

/{index}/{type}/{id}/_source

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html#_source

Jettro Coenradie
  • 4,735
  • 23
  • 31
1

filter_path (response filtering) doesn't have any effect for the version 1.5 of elasticsearch.

Unless the option had a different name or was moved in the documentation, it was first added in version 1.6.

Jorge
  • 184
  • 1
  • 8