diff --git a/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc b/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc index d18f48e1ab4..82e2d45c2ca 100644 --- a/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc @@ -19,7 +19,7 @@ The top_hits aggregation returns regular search hits, because of this many per h * <> * <> -* <> +* <> * <> * <> * <> diff --git a/docs/reference/query-dsl/bool-query.asciidoc b/docs/reference/query-dsl/bool-query.asciidoc index 021a2b2b0bd..1a78e131e01 100644 --- a/docs/reference/query-dsl/bool-query.asciidoc +++ b/docs/reference/query-dsl/bool-query.asciidoc @@ -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 -<> 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" + } + } + } + } +} +---- diff --git a/docs/reference/redirects.asciidoc b/docs/reference/redirects.asciidoc index 34136b24741..d5985d0e8ef 100644 --- a/docs/reference/redirects.asciidoc +++ b/docs/reference/redirects.asciidoc @@ -87,7 +87,7 @@ See <>. [role="exclude",id="search-request-named-queries-and-filters"] === Named query parameter for request body search API -See <>. +See <>. [role="exclude",id="search-request-post-filter"] === Post filter parameter for request body search API @@ -1007,6 +1007,11 @@ See <>. [role="exclude",id="highlighter-internal-work"] ==== How highlighters work internally +[role="exclude",id="request-body-search-queries-and-filters"] +=== Named queries + +See <. + See <>. [role="exclude",id="request-body-search-scroll"] diff --git a/docs/reference/search/request-body.asciidoc b/docs/reference/search/request-body.asciidoc index fafdb3169c7..f56d6a49bef 100644 --- a/docs/reference/search/request-body.asciidoc +++ b/docs/reference/search/request-body.asciidoc @@ -129,7 +129,10 @@ include::request/inner-hits.asciidoc[] include::request/min-score.asciidoc[] -include::request/named-queries-and-filters.asciidoc[] +[[request-body-search-queries-and-filters]] +==== Named queries + +See <>. include::request/post-filter.asciidoc[] diff --git a/docs/reference/search/request/named-queries-and-filters.asciidoc b/docs/reference/search/request/named-queries-and-filters.asciidoc deleted file mode 100644 index 1482e434d3a..00000000000 --- a/docs/reference/search/request/named-queries-and-filters.asciidoc +++ /dev/null @@ -1,29 +0,0 @@ -[[request-body-search-queries-and-filters]] -==== Named Queries - -Each filter and query can accept a `_name` in its top level definition. - -[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" - } - } - } - } -} --------------------------------------------------- - -The search response will include for each hit the `matched_queries` it matched on. The tagging of queries and filters -only make sense for the `bool` query. -