Skip to content

Commit 234c3b6

Browse files
committed
Rename _path to filter_path and update doc
1 parent 89edfbd commit 234c3b6

File tree

6 files changed

+42
-25
lines changed

6 files changed

+42
-25
lines changed

docs/reference/api-conventions.asciidoc

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ consumption. The default for the `human` flag is
8282
`false`.
8383

8484
[float]
85-
=== Response filtering
85+
=== Response Filtering
8686

87-
All REST APIs accept a `_path` parameter that can be used to reduce
87+
All REST APIs accept a `filter_path` parameter that can be used to reduce
8888
the response returned by elasticsearch. This parameter takes a comma
8989
separated list of filters expressed with the dot notation:
9090

9191
[source,sh]
9292
--------------------------------------------------
93-
curl -XGET 'localhost:9200/_search?pretty&_path=took,hits.hits._id,hits.hits._score'
93+
curl -XGET 'localhost:9200/_search?pretty&filter_path=took,hits.hits._id,hits.hits._score'
9494
{
9595
"took" : 3,
9696
"hits" : {
@@ -113,7 +113,7 @@ of a field's name:
113113

114114
[source,sh]
115115
--------------------------------------------------
116-
curl -XGET 'localhost:9200/_nodes/stats?_path=nodes.*.ho*'
116+
curl -XGET 'localhost:9200/_nodes/stats?filter_path=nodes.*.ho*'
117117
{
118118
"nodes" : {
119119
"lvJHed8uQQu4brS-SXKsNA" : {
@@ -123,13 +123,13 @@ curl -XGET 'localhost:9200/_nodes/stats?_path=nodes.*.ho*'
123123
}
124124
--------------------------------------------------
125125

126-
And the `**` wildcard can used to include fields without knowing the
126+
And the `**` wildcard can be used to include fields without knowing the
127127
exact path of the field. For example, we can return the Lucene version
128128
of every segment with this request:
129129

130130
[source,sh]
131131
--------------------------------------------------
132-
curl 'localhost:9200/_segments?pretty&_path=indices.**.version'
132+
curl 'localhost:9200/_segments?pretty&filter_path=indices.**.version'
133133
{
134134
"indices" : {
135135
"movies" : {
@@ -166,9 +166,26 @@ curl 'localhost:9200/_segments?pretty&_path=indices.**.version'
166166
--------------------------------------------------
167167

168168
Note that elasticsearch sometimes returns directly the raw value of a field,
169-
like the `_source` field. If you want to filter the response that include
170-
_source fields, you should consider using the already existing `_source`
171-
parameter (see <<get-source-filtering,Get API>> for more details).
169+
like the `_source` field. If you want to filter _source fields, you should
170+
consider combining the already existing `_source` parameter (see
171+
<<get-source-filtering,Get API>> for more details) with the `filter_path`
172+
parameter like this:
173+
174+
[source,sh]
175+
--------------------------------------------------
176+
curl -XGET 'localhost:9200/_search?pretty&filter_path=hits.hits._source&_source=title'
177+
{
178+
"hits" : {
179+
"hits" : [ {
180+
"_source":{"title":"Book #2"}
181+
}, {
182+
"_source":{"title":"Book #1"}
183+
}, {
184+
"_source":{"title":"Book #3"}
185+
} ]
186+
}
187+
}
188+
--------------------------------------------------
172189

173190

174191
[float]

rest-api-spec/api/nodes.stats.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"options" : ["node", "indices", "shards"],
5757
"default" : "node"
5858
},
59-
"_path": {
59+
"filter_path": {
6060
"type" : "list",
6161
"description" : "A comma-separated list of fields to include in the returned response"
6262
},

rest-api-spec/api/search.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"type" : "boolean",
7373
"description" : "Specify whether query terms should be lowercased"
7474
},
75-
"_path": {
75+
"filter_path": {
7676
"type" : "list",
7777
"description" : "A comma-separated list of fields to include in the returned response"
7878
},

rest-api-spec/test/nodes.stats/20_response_filtering.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# Nodes Stats with only "cluster_name" field
2929
- do:
3030
nodes.stats:
31-
_path: cluster_name
31+
filter_path: cluster_name
3232

3333
- is_true: cluster_name
3434
- is_false: nodes
@@ -39,7 +39,7 @@
3939
# Nodes Stats with "nodes" field and sub-fields
4040
- do:
4141
nodes.stats:
42-
_path: nodes.*
42+
filter_path: nodes.*
4343

4444
- is_false: cluster_name
4545
- is_true: nodes
@@ -59,7 +59,7 @@
5959
# Nodes Stats with "nodes.*.indices" field and sub-fields
6060
- do:
6161
nodes.stats:
62-
_path: nodes.*.indices
62+
filter_path: nodes.*.indices
6363

6464
- is_false: cluster_name
6565
- is_true: nodes
@@ -74,7 +74,7 @@
7474
# Nodes Stats with "nodes.*.name" and "nodes.*.indices.docs.count" fields
7575
- do:
7676
nodes.stats:
77-
_path: [ "nodes.*.name", "nodes.*.indices.docs.count" ]
77+
filter_path: [ "nodes.*.name", "nodes.*.indices.docs.count" ]
7878

7979
- is_false: cluster_name
8080
- is_true: nodes
@@ -88,7 +88,7 @@
8888
# Nodes Stats with all "count" fields
8989
- do:
9090
nodes.stats:
91-
_path: "nodes.**.count"
91+
filter_path: "nodes.**.count"
9292

9393
- is_false: cluster_name
9494
- is_true: nodes
@@ -108,7 +108,7 @@
108108
# Nodes Stats with all "count" fields in sub-fields of "jvm" field
109109
- do:
110110
nodes.stats:
111-
_path: "nodes.**.jvm.**.count"
111+
filter_path: "nodes.**.jvm.**.count"
112112

113113
- is_false: cluster_name
114114
- is_true: nodes
@@ -126,7 +126,7 @@
126126
# Nodes Stats with "nodes.*.fs.data" fields
127127
- do:
128128
nodes.stats:
129-
_path: "nodes.*.fs.data"
129+
filter_path: "nodes.*.fs.data"
130130

131131
- is_false: cluster_name
132132
- is_true: nodes
@@ -141,7 +141,7 @@
141141
# Nodes Stats with "nodes.*.fs.data.t*" fields
142142
- do:
143143
nodes.stats:
144-
_path: "nodes.*.fs.data.t*"
144+
filter_path: "nodes.*.fs.data.t*"
145145

146146
- is_false: cluster_name
147147
- is_true: nodes

rest-api-spec/test/search/70_response_filtering.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
- do:
2525
search:
2626
index: test
27-
_path: "*"
27+
filter_path: "*"
2828
body: "{ query: { match_all: {} } }"
2929

3030
- is_true: took
@@ -40,7 +40,7 @@
4040
- do:
4141
search:
4242
index: test
43-
_path: "took"
43+
filter_path: "took"
4444
body: "{ query: { match_all: {} } }"
4545

4646
- is_true: took
@@ -56,7 +56,7 @@
5656
- do:
5757
search:
5858
index: test
59-
_path: "_shards.*"
59+
filter_path: "_shards.*"
6060
body: "{ query: { match_all: {} } }"
6161

6262
- is_false: took
@@ -72,7 +72,7 @@
7272
- do:
7373
search:
7474
index: test
75-
_path: [ "hits.**._i*", "**.total" ]
75+
filter_path: [ "hits.**._i*", "**.total" ]
7676
body: "{ query: { match_all: {} } }"
7777

7878
- is_false: took

src/main/java/org/elasticsearch/rest/RestChannel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected RestChannel(RestRequest request, boolean detailedErrorsEnabled) {
4444
}
4545

4646
public XContentBuilder newBuilder() throws IOException {
47-
return newBuilder(request.hasContent() ? request.content() : null, request.hasParam("_path"));
47+
return newBuilder(request.hasContent() ? request.content() : null, request.hasParam("filter_path"));
4848
}
4949

5050
public XContentBuilder newErrorBuilder() throws IOException {
@@ -65,7 +65,7 @@ public XContentBuilder newBuilder(@Nullable BytesReference autoDetectSource, boo
6565
contentType = XContentType.JSON;
6666
}
6767

68-
String[] filters = useFiltering ? request.paramAsStringArrayOrEmptyIfAll("_path") : null;
68+
String[] filters = useFiltering ? request.paramAsStringArrayOrEmptyIfAll("filter_path") : null;
6969
XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(contentType), bytesOutput(), filters);
7070
if (request.paramAsBoolean("pretty", false)) {
7171
builder.prettyPrint().lfAtEnd();

0 commit comments

Comments
 (0)