forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API: Add response filtering with filter_path parameter
This change adds a new "filter_path" parameter that can be used to filter and reduce the responses returned by the REST API of elasticsearch. For example, returning only the shards that failed to be optimized: ``` curl -XPOST 'localhost:9200/beer/_optimize?filter_path=_shards.failed' {"_shards":{"failed":0}}% ``` It supports multiple filters (separated by a comma): ``` curl -XGET 'localhost:9200/_mapping?pretty&filter_path=*.mappings.*.properties.name,*.mappings.*.properties.title' ``` It also supports the YAML response format. Here it returns only the `_id` field of a newly indexed document: ``` curl -XPOST 'localhost:9200/library/book?filter_path=_id' -d '---hello:\n world: 1\n' --- _id: "AU0j64-b-stVfkvus5-A" ``` It also supports wildcards. Here it returns only the host name of every nodes in the cluster: ``` curl -XGET 'http://localhost:9200/_nodes/stats?filter_path=nodes.*.host*' {"nodes":{"lvJHed8uQQu4brS-SXKsNA":{"host":"portable"}}} ``` And "**" can be used to include sub fields without knowing the exact path. Here it returns only the Lucene version of every segment: ``` curl 'http://localhost:9200/_segments?pretty&filter_path=indices.**.version' { "indices" : { "beer" : { "shards" : { "0" : [ { "segments" : { "_0" : { "version" : "5.2.0" }, "_1" : { "version" : "5.2.0" } } } ] } } } } ``` Note that elasticsearch sometimes returns directly the raw value of a field, like the _source field. 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 elastic#2"} }, { "_source":{"title":"Book elastic#1"} }, { "_source":{"title":"Book elastic#3"} } ] } } ```
- Loading branch information
Showing
31 changed files
with
1,986 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
rest-api-spec/test/nodes.stats/20_response_filtering.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
--- | ||
"Nodes Stats with response filtering": | ||
- do: | ||
cluster.state: {} | ||
|
||
# Get master node id | ||
- set: { master_node: master } | ||
|
||
# Nodes Stats with no filtering | ||
- do: | ||
nodes.stats: {} | ||
|
||
- is_true: cluster_name | ||
- is_true: nodes | ||
- is_true: nodes.$master.name | ||
- is_true: nodes.$master.indices | ||
- is_true: nodes.$master.indices.docs | ||
- gte: { nodes.$master.indices.docs.count: 0 } | ||
- is_true: nodes.$master.indices.segments | ||
- gte: { nodes.$master.indices.segments.count: 0 } | ||
- is_true: nodes.$master.jvm | ||
- is_true: nodes.$master.jvm.threads | ||
- gte: { nodes.$master.jvm.threads.count: 0 } | ||
- is_true: nodes.$master.jvm.buffer_pools.direct | ||
- gte: { nodes.$master.jvm.buffer_pools.direct.count: 0 } | ||
- gte: { nodes.$master.jvm.buffer_pools.direct.used_in_bytes: 0 } | ||
|
||
# Nodes Stats with only "cluster_name" field | ||
- do: | ||
nodes.stats: | ||
filter_path: cluster_name | ||
|
||
- is_true: cluster_name | ||
- is_false: nodes | ||
- is_false: nodes.$master.name | ||
- is_false: nodes.$master.indices | ||
- is_false: nodes.$master.jvm | ||
|
||
# Nodes Stats with "nodes" field and sub-fields | ||
- do: | ||
nodes.stats: | ||
filter_path: nodes.* | ||
|
||
- is_false: cluster_name | ||
- is_true: nodes | ||
- is_true: nodes.$master.name | ||
- is_true: nodes.$master.indices | ||
- is_true: nodes.$master.indices.docs | ||
- gte: { nodes.$master.indices.docs.count: 0 } | ||
- is_true: nodes.$master.indices.segments | ||
- gte: { nodes.$master.indices.segments.count: 0 } | ||
- is_true: nodes.$master.jvm | ||
- is_true: nodes.$master.jvm.threads | ||
- gte: { nodes.$master.jvm.threads.count: 0 } | ||
- is_true: nodes.$master.jvm.buffer_pools.direct | ||
- gte: { nodes.$master.jvm.buffer_pools.direct.count: 0 } | ||
- gte: { nodes.$master.jvm.buffer_pools.direct.used_in_bytes: 0 } | ||
|
||
# Nodes Stats with "nodes.*.indices" field and sub-fields | ||
- do: | ||
nodes.stats: | ||
filter_path: nodes.*.indices | ||
|
||
- is_false: cluster_name | ||
- is_true: nodes | ||
- is_false: nodes.$master.name | ||
- is_true: nodes.$master.indices | ||
- is_true: nodes.$master.indices.docs | ||
- gte: { nodes.$master.indices.docs.count: 0 } | ||
- is_true: nodes.$master.indices.segments | ||
- gte: { nodes.$master.indices.segments.count: 0 } | ||
- is_false: nodes.$master.jvm | ||
|
||
# Nodes Stats with "nodes.*.name" and "nodes.*.indices.docs.count" fields | ||
- do: | ||
nodes.stats: | ||
filter_path: [ "nodes.*.name", "nodes.*.indices.docs.count" ] | ||
|
||
- is_false: cluster_name | ||
- is_true: nodes | ||
- is_true: nodes.$master.name | ||
- is_true: nodes.$master.indices | ||
- is_true: nodes.$master.indices.docs | ||
- gte: { nodes.$master.indices.docs.count: 0 } | ||
- is_false: nodes.$master.indices.segments | ||
- is_false: nodes.$master.jvm | ||
|
||
# Nodes Stats with all "count" fields | ||
- do: | ||
nodes.stats: | ||
filter_path: "nodes.**.count" | ||
|
||
- is_false: cluster_name | ||
- is_true: nodes | ||
- is_false: nodes.$master.name | ||
- is_true: nodes.$master.indices | ||
- is_true: nodes.$master.indices.docs | ||
- gte: { nodes.$master.indices.docs.count: 0 } | ||
- is_true: nodes.$master.indices.segments | ||
- gte: { nodes.$master.indices.segments.count: 0 } | ||
- is_true: nodes.$master.jvm | ||
- is_true: nodes.$master.jvm.threads | ||
- gte: { nodes.$master.jvm.threads.count: 0 } | ||
- is_true: nodes.$master.jvm.buffer_pools.direct | ||
- gte: { nodes.$master.jvm.buffer_pools.direct.count: 0 } | ||
- is_false: nodes.$master.jvm.buffer_pools.direct.used_in_bytes | ||
|
||
# Nodes Stats with all "count" fields in sub-fields of "jvm" field | ||
- do: | ||
nodes.stats: | ||
filter_path: "nodes.**.jvm.**.count" | ||
|
||
- is_false: cluster_name | ||
- is_true: nodes | ||
- is_false: nodes.$master.name | ||
- is_false: nodes.$master.indices | ||
- is_false: nodes.$master.indices.docs.count | ||
- is_false: nodes.$master.indices.segments.count | ||
- is_true: nodes.$master.jvm | ||
- is_true: nodes.$master.jvm.threads | ||
- gte: { nodes.$master.jvm.threads.count: 0 } | ||
- is_true: nodes.$master.jvm.buffer_pools.direct | ||
- gte: { nodes.$master.jvm.buffer_pools.direct.count: 0 } | ||
- is_false: nodes.$master.jvm.buffer_pools.direct.used_in_bytes | ||
|
||
# Nodes Stats with "nodes.*.fs.data" fields | ||
- do: | ||
nodes.stats: | ||
filter_path: "nodes.*.fs.data" | ||
|
||
- is_false: cluster_name | ||
- is_true: nodes | ||
- is_false: nodes.$master.name | ||
- is_false: nodes.$master.indices | ||
- is_false: nodes.$master.jvm | ||
- is_true: nodes.$master.fs.data | ||
- is_true: nodes.$master.fs.data.0.path | ||
- is_true: nodes.$master.fs.data.0.type | ||
- is_true: nodes.$master.fs.data.0.total_in_bytes | ||
|
||
# Nodes Stats with "nodes.*.fs.data.t*" fields | ||
- do: | ||
nodes.stats: | ||
filter_path: "nodes.*.fs.data.t*" | ||
|
||
- is_false: cluster_name | ||
- is_true: nodes | ||
- is_false: nodes.$master.name | ||
- is_false: nodes.$master.indices | ||
- is_false: nodes.$master.jvm | ||
- is_true: nodes.$master.fs.data | ||
- is_false: nodes.$master.fs.data.0.path | ||
- is_true: nodes.$master.fs.data.0.type | ||
- is_true: nodes.$master.fs.data.0.total_in_bytes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--- | ||
"Search with response filtering": | ||
- do: | ||
indices.create: | ||
index: test | ||
- do: | ||
index: | ||
index: test | ||
type: test | ||
id: 1 | ||
body: { foo: bar } | ||
|
||
- do: | ||
index: | ||
index: test | ||
type: test | ||
id: 2 | ||
body: { foo: bar } | ||
|
||
- do: | ||
indices.refresh: | ||
index: [test] | ||
|
||
- do: | ||
search: | ||
index: test | ||
filter_path: "*" | ||
body: "{ query: { match_all: {} } }" | ||
|
||
- is_true: took | ||
- is_true: _shards.total | ||
- is_true: hits.total | ||
- is_true: hits.hits.0._index | ||
- is_true: hits.hits.0._type | ||
- is_true: hits.hits.0._id | ||
- is_true: hits.hits.1._index | ||
- is_true: hits.hits.1._type | ||
- is_true: hits.hits.1._id | ||
|
||
- do: | ||
search: | ||
index: test | ||
filter_path: "took" | ||
body: "{ query: { match_all: {} } }" | ||
|
||
- is_true: took | ||
- is_false: _shards.total | ||
- is_false: hits.total | ||
- is_false: hits.hits.0._index | ||
- is_false: hits.hits.0._type | ||
- is_false: hits.hits.0._id | ||
- is_false: hits.hits.1._index | ||
- is_false: hits.hits.1._type | ||
- is_false: hits.hits.1._id | ||
|
||
- do: | ||
search: | ||
index: test | ||
filter_path: "_shards.*" | ||
body: "{ query: { match_all: {} } }" | ||
|
||
- is_false: took | ||
- is_true: _shards.total | ||
- is_false: hits.total | ||
- is_false: hits.hits.0._index | ||
- is_false: hits.hits.0._type | ||
- is_false: hits.hits.0._id | ||
- is_false: hits.hits.1._index | ||
- is_false: hits.hits.1._type | ||
- is_false: hits.hits.1._id | ||
|
||
- do: | ||
search: | ||
index: test | ||
filter_path: [ "hits.**._i*", "**.total" ] | ||
body: "{ query: { match_all: {} } }" | ||
|
||
- is_false: took | ||
- is_true: _shards.total | ||
- is_true: hits.total | ||
- is_true: hits.hits.0._index | ||
- is_false: hits.hits.0._type | ||
- is_true: hits.hits.0._id | ||
- is_true: hits.hits.1._index | ||
- is_false: hits.hits.1._type | ||
- is_true: hits.hits.1._id | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.