{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/29683129","id":29683129,"diff_hunk":"@@ -0,0 +1,293 @@\n+/*\n+ * Licensed to Elasticsearch under one or more contributor\n+ * license agreements. See the NOTICE file distributed with\n+ * this work for additional information regarding copyright\n+ * ownership. Elasticsearch licenses this file to you under\n+ * the Apache License, Version 2.0 (the \"License\"); you may\n+ * not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *    http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+package org.elasticsearch.common.xcontent.support.filtering;\n+\n+import org.elasticsearch.common.bytes.BytesReference;\n+import org.elasticsearch.common.xcontent.XContentBuilder;\n+import org.elasticsearch.common.xcontent.XContentFactory;\n+import org.elasticsearch.common.xcontent.XContentParser;\n+import org.elasticsearch.common.xcontent.XContentType;\n+import org.elasticsearch.test.ElasticsearchTestCase;\n+import org.hamcrest.Matchers;\n+import org.junit.Test;\n+\n+import java.io.ByteArrayInputStream;\n+import java.io.IOException;\n+\n+import static org.hamcrest.CoreMatchers.not;\n+import static org.hamcrest.Matchers.isEmptyString;\n+import static org.hamcrest.Matchers.nullValue;\n+\n+public abstract class AbstractFilteringJsonGeneratorTests extends ElasticsearchTestCase {\n+\n+    protected abstract XContentType getXContentType();\n+\n+    protected abstract void assertXContentBuilder(String expected, XContentBuilder builder);\n+\n+    protected void assertString(String expected, XContentBuilder builder) {\n+        assertNotNull(builder);\n+        assertNotNull(expected);\n+        assertNotNull(expected, not(isEmptyString()));\n+\n+        // Verify that the result is equal to the expected string\n+        assertThat(builder.bytes().toUtf8(), Matchers.equalTo(expected));\n+    }\n+\n+    protected void assertBinary(String expected, XContentBuilder builder) {\n+        assertNotNull(builder);\n+        assertNotNull(expected);\n+        assertNotNull(expected, not(isEmptyString()));\n+\n+        try {\n+            XContentParser jsonParser = XContentFactory.xContent(XContentType.JSON).createParser(expected.getBytes(\"UTF8\"));\n+            XContentParser xsonParser = XContentFactory.xContent(builder.contentType()).createParser(builder.bytes());\n+\n+            while (true) {\n+                XContentParser.Token token1 = jsonParser.nextToken();\n+                XContentParser.Token token2 = xsonParser.nextToken();\n+                if (token1 == null) {\n+                    assertThat(token2, nullValue());\n+                    return;\n+                }\n+                assertThat(token1, Matchers.equalTo(token2));\n+                switch (token1) {\n+                    case FIELD_NAME:\n+                        assertThat(jsonParser.currentName(), Matchers.equalTo(xsonParser.currentName()));","path":"src/test/java/org/elasticsearch/common/xcontent/support/filtering/AbstractFilteringJsonGeneratorTests.java","position":72,"original_position":72,"commit_id":"73a93c7158a994ff4cc68975dd7fd9ebd96bc79f","original_commit_id":"73a93c7158a994ff4cc68975dd7fd9ebd96bc79f","user":{"login":"spinscale","id":667544,"avatar_url":"https://avatars.githubusercontent.com/u/667544?v=3","gravatar_id":"","url":"https://api.github.com/users/spinscale","html_url":"https://github.com/spinscale","followers_url":"https://api.github.com/users/spinscale/followers","following_url":"https://api.github.com/users/spinscale/following{/other_user}","gists_url":"https://api.github.com/users/spinscale/gists{/gist_id}","starred_url":"https://api.github.com/users/spinscale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spinscale/subscriptions","organizations_url":"https://api.github.com/users/spinscale/orgs","repos_url":"https://api.github.com/users/spinscale/repos","events_url":"https://api.github.com/users/spinscale/events{/privacy}","received_events_url":"https://api.github.com/users/spinscale/received_events","type":"User","site_admin":false},"body":"static import of Matchers or just static import `Matchers.is()` (but thats my personal preference over `equalTo`...)","created_at":"2015-05-05T15:57:20Z","updated_at":"2015-05-05T15:57:20Z","html_url":"https://github.com/elastic/elasticsearch/pull/10980#discussion_r29683129","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/10980","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/29683129"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/10980#discussion_r29683129"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/10980"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/10980","id":34718542,"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","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10980","number":10980,"state":"open","locked":false,"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},"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```","created_at":"2015-05-05T12:18:56Z","updated_at":"2015-05-05T15:57:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aeb0626134d0e6542923447f58400974bc45dd73","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/10980/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/10980/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10980/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/73a93c7158a994ff4cc68975dd7fd9ebd96bc79f","head":{"label":"tlrx:response-filtering-with-path-parameter","ref":"response-filtering-with-path-parameter","sha":"73a93c7158a994ff4cc68975dd7fd9ebd96bc79f","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},"repo":{"id":24718639,"name":"elasticsearch","full_name":"tlrx/elasticsearch","owner":{"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},"private":false,"html_url":"https://github.com/tlrx/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/tlrx/elasticsearch","forks_url":"https://api.github.com/repos/tlrx/elasticsearch/forks","keys_url":"https://api.github.com/repos/tlrx/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tlrx/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tlrx/elasticsearch/teams","hooks_url":"https://api.github.com/repos/tlrx/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/tlrx/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/tlrx/elasticsearch/events","assignees_url":"https://api.github.com/repos/tlrx/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/tlrx/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/tlrx/elasticsearch/tags","blobs_url":"https://api.github.com/repos/tlrx/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tlrx/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tlrx/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/tlrx/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tlrx/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/tlrx/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/tlrx/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/tlrx/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/tlrx/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/tlrx/elasticsearch/subscription","commits_url":"https://api.github.com/repos/tlrx/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/tlrx/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/tlrx/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/tlrx/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/tlrx/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/tlrx/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tlrx/elasticsearch/merges","archive_url":"https://api.github.com/repos/tlrx/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tlrx/elasticsearch/downloads","issues_url":"https://api.github.com/repos/tlrx/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/tlrx/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/tlrx/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/tlrx/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tlrx/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/tlrx/elasticsearch/releases{/id}","created_at":"2014-10-02T12:51:44Z","updated_at":"2014-10-02T08:42:36Z","pushed_at":"2015-05-05T15:20:23Z","git_url":"git://github.com/tlrx/elasticsearch.git","ssh_url":"git@github.com:tlrx/elasticsearch.git","clone_url":"https://github.com/tlrx/elasticsearch.git","svn_url":"https://github.com/tlrx/elasticsearch","homepage":"http://elasticsearch.org","size":110173,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elastic:master","ref":"master","sha":"00d663f594f972bc79b962b5fd5f9c9c343ede32","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":507775,"name":"elasticsearch","full_name":"elastic/elasticsearch","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":false,"url":"https://api.github.com/repos/elastic/elasticsearch","forks_url":"https://api.github.com/repos/elastic/elasticsearch/forks","keys_url":"https://api.github.com/repos/elastic/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/elasticsearch/teams","hooks_url":"https://api.github.com/repos/elastic/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/elasticsearch/events","assignees_url":"https://api.github.com/repos/elastic/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/elasticsearch/tags","blobs_url":"https://api.github.com/repos/elastic/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/elastic/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/elastic/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/elastic/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/elastic/elasticsearch/subscription","commits_url":"https://api.github.com/repos/elastic/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/elasticsearch/merges","archive_url":"https://api.github.com/repos/elastic/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/elasticsearch/downloads","issues_url":"https://api.github.com/repos/elastic/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/elastic/elasticsearch/releases{/id}","created_at":"2010-02-08T13:20:56Z","updated_at":"2015-05-05T15:51:09Z","pushed_at":"2015-05-05T15:52:21Z","git_url":"git://github.com/elastic/elasticsearch.git","ssh_url":"git@github.com:elastic/elasticsearch.git","clone_url":"https://github.com/elastic/elasticsearch.git","svn_url":"https://github.com/elastic/elasticsearch","homepage":"http://elasticsearch.org","size":351258,"stargazers_count":11056,"watchers_count":11056,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3483,"mirror_url":null,"open_issues_count":1108,"forks":3483,"open_issues":1108,"watchers":11056,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/10980"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/10980"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/10980"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/10980/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/10980/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/10980/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/73a93c7158a994ff4cc68975dd7fd9ebd96bc79f"}}}}