{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/10980","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10980/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10980/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10980/events","html_url":"https://github.com/elastic/elasticsearch/pull/10980","id":73300356,"number":10980,"title":"API: Add response filtering with _path parameter","user":{"login":"tlrx","id":642733,"avatar_url":"https://avatars.githubusercontent.com/u/642733?v=3","gravatar_id":"","url":"https://api.github.com/users/tlrx","html_url":"https://github.com/tlrx","followers_url":"https://api.github.com/users/tlrx/followers","following_url":"https://api.github.com/users/tlrx/following{/other_user}","gists_url":"https://api.github.com/users/tlrx/gists{/gist_id}","starred_url":"https://api.github.com/users/tlrx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlrx/subscriptions","organizations_url":"https://api.github.com/users/tlrx/orgs","repos_url":"https://api.github.com/users/tlrx/repos","events_url":"https://api.github.com/users/tlrx/events{/privacy}","received_events_url":"https://api.github.com/users/tlrx/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/:REST","name":":REST","color":"009800"},{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/release%20highlight","name":"release highlight","color":"fbca04"},{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/review","name":"review","color":"0052cc"},{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/v1.6.0","name":"v1.6.0","color":"dddddd"},{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/v2.0.0","name":"v2.0.0","color":"dddddd"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":26,"created_at":"2015-05-05T12:18:56Z","updated_at":"2015-05-20T18:39:51Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/10980","html_url":"https://github.com/elastic/elasticsearch/pull/10980","diff_url":"https://github.com/elastic/elasticsearch/pull/10980.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/10980.patch"},"body":"This change adds a new \"_path\" parameter that can be used to filter and reduce the responses returned by the REST API of elasticsearch.\r\n\r\nFor example, returning only the shards that failed to be optimized:\r\n```\r\ncurl -XPOST 'localhost:9200/beer/_optimize?_path=_shards.failed'\r\n{\"_shards\":{\"failed\":0}}%\r\n```\r\n\r\nIt supports multiple filters (separated by a comma):\r\n```\r\ncurl -XGET 'localhost:9200/_mapping?pretty&_path=*.mappings.*.properties.name,*.mappings.*.properties.title'\r\n```\r\n\r\nIt also supports the YAML response format. Here it returns only the `_id` field of a newly indexed document:\r\n```\r\ncurl -XPOST 'localhost:9200/library/book?_path=_id' -d '---hello:\\n  world: 1\\n'\r\n---\r\n_id: \"AU0j64-b-stVfkvus5-A\"\r\n```\r\n\r\nIt also supports wildcards. Here it returns only the host name of every nodes in the cluster:\r\n```\r\ncurl -XGET 'http://localhost:9200/_nodes/stats?_path=nodes.*.host*'\r\n{\"nodes\":{\"lvJHed8uQQu4brS-SXKsNA\":{\"host\":\"portable\"}}}\r\n```\r\n\r\nAnd \"**\" can be used to include sub fields without knowing the exact path. Here it returns only the Lucene version of every segment:\r\n```\r\ncurl 'http://localhost:9200/_segments?pretty&_path=indices.**.version'\r\n{\r\n  \"indices\" : {\r\n    \"beer\" : {\r\n      \"shards\" : {\r\n        \"0\" : [ {\r\n          \"segments\" : {\r\n            \"_0\" : {\r\n              \"version\" : \"5.2.0\"\r\n            },\r\n            \"_1\" : {\r\n              \"version\" : \"5.2.0\"\r\n            }\r\n          }\r\n        } ]\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nNote that elasticsearch sometimes returns directly the raw value of a field, like the \"_source\" field. If you want to filter the response that include _source fields like in Search or Get responses , you should consider using the already existing \"fields\" parameter:\r\n ```\r\n curl -XGET 'localhost:9200/beer/tasty/3672?pretty&fields=category'\r\n {\r\n   \"_index\" : \"beer\",\r\n   \"_type\" : \"tasty\",\r\n   \"_id\" : \"3672\",\r\n   \"_version\" : 1,\r\n   \"found\" : true,\r\n   \"fields\" : {\r\n     \"category\" : [ \"German Lager\" ]\r\n   }\r\n }\r\n```\r\n\r\nThe \"_path\" parameter can be used to further reduce the result:\r\n ```\r\ncurl -XGET 'localhost:9200/beer/tasty/3672?pretty&fields=category&_path=fields.category'\r\n{\r\n  \"fields\" : {\r\n    \"category\" : [ \"German Lager\" ]\r\n  }\r\n}\r\n\r\n```\r\n\r\nCloses #7401"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments/103989932","html_url":"https://github.com/elastic/elasticsearch/pull/10980#issuecomment-103989932","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10980","id":103989932,"user":{"login":"tlrx","id":642733,"avatar_url":"https://avatars.githubusercontent.com/u/642733?v=3","gravatar_id":"","url":"https://api.github.com/users/tlrx","html_url":"https://github.com/tlrx","followers_url":"https://api.github.com/users/tlrx/followers","following_url":"https://api.github.com/users/tlrx/following{/other_user}","gists_url":"https://api.github.com/users/tlrx/gists{/gist_id}","starred_url":"https://api.github.com/users/tlrx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlrx/subscriptions","organizations_url":"https://api.github.com/users/tlrx/orgs","repos_url":"https://api.github.com/users/tlrx/repos","events_url":"https://api.github.com/users/tlrx/events{/privacy}","received_events_url":"https://api.github.com/users/tlrx/received_events","type":"User","site_admin":false},"created_at":"2015-05-20T18:39:51Z","updated_at":"2015-05-20T18:39:51Z","body":"@clintongormley sounds good to me, thanks"}}