From a865090cf33e88ceef39ea164c37b07b884343ae Mon Sep 17 00:00:00 2001 From: Isabel Drost-Fromm Date: Tue, 10 May 2016 12:42:17 +0200 Subject: [PATCH] CONSOLE is the new AUTOSENSE --- .../query-dsl/constant-score-query.asciidoc | 14 +- .../query-dsl/function-score-query.asciidoc | 102 ++++++------ .../query-dsl/geo-distance-query.asciidoc | 110 ++++++------- .../query-dsl/match-all-query.asciidoc | 27 ++-- docs/reference/query-dsl/mlt-query.asciidoc | 146 +++++++++--------- .../query-dsl/multi-match-query.asciidoc | 132 ++++++++-------- .../reference/query-dsl/prefix-query.asciidoc | 6 +- .../query-dsl/query_filter_context.asciidoc | 2 +- docs/reference/query-dsl/range-query.asciidoc | 10 +- .../simple-query-string-query.asciidoc | 20 +-- .../query-dsl/span-first-query.asciidoc | 16 +- .../query-dsl/span-or-query.asciidoc | 16 +- .../query-dsl/template-query.asciidoc | 12 +- docs/reference/query-dsl/type-query.asciidoc | 10 +- 14 files changed, 313 insertions(+), 310 deletions(-) diff --git a/docs/reference/query-dsl/constant-score-query.asciidoc b/docs/reference/query-dsl/constant-score-query.asciidoc index 0928e9a5718..5002efcdabe 100644 --- a/docs/reference/query-dsl/constant-score-query.asciidoc +++ b/docs/reference/query-dsl/constant-score-query.asciidoc @@ -9,14 +9,14 @@ filter. Maps to Lucene `ConstantScoreQuery`. -------------------------------------------------- GET /_search { - "query": { - "constant_score" : { - "filter" : { - "term" : { "user" : "kimchy"} - }, - "boost" : 1.2 + "query": { + "constant_score" : { + "filter" : { + "term" : { "user" : "kimchy"} + }, + "boost" : 1.2 + } } - } } -------------------------------------------------- // CONSOLE diff --git a/docs/reference/query-dsl/function-score-query.asciidoc b/docs/reference/query-dsl/function-score-query.asciidoc index e48a396e6c8..e7e4b8f5877 100644 --- a/docs/reference/query-dsl/function-score-query.asciidoc +++ b/docs/reference/query-dsl/function-score-query.asciidoc @@ -16,14 +16,14 @@ by the query. -------------------------------------------------- GET /_search { - "query": { - "function_score": { - "query": {}, - "boost": "5", - "random_score": {}, <1> - "boost_mode":"multiply" + "query": { + "function_score": { + "query": {}, + "boost": "5", + "random_score": {}, <1> + "boost_mode":"multiply" + } } - } } -------------------------------------------------- // CONSOLE @@ -38,27 +38,27 @@ given filtering query -------------------------------------------------- GET /_search { - "query": { - "function_score": { - "query": {}, - "boost": "5", <1> - "functions": [ - { - "filter": {}, - "random_score": {}, <2> - "weight": 23 - }, - { - "filter": {}, - "weight": 42 - } - ], - "max_boost": 42, - "score_mode": "max", - "boost_mode": "multiply", - "min_score" : 42 + "query": { + "function_score": { + "query": {}, + "boost": "5", <1> + "functions": [ + { + "filter": {}, + "random_score": {}, <2> + "weight": 23 + }, + { + "filter": {}, + "weight": 42 + } + ], + "max_boost": 42, + "score_mode": "max", + "boost_mode": "multiply", + "min_score" : 42 + } } - } } -------------------------------------------------- // CONSOLE @@ -473,34 +473,34 @@ the request would look like this: -------------------------------------------------- GET /_search { - "query": { - "function_score": { - "functions": [ - { - "gauss": { - "price": { - "origin": "0", - "scale": "20" + "query": { + "function_score": { + "functions": [ + { + "gauss": { + "price": { + "origin": "0", + "scale": "20" + } + } + }, + { + "gauss": { + "location": { + "origin": "11, 12", + "scale": "2km" + } + } } - } - }, - { - "gauss": { - "location": { - "origin": "11, 12", - "scale": "2km" + ], + "query": { + "match": { + "properties": "balcony" } - } + }, + "score_mode": "multiply" } - ], - "query": { - "match": { - "properties": "balcony" - } - }, - "score_mode": "multiply" } - } } -------------------------------------------------- // CONSOLE diff --git a/docs/reference/query-dsl/geo-distance-query.asciidoc b/docs/reference/query-dsl/geo-distance-query.asciidoc index 228ab804d7a..2abb296c546 100644 --- a/docs/reference/query-dsl/geo-distance-query.asciidoc +++ b/docs/reference/query-dsl/geo-distance-query.asciidoc @@ -8,7 +8,7 @@ distance from a geo point. Assuming the following mapping: -------------------------------------------------- PUT /my_locations { - "mappings": { + "mappings": { "location": { "properties": { "pin": { @@ -51,22 +51,22 @@ filter: -------------------------------------------------- GET /my_locations/location/_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_distance" : { - "distance" : "200km", - "pin.location" : { - "lat" : 40, - "lon" : -70 + "query": { + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : "200km", + "pin.location" : { + "lat" : 40, + "lon" : -70 + } } } } } - } } -------------------------------------------------- // CONSOLE @@ -85,22 +85,22 @@ representation of the geo point, the filter can accept it as well: -------------------------------------------------- GET /my_locations/location/_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_distance" : { - "distance" : "12km", - "pin.location" : { - "lat" : 40, - "lon" : -70 + "query": { + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : "12km", + "pin.location" : { + "lat" : 40, + "lon" : -70 + } } } } } - } } -------------------------------------------------- // CONSOLE @@ -116,19 +116,19 @@ conform with http://geojson.org/[GeoJSON]. -------------------------------------------------- GET /my_locations/location/_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_distance" : { - "distance" : "12km", - "pin.location" : [-70, 40] + "query": { + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : "12km", + "pin.location" : [-70, 40] + } } } } - } } -------------------------------------------------- // CONSOLE @@ -144,19 +144,19 @@ Format in `lat,lon`. -------------------------------------------------- GET /my_locations/location/_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_distance" : { - "distance" : "12km", - "pin.location" : "40,-70" + "query": { + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : "12km", + "pin.location" : "40,-70" + } } } } - } } -------------------------------------------------- // CONSOLE @@ -169,19 +169,19 @@ GET /my_locations/location/_search -------------------------------------------------- GET /my_locations/location/_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_distance" : { - "distance" : "12km", - "pin.location" : "drm3btev3e86" + "query": { + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : "12km", + "pin.location" : "drm3btev3e86" + } } } } - } } -------------------------------------------------- // CONSOLE diff --git a/docs/reference/query-dsl/match-all-query.asciidoc b/docs/reference/query-dsl/match-all-query.asciidoc index d4064d053f6..6e448828676 100644 --- a/docs/reference/query-dsl/match-all-query.asciidoc +++ b/docs/reference/query-dsl/match-all-query.asciidoc @@ -7,24 +7,26 @@ of `1.0`. [source,js] -------------------------------------------------- GET /_search -{ "query": { - "match_all": {} - } +{ + "query": { + "match_all": {} + } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE The `_score` can be changed with the `boost` parameter: [source,js] -------------------------------------------------- GET /_search -{ "query": { - "match_all": { "boost" : 1.2 } - } +{ + "query": { + "match_all": { "boost" : 1.2 } + } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE [[query-dsl-match-none-query]] [float] @@ -35,9 +37,10 @@ This is the inverse of the `match_all` query, which matches no documents. [source,js] -------------------------------------------------- GET /_search -{ "query": { - "match_none": {} - } +{ + "query": { + "match_none": {} + } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE diff --git a/docs/reference/query-dsl/mlt-query.asciidoc b/docs/reference/query-dsl/mlt-query.asciidoc index 795bf51584d..b132b49f234 100644 --- a/docs/reference/query-dsl/mlt-query.asciidoc +++ b/docs/reference/query-dsl/mlt-query.asciidoc @@ -17,17 +17,17 @@ fields, limiting the number of selected terms to 12. -------------------------------------------------- GET /_search { - "query": { - "more_like_this" : { - "fields" : ["title", "description"], - "like" : "Once upon a time", - "min_term_freq" : 1, - "max_query_terms" : 12 + "query": { + "more_like_this" : { + "fields" : ["title", "description"], + "like" : "Once upon a time", + "min_term_freq" : 1, + "max_query_terms" : 12 + } } - } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE A more complicated use case consists of mixing texts with documents already existing in the index. In this case, the syntax to specify a document is @@ -37,29 +37,29 @@ similar to the one used in the <>. -------------------------------------------------- GET /_search { - "query": { - "more_like_this" : { - "fields" : ["title", "description"], - "like" : [ - { - "_index" : "imdb", - "_type" : "movies", - "_id" : "1" - }, - { - "_index" : "imdb", - "_type" : "movies", - "_id" : "2" - }, - "and potentially some more text here as well" - ], - "min_term_freq" : 1, - "max_query_terms" : 12 + "query": { + "more_like_this" : { + "fields" : ["title", "description"], + "like" : [ + { + "_index" : "imdb", + "_type" : "movies", + "_id" : "1" + }, + { + "_index" : "imdb", + "_type" : "movies", + "_id" : "2" + }, + "and potentially some more text here as well" + ], + "min_term_freq" : 1, + "max_query_terms" : 12 + } } - } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE Finally, users can mix some texts, a chosen set of documents but also provide documents not necessarily present in the index. To provide documents not @@ -69,34 +69,34 @@ present in the index, the syntax is similar to < The query string. <2> The fields to be queried. @@ -37,7 +37,7 @@ GET /_search } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE <1> Query the `title`, `first_name` and `last_name` fields. Individual fields can be boosted with the caret (`^`) notation: @@ -54,7 +54,7 @@ GET /_search } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE <1> The `subject` field is three times as important as the `message` field. @@ -98,16 +98,16 @@ find the single best matching field. For instance, this query: GET /_search { "query": { - "multi_match" : { - "query": "brown fox", - "type": "best_fields", - "fields": [ "subject", "message" ], - "tie_breaker": 0.3 - } + "multi_match" : { + "query": "brown fox", + "type": "best_fields", + "fields": [ "subject", "message" ], + "tie_breaker": 0.3 + } } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE would be executed as: @@ -126,7 +126,7 @@ GET /_search } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE Normally the `best_fields` type uses the score of the *single* best matching field, but if `tie_breaker` is specified, then it calculates the score as @@ -165,7 +165,7 @@ GET /_search } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE <1> All terms must be present. @@ -207,7 +207,7 @@ GET /_search } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE would be executed as: @@ -226,7 +226,7 @@ GET /_search } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE The score from each `match` clause is added together, then divided by the number of `match` clauses. @@ -249,15 +249,15 @@ This query: GET /_search { "query": { - "multi_match" : { - "query": "quick brown f", - "type": "phrase_prefix", - "fields": [ "subject", "message" ] - } + "multi_match" : { + "query": "quick brown f", + "type": "phrase_prefix", + "fields": [ "subject", "message" ] + } } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE would be executed as: @@ -266,16 +266,16 @@ would be executed as: GET /_search { "query": { - "dis_max": { - "queries": [ - { "match_phrase_prefix": { "subject": "quick brown f" }}, - { "match_phrase_prefix": { "message": "quick brown f" }} - ] - } + "dis_max": { + "queries": [ + { "match_phrase_prefix": { "subject": "quick brown f" }}, + { "match_phrase_prefix": { "message": "quick brown f" }} + ] + } } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE Also, accepts `analyzer`, `boost`, `slop` and `zero_terms_query` as explained in <>. Type `phrase_prefix` additionally accepts @@ -326,16 +326,16 @@ A query like: GET /_search { "query": { - "multi_match" : { - "query": "Will Smith", - "type": "cross_fields", - "fields": [ "first_name", "last_name" ], - "operator": "and" - } + "multi_match" : { + "query": "Will Smith", + "type": "cross_fields", + "fields": [ "first_name", "last_name" ], + "operator": "and" + } } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE is executed as: @@ -386,18 +386,18 @@ both use an `edge_ngram` analyzer, this query: GET /_search { "query": { - "multi_match" : { - "query": "Jon", - "type": "cross_fields", - "fields": [ + "multi_match" : { + "query": "Jon", + "type": "cross_fields", + "fields": [ "first", "first.edge", "last", "last.edge" - ] - } + ] + } } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE would be executed as: @@ -426,28 +426,28 @@ GET /_search { "query": { "bool": { - "should": [ - { - "multi_match" : { - "query": "Will Smith", - "type": "cross_fields", - "fields": [ "first", "last" ], - "minimum_should_match": "50%" <1> - } - }, - { - "multi_match" : { - "query": "Will Smith", - "type": "cross_fields", - "fields": [ "*.edge" ] - } - } - ] + "should": [ + { + "multi_match" : { + "query": "Will Smith", + "type": "cross_fields", + "fields": [ "first", "last" ], + "minimum_should_match": "50%" <1> + } + }, + { + "multi_match" : { + "query": "Will Smith", + "type": "cross_fields", + "fields": [ "*.edge" ] + } + } + ] } } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE <1> Either `will` or `smith` must be present in either of the `first` or `last` fields @@ -460,16 +460,16 @@ parameter in the query. GET /_search { "query": { - "multi_match" : { - "query": "Jon", - "type": "cross_fields", - "analyzer": "standard", <1> - "fields": [ "first", "last", "*.edge" ] - } + "multi_match" : { + "query": "Jon", + "type": "cross_fields", + "analyzer": "standard", <1> + "fields": [ "first", "last", "*.edge" ] + } } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE <1> Use the `standard` analyzer for all fields. diff --git a/docs/reference/query-dsl/prefix-query.asciidoc b/docs/reference/query-dsl/prefix-query.asciidoc index 543cccfeef5..d2b75d10e5f 100644 --- a/docs/reference/query-dsl/prefix-query.asciidoc +++ b/docs/reference/query-dsl/prefix-query.asciidoc @@ -14,7 +14,7 @@ GET /_search } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE A boost can also be associated with the query: @@ -26,7 +26,7 @@ GET /_search } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE Or : @@ -38,7 +38,7 @@ GET /_search } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE This multi term query allows you to control how it gets rewritten using the <> diff --git a/docs/reference/query-dsl/query_filter_context.asciidoc b/docs/reference/query-dsl/query_filter_context.asciidoc index 7ef0d7b0f4f..79f8c4bd960 100644 --- a/docs/reference/query-dsl/query_filter_context.asciidoc +++ b/docs/reference/query-dsl/query_filter_context.asciidoc @@ -63,7 +63,7 @@ GET /_search } } ------------------------------------ -// AUTOSENSE +// CONSOLE <1> The `query` parameter indicates query context. <2> The `bool` and two `match` clauses are used in query context, which means that they are used to score how well each document diff --git a/docs/reference/query-dsl/range-query.asciidoc b/docs/reference/query-dsl/range-query.asciidoc index 939c300f1a0..67d76953f03 100644 --- a/docs/reference/query-dsl/range-query.asciidoc +++ b/docs/reference/query-dsl/range-query.asciidoc @@ -22,7 +22,7 @@ GET _search } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE The `range` query accepts the following parameters: @@ -54,7 +54,7 @@ GET _search } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE ===== Date math and rounding @@ -106,6 +106,7 @@ GET _search } } -------------------------------------------------- +// CONSOLE ===== Time zone in range queries @@ -117,8 +118,7 @@ accepts it), or it can be specified as the `time_zone` parameter: -------------------------------------------------- GET _search { - "query": - { + "query": { "range" : { "timestamp" : { "gte": "2015-01-01 00:00:00", <1> @@ -129,6 +129,6 @@ GET _search } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE <1> This date will be converted to `2014-12-31T23:00:00 UTC`. <2> `now` is not affected by the `time_zone` parameter (dates must be stored as UTC). diff --git a/docs/reference/query-dsl/simple-query-string-query.asciidoc b/docs/reference/query-dsl/simple-query-string-query.asciidoc index 72093a53f6e..796f2517fea 100644 --- a/docs/reference/query-dsl/simple-query-string-query.asciidoc +++ b/docs/reference/query-dsl/simple-query-string-query.asciidoc @@ -100,12 +100,12 @@ introduced fields included). For example: -------------------------------------------------- GET /_search { - "query": { - "simple_query_string" : { - "fields" : ["content", "name.*^5"], - "query" : "foo bar baz" + "query": { + "simple_query_string" : { + "fields" : ["content", "name.*^5"], + "query" : "foo bar baz" + } } - } } -------------------------------------------------- // CONSOLE @@ -120,12 +120,12 @@ should be enabled. It is specified as a `|`-delimited string with the -------------------------------------------------- GET /_search { - "query": { - "simple_query_string" : { - "query" : "foo | bar + baz*", - "flags" : "OR|AND|PREFIX" + "query": { + "simple_query_string" : { + "query" : "foo | bar + baz*", + "flags" : "OR|AND|PREFIX" + } } - } } -------------------------------------------------- // CONSOLE diff --git a/docs/reference/query-dsl/span-first-query.asciidoc b/docs/reference/query-dsl/span-first-query.asciidoc index 36a6a2edd9f..dba7932661d 100644 --- a/docs/reference/query-dsl/span-first-query.asciidoc +++ b/docs/reference/query-dsl/span-first-query.asciidoc @@ -8,17 +8,17 @@ to Lucene `SpanFirstQuery`. Here is an example: -------------------------------------------------- GET /_search { - "query": { - "span_first" : { - "match" : { - "span_term" : { "user" : "kimchy" } - }, - "end" : 3 + "query": { + "span_first" : { + "match" : { + "span_term" : { "user" : "kimchy" } + }, + "end" : 3 + } } - } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE The `match` clause can be any other span type query. The `end` controls the maximum end position permitted in a match. diff --git a/docs/reference/query-dsl/span-or-query.asciidoc b/docs/reference/query-dsl/span-or-query.asciidoc index 487dcffb6b4..470935d6f5c 100644 --- a/docs/reference/query-dsl/span-or-query.asciidoc +++ b/docs/reference/query-dsl/span-or-query.asciidoc @@ -8,15 +8,15 @@ Matches the union of its span clauses. The span or query maps to Lucene -------------------------------------------------- GET /_search { - "query": { - "span_or" : { - "clauses" : [ - { "span_term" : { "field" : "value1" } }, - { "span_term" : { "field" : "value2" } }, - { "span_term" : { "field" : "value3" } } - ] + "query": { + "span_or" : { + "clauses" : [ + { "span_term" : { "field" : "value1" } }, + { "span_term" : { "field" : "value2" } }, + { "span_term" : { "field" : "value3" } } + ] + } } - } } -------------------------------------------------- // CONSOLE diff --git a/docs/reference/query-dsl/template-query.asciidoc b/docs/reference/query-dsl/template-query.asciidoc index ed2432a3479..f66dbe56d3e 100644 --- a/docs/reference/query-dsl/template-query.asciidoc +++ b/docs/reference/query-dsl/template-query.asciidoc @@ -20,7 +20,7 @@ GET /_search } } ------------------------------------------ -// AUTOSENSE +// CONSOLE The above request is translated into: @@ -35,7 +35,7 @@ GET /_search } } ------------------------------------------ -// AUTOSENSE +// CONSOLE Alternatively passing the template as an escaped string works as well: @@ -53,7 +53,7 @@ GET /_search } } ------------------------------------------ -// AUTOSENSE +// CONSOLE <1> New line characters (`\n`) should be escaped as `\\n` or removed, and quotes (`"`) should be escaped as `\\"`. @@ -79,7 +79,7 @@ GET /_search } } ------------------------------------------ -// AUTOSENSE +// CONSOLE <1> Name of the query template in `config/scripts/`, i.e., `my_template.mustache`. @@ -92,7 +92,7 @@ PUT /_search/template/my_template "template": { "match": { "text": "{{query_string}}" }} } ------------------------------------------ -// AUTOSENSE +// CONSOLE and refer to it in the `template` query with the `id` parameter: @@ -111,7 +111,7 @@ GET /_search } } ------------------------------------------ -// AUTOSENSE +// CONSOLE // TEST[continued] <1> Name of the query template in `config/scripts/`, i.e., `my_template.mustache`. diff --git a/docs/reference/query-dsl/type-query.asciidoc b/docs/reference/query-dsl/type-query.asciidoc index 94aaa2d2b65..05e909bc366 100644 --- a/docs/reference/query-dsl/type-query.asciidoc +++ b/docs/reference/query-dsl/type-query.asciidoc @@ -7,11 +7,11 @@ Filters documents matching the provided document / mapping type. -------------------------------------------------- GET /_search { - "query": { - "type" : { - "value" : "my_type" + "query": { + "type" : { + "value" : "my_type" + } } - } } -------------------------------------------------- -// AUTOSENSE +// CONSOLE