|
@@ -142,9 +142,30 @@ GET _search
|
|
|
}
|
|
|
---------------------------------
|
|
|
|
|
|
-==== Using named queries to see which clauses matched
|
|
|
+[[named-queries]]
|
|
|
+==== Named queries
|
|
|
|
|
|
-If you need to know which of the clauses in the bool query matched the documents
|
|
|
-returned from the query, you can use
|
|
|
-<<request-body-search-queries-and-filters,named queries>> to assign a name to
|
|
|
-each clause.
|
|
|
+Each query accepts a `_name` in its top level definition. You can use named
|
|
|
+queries to track which queries matched returned documents. If named queries are
|
|
|
+used, the response includes a `matched_queries` property for each hit.
|
|
|
+
|
|
|
+[source,console]
|
|
|
+----
|
|
|
+GET /_search
|
|
|
+{
|
|
|
+ "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"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+----
|