WARNING: Version 1.7 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Named Queries and Filters
editNamed Queries and Filters
editEach filter and query can accept a _name
in its top level definition.
{ "filtered" : { "query" : { "bool" : { "should" : [ {"match" : { "name.first" : {"query" : "shay", "_name" : "first"} }}, {"match" : { "name.last" : {"query" : "banon", "_name" : "last"} }} ] } }, "filter" : { "terms" : { "name.last" : ["banon", "kimchy"], "_name" : "test" } } } }
The search response will include for each hit the matched_queries
it matched on. The tagging of queries and filters
only make sense for compound queries and filters (such as bool
query and filter, or
and and
filter, filtered
query etc.).
Note, the query filter had to be enhanced in order to support this. In
order to set a name, the fquery
filter should be used, which wraps a
query (just so there will be a place to set a name for it), for example:
{ "filtered" : { "query" : { "term" : { "name.first" : "shay" } }, "filter" : { "fquery" : { "query" : { "term" : { "name.last" : "banon" } }, "_name" : "test" } } } }
Named queries
editThe support for the _name
option on queries is available from version 0.90.4
and the support on filters is available
also in versions before 0.90.4
.