Skip to content

Instantly share code, notes, and snippets.

@geekpete
Last active December 15, 2016 01:33
Show Gist options
  • Save geekpete/02f07040798b8d47b7308c5ccaee6864 to your computer and use it in GitHub Desktop.
Save geekpete/02f07040798b8d47b7308c5ccaee6864 to your computer and use it in GitHub Desktop.
source filtering and filter_path
"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"
Response Filtering (filter_path):
https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#common-options-response-filtering
Source Filtering:
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html#get-source-filtering
GET /birthday/_search
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "birthday",
"_type": "t",
"_id": "1",
"_score": 1,
"_source": {
"birthday": "1974-05-04",
"first_name": "foo",
"last_name": "bar",
"hobby": "baz"
}
}
]
}
}
# using both filter_path and source filtering
GET /birthday/_search?_source_include=birthday&filter_path=hits.hits._source
{
"hits": {
"hits": [
{
"_source": {
"birthday": "1974-05-04"
}
}
]
}
}
# using only filter_path and without source filtering
GET /birthday/_search?filter_path=hits.hits._source.birthday
{
"hits": {
"hits": [
{
"_source": {
"birthday": "1974-05-04"
}
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment