From 86f1b07df07bdebb70cebf7e8f8f0b40a46bfc7c Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Fri, 11 Sep 2015 10:35:56 +0200 Subject: [PATCH] Docs: Remove docs for the `filtered`, `and`, `or` and `(f)query` queries. --- .../bucket/histogram-aggregation.asciidoc | 2 +- .../metrics/sum-aggregation.asciidoc | 3 +- docs/reference/getting-started.asciidoc | 12 +- docs/reference/migration/migrate_1_0.asciidoc | 2 +- docs/reference/query-dsl/and-query.asciidoc | 34 ------ .../query-dsl/compound-queries.asciidoc | 17 --- .../query-dsl/filtered-query.asciidoc | 96 ---------------- .../query-dsl/geo-bounding-box-query.asciidoc | 28 ++--- .../query-dsl/geo-distance-query.asciidoc | 20 ++-- .../geo-distance-range-query.asciidoc | 4 +- .../query-dsl/geo-polygon-query.asciidoc | 14 +-- .../query-dsl/geo-shape-query.asciidoc | 8 +- .../query-dsl/geohash-cell-query.asciidoc | 4 +- docs/reference/query-dsl/limit-query.asciidoc | 19 ---- docs/reference/query-dsl/not-query.asciidoc | 8 +- docs/reference/query-dsl/or-query.asciidoc | 29 ----- .../reference/query-dsl/script-query.asciidoc | 12 +- docs/reference/query-dsl/terms-query.asciidoc | 16 +-- docs/reference/redirects.asciidoc | 104 ++++++++++++++---- docs/reference/search.asciidoc | 4 +- .../named-queries-and-filters.asciidoc | 45 ++------ .../search/request/post-filter.asciidoc | 34 +++--- .../reference/search/search-template.asciidoc | 6 +- docs/reference/search/validate.asciidoc | 14 +-- 24 files changed, 179 insertions(+), 356 deletions(-) delete mode 100644 docs/reference/query-dsl/and-query.asciidoc delete mode 100644 docs/reference/query-dsl/filtered-query.asciidoc delete mode 100644 docs/reference/query-dsl/limit-query.asciidoc delete mode 100644 docs/reference/query-dsl/or-query.asciidoc diff --git a/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc b/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc index bc8a6e13ffd0..e01a067670b4 100644 --- a/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc @@ -148,7 +148,7 @@ Example: -------------------------------------------------- { "query" : { - "filtered" : { "filter": { "range" : { "price" : { "to" : "500" } } } } + "constant_score" : { "filter": { "range" : { "price" : { "to" : "500" } } } } }, "aggs" : { "prices" : { diff --git a/docs/reference/aggregations/metrics/sum-aggregation.asciidoc b/docs/reference/aggregations/metrics/sum-aggregation.asciidoc index 98286e9396ff..d55fcd01018c 100644 --- a/docs/reference/aggregations/metrics/sum-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/sum-aggregation.asciidoc @@ -9,8 +9,7 @@ Assuming the data consists of documents representing stock ticks, where each tic -------------------------------------------------- { "query" : { - "filtered" : { - "query" : { "match_all" : {}}, + "constant_score" : { "filter" : { "range" : { "timestamp" : { "from" : "now/1d+9.5h", "to" : "now/1d+16h" }} } diff --git a/docs/reference/getting-started.asciidoc b/docs/reference/getting-started.asciidoc index e69cfb43782c..473287dbc612 100755 --- a/docs/reference/getting-started.asciidoc +++ b/docs/reference/getting-started.asciidoc @@ -862,17 +862,17 @@ In the previous section, we skipped over a little detail called the document sco But queries do not always need to produce scores, in particular when they are only used for "filtering" the document set. Elasticsearch detects these situations and automatically optimizes query execution in order not to compute useless scores. -To understand filters, let's first introduce the <>, which allows you to combine a query (like `match_all`, `match`, `bool`, etc.) together with another query which is only used for filtering. As an example, let's introduce the <>, which allows us to filter documents by a range of values. This is generally used for numeric or date filtering. +The <> that we introduced in the previous section also supports `filter` clauses which allow to use a query to restrict the documents that will be matched by other clauses, without changing how scores are computed. As an example, let's introduce the <>, which allows us to filter documents by a range of values. This is generally used for numeric or date filtering. -This example uses a filtered query to return all accounts with balances between 20000 and 30000, inclusive. In other words, we want to find accounts with a balance that is greater than or equal to 20000 and less than or equal to 30000. +This example uses a bool query to return all accounts with balances between 20000 and 30000, inclusive. In other words, we want to find accounts with a balance that is greater than or equal to 20000 and less than or equal to 30000. [source,sh] -------------------------------------------------- curl -XPOST 'localhost:9200/bank/_search?pretty' -d ' { "query": { - "filtered": { - "query": { "match_all": {} }, + "bool": { + "must": { "match_all": {} }, "filter": { "range": { "balance": { @@ -886,9 +886,9 @@ curl -XPOST 'localhost:9200/bank/_search?pretty' -d ' }' -------------------------------------------------- -Dissecting the above, the filtered query contains a `match_all` query (the query part) and a `range` query (the filter part). We can substitute any other queries into the query and the filter parts. In the above case, the range query makes perfect sense since documents falling into the range all match "equally", i.e., no document is more relevant than another. +Dissecting the above, the bool query contains a `match_all` query (the query part) and a `range` query (the filter part). We can substitute any other queries into the query and the filter parts. In the above case, the range query makes perfect sense since documents falling into the range all match "equally", i.e., no document is more relevant than another. -In addition to the `match_all`, `match`, `bool`, `filtered`, and `range` queries, there are a lot of other query types that are available and we won't go into them here. Since we already have a basic understanding of how they work, it shouldn't be too difficult to apply this knowledge in learning and experimenting with the other query types. +In addition to the `match_all`, `match`, `bool`, and `range` queries, there are a lot of other query types that are available and we won't go into them here. Since we already have a basic understanding of how they work, it shouldn't be too difficult to apply this knowledge in learning and experimenting with the other query types. === Executing Aggregations diff --git a/docs/reference/migration/migrate_1_0.asciidoc b/docs/reference/migration/migrate_1_0.asciidoc index 66b1245855bc..c8750d11b82d 100644 --- a/docs/reference/migration/migrate_1_0.asciidoc +++ b/docs/reference/migration/migrate_1_0.asciidoc @@ -188,7 +188,7 @@ GET /_count Also, the top-level `filter` parameter in search has been renamed to <>, to indicate that it should not be used as the primary way to filter search results (use a -<> instead), but only to filter +<> instead), but only to filter results AFTER aggregations have been calculated. This example counts the top colors in all matching docs, but only returns docs diff --git a/docs/reference/query-dsl/and-query.asciidoc b/docs/reference/query-dsl/and-query.asciidoc deleted file mode 100644 index 5ef23af2c1af..000000000000 --- a/docs/reference/query-dsl/and-query.asciidoc +++ /dev/null @@ -1,34 +0,0 @@ -[[query-dsl-and-query]] -=== And Query - -deprecated[2.0.0-beta1, Use the `bool` query instead] - -A query that matches documents using the `AND` boolean operator on other -queries. - -[source,js] --------------------------------------------------- -{ - "filtered" : { - "query" : { - "term" : { "name.first" : "shay" } - }, - "filter" : { - "and" : [ - { - "range" : { - "postDate" : { - "from" : "2010-03-01", - "to" : "2010-04-01" - } - } - }, - { - "prefix" : { "name.second" : "ba" } - } - ] - } - } -} --------------------------------------------------- - diff --git a/docs/reference/query-dsl/compound-queries.asciidoc b/docs/reference/query-dsl/compound-queries.asciidoc index 0228ddd90aae..c6a1f0f2c3ab 100644 --- a/docs/reference/query-dsl/compound-queries.asciidoc +++ b/docs/reference/query-dsl/compound-queries.asciidoc @@ -41,18 +41,6 @@ documents which also match a `negative` query. Execute one query for the specified indices, and another for other indices. -<>, <>, <>:: - -Synonyms for the `bool` query. - -<>:: - -Combine a query clause in query context with another in filter context. deprecated[2.0.0-beta1,Use the `bool` query instead] - -<>:: - -Limits the number of documents examined per shard. - include::constant-score-query.asciidoc[] include::bool-query.asciidoc[] @@ -60,10 +48,5 @@ include::dis-max-query.asciidoc[] include::function-score-query.asciidoc[] include::boosting-query.asciidoc[] include::indices-query.asciidoc[] -include::and-query.asciidoc[] include::not-query.asciidoc[] -include::or-query.asciidoc[] -include::filtered-query.asciidoc[] -include::limit-query.asciidoc[] - diff --git a/docs/reference/query-dsl/filtered-query.asciidoc b/docs/reference/query-dsl/filtered-query.asciidoc deleted file mode 100644 index 5d399d07df43..000000000000 --- a/docs/reference/query-dsl/filtered-query.asciidoc +++ /dev/null @@ -1,96 +0,0 @@ -[[query-dsl-filtered-query]] -=== Filtered Query - -deprecated[2.0.0-beta1, Use the `bool` query instead with a `must` clause for the query and a `filter` clause for the filter] - -The `filtered` query is used to combine a query which will be used for -scoring with another query which will only be used for filtering the result -set. - -TIP: Exclude as many document as you can with a filter, then query just the -documents that remain. - -[source,js] --------------------------------------------------- -{ - "filtered": { - "query": { - "match": { "tweet": "full text search" } - }, - "filter": { - "range": { "created": { "gte": "now-1d/d" }} - } - } -} --------------------------------------------------- - -The `filtered` query can be used wherever a `query` is expected, for instance, -to use the above example in search request: - -[source,js] --------------------------------------------------- -curl -XGET localhost:9200/_search -d ' -{ - "query": { - "filtered": { <1> - "query": { - "match": { "tweet": "full text search" } - }, - "filter": { - "range": { "created": { "gte": "now-1d/d" }} - } - } - } -} -' --------------------------------------------------- -<1> The `filtered` query is passed as the value of the `query` - parameter in the search request. - -==== Filtering without a query - -If a `query` is not specified, it defaults to the -<>. This means that the -`filtered` query can be used to wrap just a filter, so that it can be used -wherever a query is expected. - -[source,js] --------------------------------------------------- -curl -XGET localhost:9200/_search -d ' -{ - "query": { - "filtered": { <1> - "filter": { - "range": { "created": { "gte": "now-1d/d" }} - } - } - } -} -' --------------------------------------------------- -<1> No `query` has been specified, so this request applies just the filter, - returning all documents created since yesterday. - -===== Multiple filters - -Multiple filters can be applied by wrapping them in a -<>, for example: - -[source,js] --------------------------------------------------- -{ - "filtered": { - "query": { "match": { "tweet": "full text search" }}, - "filter": { - "bool": { - "must": { "range": { "created": { "gte": "now-1d/d" }}}, - "should": [ - { "term": { "featured": true }}, - { "term": { "starred": true }} - ], - "must_not": { "term": { "deleted": false }} - } - } - } -} --------------------------------------------------- diff --git a/docs/reference/query-dsl/geo-bounding-box-query.asciidoc b/docs/reference/query-dsl/geo-bounding-box-query.asciidoc index 60aab15b54a7..6710461b5ba1 100644 --- a/docs/reference/query-dsl/geo-bounding-box-query.asciidoc +++ b/docs/reference/query-dsl/geo-bounding-box-query.asciidoc @@ -22,8 +22,8 @@ Then the following simple query can be executed with a [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { @@ -75,8 +75,8 @@ representation of the geo point, the filter can accept it as well: [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "boost" : { + "must" : { "match_all" : {} }, "filter" : { @@ -106,8 +106,8 @@ conform with http://geojson.org/[GeoJSON]. [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { @@ -130,8 +130,8 @@ Format in `lat,lon`. [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { @@ -152,8 +152,8 @@ Format in `lat,lon`. [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { @@ -181,8 +181,8 @@ values separately. [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { @@ -227,8 +227,8 @@ are not supported. Here is an example: [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { diff --git a/docs/reference/query-dsl/geo-distance-query.asciidoc b/docs/reference/query-dsl/geo-distance-query.asciidoc index 130319d951f3..c5b6029dc2f2 100644 --- a/docs/reference/query-dsl/geo-distance-query.asciidoc +++ b/docs/reference/query-dsl/geo-distance-query.asciidoc @@ -22,8 +22,8 @@ filter: [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { @@ -51,8 +51,8 @@ representation of the geo point, the filter can accept it as well: [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { @@ -77,8 +77,8 @@ conform with http://geojson.org/[GeoJSON]. [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { @@ -99,8 +99,8 @@ Format in `lat,lon`. [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { @@ -119,8 +119,8 @@ Format in `lat,lon`. [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { diff --git a/docs/reference/query-dsl/geo-distance-range-query.asciidoc b/docs/reference/query-dsl/geo-distance-range-query.asciidoc index cacf0a7a9cb9..901cca09829f 100644 --- a/docs/reference/query-dsl/geo-distance-range-query.asciidoc +++ b/docs/reference/query-dsl/geo-distance-range-query.asciidoc @@ -6,8 +6,8 @@ Filters documents that exists within a range from a specific point: [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "boost" : { + "must" : { "match_all" : {} }, "filter" : { diff --git a/docs/reference/query-dsl/geo-polygon-query.asciidoc b/docs/reference/query-dsl/geo-polygon-query.asciidoc index ff53a351b678..306b2dd2d849 100644 --- a/docs/reference/query-dsl/geo-polygon-query.asciidoc +++ b/docs/reference/query-dsl/geo-polygon-query.asciidoc @@ -7,7 +7,7 @@ points. Here is an example: [source,js] -------------------------------------------------- { - "filtered" : { + "bool" : { "query" : { "match_all" : {} }, @@ -53,8 +53,8 @@ conform with http://geojson.org/[GeoJSON]. [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { @@ -80,8 +80,8 @@ Format in `lat,lon`. [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { @@ -105,8 +105,8 @@ Format in `lat,lon`. [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { diff --git a/docs/reference/query-dsl/geo-shape-query.asciidoc b/docs/reference/query-dsl/geo-shape-query.asciidoc index 8ab2f13a22c6..77deabcad91a 100644 --- a/docs/reference/query-dsl/geo-shape-query.asciidoc +++ b/docs/reference/query-dsl/geo-shape-query.asciidoc @@ -40,8 +40,8 @@ The following query will find the point using the Elasticsearch's -------------------------------------------------- { "query":{ - "filtered": { - "query": { + "bool": { + "must": { "match_all": {} }, "filter": { @@ -81,8 +81,8 @@ shape: [source,js] -------------------------------------------------- { - "filtered": { - "query": { + "bool": { + "must": { "match_all": {} }, "filter": { diff --git a/docs/reference/query-dsl/geohash-cell-query.asciidoc b/docs/reference/query-dsl/geohash-cell-query.asciidoc index c3c83de18662..807e86715729 100644 --- a/docs/reference/query-dsl/geohash-cell-query.asciidoc +++ b/docs/reference/query-dsl/geohash-cell-query.asciidoc @@ -43,8 +43,8 @@ next to the given cell. [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "match_all" : {} }, "filter" : { diff --git a/docs/reference/query-dsl/limit-query.asciidoc b/docs/reference/query-dsl/limit-query.asciidoc deleted file mode 100644 index 198ad7862ab7..000000000000 --- a/docs/reference/query-dsl/limit-query.asciidoc +++ /dev/null @@ -1,19 +0,0 @@ -[[query-dsl-limit-query]] -=== Limit Query - -A limit query limits the number of documents (per shard) to execute on. -For example: - -[source,js] --------------------------------------------------- -{ - "filtered" : { - "filter" : { - "limit" : {"value" : 100} - }, - "query" : { - "term" : { "name.first" : "shay" } - } - } -} --------------------------------------------------- diff --git a/docs/reference/query-dsl/not-query.asciidoc b/docs/reference/query-dsl/not-query.asciidoc index a74a0f11734c..7854ee90afa5 100644 --- a/docs/reference/query-dsl/not-query.asciidoc +++ b/docs/reference/query-dsl/not-query.asciidoc @@ -6,8 +6,8 @@ A query that filters out matched documents using a query. For example: [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "term" : { "name.first" : "shay" } }, "filter" : { @@ -29,8 +29,8 @@ Or, in a longer form with a `filter` element: [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { + "bool" : { + "must" : { "term" : { "name.first" : "shay" } }, "filter" : { diff --git a/docs/reference/query-dsl/or-query.asciidoc b/docs/reference/query-dsl/or-query.asciidoc deleted file mode 100644 index 46005dc58c84..000000000000 --- a/docs/reference/query-dsl/or-query.asciidoc +++ /dev/null @@ -1,29 +0,0 @@ -[[query-dsl-or-query]] -=== Or Query - -deprecated[2.0.0-beta1, Use the `bool` query instead] - -A query that matches documents using the `OR` boolean operator on other -queries. - -[source,js] --------------------------------------------------- -{ - "filtered" : { - "query" : { - "term" : { "name.first" : "shay" } - }, - "filter" : { - "or" : [ - { - "term" : { "name.second" : "banon" } - }, - { - "term" : { "name.nick" : "kimchy" } - } - ] - } - } -} --------------------------------------------------- - diff --git a/docs/reference/query-dsl/script-query.asciidoc b/docs/reference/query-dsl/script-query.asciidoc index c14e8142f7db..223460f723d5 100644 --- a/docs/reference/query-dsl/script-query.asciidoc +++ b/docs/reference/query-dsl/script-query.asciidoc @@ -2,13 +2,13 @@ === Script Query A query allowing to define -<> as filters. For -example: +<> as queries. They are typically used in a filter +context, for example: [source,js] ---------------------------------------------- -"filtered" : { - "query" : { +"bool" : { + "must" : { ... }, "filter" : { @@ -28,8 +28,8 @@ to use the ability to pass parameters to the script itself, for example: [source,js] ---------------------------------------------- -"filtered" : { - "query" : { +"bool" : { + "must" : { ... }, "filter" : { diff --git a/docs/reference/query-dsl/terms-query.asciidoc b/docs/reference/query-dsl/terms-query.asciidoc index 58b0ba5d85b2..16cfd8cd89a5 100644 --- a/docs/reference/query-dsl/terms-query.asciidoc +++ b/docs/reference/query-dsl/terms-query.asciidoc @@ -79,16 +79,12 @@ curl -XPUT localhost:9200/tweets/tweet/1 -d '{ # search on all the tweets that match the followers of user 2 curl -XGET localhost:9200/tweets/_search -d '{ "query" : { - "filtered" : { - "filter" : { - "terms" : { - "user" : { - "index" : "users", - "type" : "user", - "id" : "2", - "path" : "followers" - } - } + "terms" : { + "user" : { + "index" : "users", + "type" : "user", + "id" : "2", + "path" : "followers" } } } diff --git a/docs/reference/redirects.asciidoc b/docs/reference/redirects.asciidoc index 9c6a9b49aae9..922216aeb939 100644 --- a/docs/reference/redirects.asciidoc +++ b/docs/reference/redirects.asciidoc @@ -77,20 +77,6 @@ in ``query context'' and as a filter in ``filter context'' (see <>). Queries and filters have been merged. Any query clause can now be used as a query in ``query context'' and as a filter in ``filter context'' (see <>). -[role="exclude",id="query-dsl-and-filter"] -=== And Filter - -The `and` filter has been replaced by the <>. It behaves -as a query in ``query context'' and as a filter in ``filter context'' (see -<>). - -[role="exclude",id="query-dsl-or-filter"] -=== Or Filter - -The `or` filter has been replaced by the <>. It behaves -as a query in ``query context'' and as a filter in ``filter context'' (see -<>). - [role="exclude",id="query-dsl-not-filter"] === Not Filter @@ -195,13 +181,6 @@ The `indices` filter has been replaced by the <>. It b as a query in ``query context'' and as a filter in ``filter context'' (see <>). -[role="exclude",id="query-dsl-limit-filter"] -=== Limit Filter - -The `limit` filter has been replaced by the <>. -It behaves as a query in ``query context'' and as a filter in ``filter -context'' (see <>). - [role="exclude",id="query-dsl-match-all-filter"] === Match All Filter @@ -381,3 +360,86 @@ The shard query cache has been renamed <>. === Query cache The filter cache has been renamed <>. + +[role="exclude",id="query-dsl-filtered-query"] +=== Filtered query + +The `filtered` query is replaced in favour of the <> query. Instead of +the following: + +[source,js] +------------------------- +GET _search +{ + "query": { + "filtered": { + "query": { + "match": { + "text": "quick brown fox" + } + }, + "filter": { + "term": { + "status": "published" + } + } + } + } +} +------------------------- + +move the query and filter to the `must` and `filter` parameters in the `bool` +query: + +[source,js] +------------------------- +GET _search +{ + "query": { + "bool": { + "must": { + "match": { + "text": "quick brown fox" + } + }, + "filter": { + "term": { + "status": "published" + } + } + } + } +} +------------------------- + +[role="exclude",id="query-dsl-or-query"] +=== Or query + +The `or` query is replaced in favour of the <> query. + +[role="exclude",id="query-dsl-or-filter"] +=== Or filter + +The `or` filter is replaced in favour of the <> query. + +[role="exclude",id="query-dsl-and-query"] +=== And query + +The `and` query is replaced in favour of the <> query. + +[role="exclude",id="query-dsl-and-filter"] +=== And filter + +The `and` filter is replaced in favour of the <> query. + +[role="exclude",id="query-dsl-limit-query"] +=== Limit query + +The `limit` query is replaced in favour of the <> +parameter of search requests. + +[role="exclude",id="query-dsl-limit-filter"] +=== Limit filter + +The `limit` filter is replaced in favour of the <> +parameter of search requests. diff --git a/docs/reference/search.asciidoc b/docs/reference/search.asciidoc index 9a0de108c5ab..f59444d739ef 100644 --- a/docs/reference/search.asciidoc +++ b/docs/reference/search.asciidoc @@ -34,8 +34,8 @@ only the relevant shard: -------------------------------------------------- $ curl -XGET 'http://localhost:9200/twitter/tweet/_search?routing=kimchy' -d '{ "query": { - "filtered" : { - "query" : { + "bool" : { + "must" : { "query_string" : { "query" : "some query string here" } diff --git a/docs/reference/search/request/named-queries-and-filters.asciidoc b/docs/reference/search/request/named-queries-and-filters.asciidoc index 183f0e73f100..96d7c1357a93 100644 --- a/docs/reference/search/request/named-queries-and-filters.asciidoc +++ b/docs/reference/search/request/named-queries-and-filters.asciidoc @@ -1,20 +1,16 @@ [[search-request-named-queries-and-filters]] -=== Named Queries and Filters +=== Named Queries Each filter and query can accept a `_name` in its top level definition. [source,js] -------------------------------------------------- { - "filtered" : { - "query" : { - "bool" : { - "should" : [ - {"match" : { "name.first" : {"query" : "shay", "_name" : "first"} }}, - {"match" : { "name.last" : {"query" : "banon", "_name" : "last"} }} - ] - } - }, + "bool" : { + "should" : [ + {"match" : { "name.first" : {"query" : "shay", "_name" : "first"} }}, + {"match" : { "name.last" : {"query" : "banon", "_name" : "last"} }} + ], "filter" : { "terms" : { "name.last" : ["banon", "kimchy"], @@ -26,32 +22,5 @@ Each filter and query can accept a `_name` in its top level definition. -------------------------------------------------- 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.). +only make sense for the `bool` query. -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: - -[source,js] --------------------------------------------------- -{ - "filtered" : { - "query" : { - "term" : { "name.first" : "shay" } - }, - "filter" : { - "fquery" : { - "query" : { - "term" : { "name.last" : "banon" } - }, - "_name" : "test" - } - } - } -} --------------------------------------------------- - -==== Named queries - -The 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`. diff --git a/docs/reference/search/request/post-filter.asciidoc b/docs/reference/search/request/post-filter.asciidoc index 274d14bd698c..7c352e9fd502 100644 --- a/docs/reference/search/request/post-filter.asciidoc +++ b/docs/reference/search/request/post-filter.asciidoc @@ -2,28 +2,24 @@ === Post filter The `post_filter` is applied to the search `hits` at the very end of a search -request, after aggregations have already been calculated. It's purpose is +request, after aggregations have already been calculated. Its purpose is best explained by example: Imagine that you are selling shirts, and the user has specified two filters: `color:red` and `brand:gucci`. You only want to show them red shirts made by Gucci in the search results. Normally you would do this with a -<>: +<>: [source,js] -------------------------------------------------- curl -XGET localhost:9200/shirts/_search -d ' { "query": { - "filtered": { - "filter": { - "bool": { - "must": [ - { "term": { "color": "red" }}, - { "term": { "brand": "gucci" }} - ] - } - } + "bool": { + "filter": [ + { "term": { "color": "red" }}, + { "term": { "brand": "gucci" }} + ] } } } @@ -43,15 +39,11 @@ This can be done with a curl -XGET localhost:9200/shirts/_search -d ' { "query": { - "filtered": { - "filter": { - "bool": { - "must": [ - { "term": { "color": "red" }}, - { "term": { "brand": "gucci" }} - ] - } - } + "bool": { + "filter": [ + { "term": { "color": "red" }}, + { "term": { "brand": "gucci" }} + ] } }, "aggs": { @@ -78,7 +70,7 @@ the `post_filter`: curl -XGET localhost:9200/shirts/_search -d ' { "query": { - "filtered": { + "bool": { "filter": { { "term": { "brand": "gucci" }} <1> } diff --git a/docs/reference/search/search-template.asciidoc b/docs/reference/search/search-template.asciidoc index bce95289e8e4..77670acafb1e 100644 --- a/docs/reference/search/search-template.asciidoc +++ b/docs/reference/search/search-template.asciidoc @@ -169,8 +169,8 @@ We could write the query as: ------------------------------------------ { "query": { - "filtered": { - "query": { + "bool": { + "must": { "match": { "line": "{{text}}" <1> } @@ -212,7 +212,7 @@ via the REST API, should be written as a string: [source,js] -------------------- -"inline": "{\"query\":{\"filtered\":{\"query\":{\"match\":{\"line\":\"{{text}}\"}},\"filter\":{{{#line_no}}\"range\":{\"line_no\":{{{#start}}\"gte\":\"{{start}}\"{{#end}},{{/end}}{{/start}}{{#end}}\"lte\":\"{{end}}\"{{/end}}}}{{/line_no}}}}}}" +"inline": "{\"query\":{\"bool\":{\"must\":{\"match\":{\"line\":\"{{text}}\"}},\"filter\":{{{#line_no}}\"range\":{\"line_no\":{{{#start}}\"gte\":\"{{start}}\"{{#end}},{{/end}}{{/start}}{{#end}}\"lte\":\"{{end}}\"{{/end}}}}{{/line_no}}}}}}" -------------------- ================================== diff --git a/docs/reference/search/validate.asciidoc b/docs/reference/search/validate.asciidoc index b47f63e69420..a08e183089c1 100644 --- a/docs/reference/search/validate.asciidoc +++ b/docs/reference/search/validate.asciidoc @@ -55,8 +55,8 @@ Or, with a request body: -------------------------------------------------- curl -XGET 'http://localhost:9200/twitter/tweet/_validate/query' -d '{ "query" : { - "filtered" : { - "query" : { + "bool" : { + "must" : { "query_string" : { "query" : "*:*" } @@ -99,7 +99,7 @@ curl -XGET 'http://localhost:9200/twitter/tweet/_validate/query?q=post_date:foo& "explanations" : [ { "index" : "twitter", "valid" : false, - "error" : "org.elasticsearch.index.query.QueryParsingException: [twitter] Failed to parse; org.elasticsearch.ElasticsearchParseException: failed to parse date field [foo], tried both date format [dateOptionalTime], and timestamp number; java.lang.IllegalArgumentException: Invalid format: \"foo\"" + "error" : "[twitter] QueryParsingException[Failed to parse]; nested: IllegalArgumentException[Invalid format: \"foo\"];; java.lang.IllegalArgumentException: Invalid format: \"foo\"" } ] } -------------------------------------------------- @@ -112,14 +112,14 @@ For Fuzzy Queries: [source,js] -------------------------------------------------- -curl -XGET 'http://localhost:9200/imdb/movies/_validate/query?rewrite=true' +curl -XGET 'http://localhost:9200/imdb/movies/_validate/query?rewrite=true' -d ' { "query": { "fuzzy": { "actors": "kyle" } } -} +}' -------------------------------------------------- Response: @@ -137,7 +137,7 @@ Response: { "index": "imdb", "valid": true, - "explanation": "filtered(plot:kyle plot:kylie^0.75 plot:kyne^0.75 plot:lyle^0.75 plot:pyle^0.75)->cache(_type:movies)" + "explanation": "plot:kyle plot:kylie^0.75 plot:kyne^0.75 plot:lyle^0.75 plot:pyle^0.75 #_type:movies" } ] } @@ -175,7 +175,7 @@ Response: { "index": "imdb", "valid": true, - "explanation": "filtered(((title:terminator^3.71334 plot:future^2.763601 plot:human^2.8415773 plot:sarah^3.4193945 plot:kyle^3.8244398 plot:cyborg^3.9177752 plot:connor^4.040236 plot:reese^4.7133346 ... )~6) -ConstantScore(_uid:movies#88247))->cache(_type:movies)" + "explanation": "((title:terminator^3.71334 plot:future^2.763601 plot:human^2.8415773 plot:sarah^3.4193945 plot:kyle^3.8244398 plot:cyborg^3.9177752 plot:connor^4.040236 plot:reese^4.7133346 ... )~6) -ConstantScore(_uid:movies#88247) #_type:movies" } ] }