diff --git a/docs/reference/query-dsl/bool-query.asciidoc b/docs/reference/query-dsl/bool-query.asciidoc index 2a289910c43..8fcd66129cd 100644 --- a/docs/reference/query-dsl/bool-query.asciidoc +++ b/docs/reference/query-dsl/bool-query.asciidoc @@ -81,7 +81,7 @@ all documents where the `status` field contains the term `active`. This first query assigns a score of `0` to all documents, as no scoring query has been specified: -[source,js] +[source,json] --------------------------------- GET _search { @@ -101,7 +101,7 @@ GET _search This `bool` query has a `match_all` query, which assigns a score of `1.0` to all documents. -[source,js] +[source,json] --------------------------------- GET _search { @@ -125,7 +125,7 @@ This `constant_score` query behaves in exactly the same way as the second exampl The `constant_score` query assigns a score of `1.0` to all documents matched by the filter. -[source,js] +[source,json] --------------------------------- GET _search { diff --git a/docs/reference/query-dsl/boosting-query.asciidoc b/docs/reference/query-dsl/boosting-query.asciidoc index 5bb07392ab7..969b3bbedfe 100644 --- a/docs/reference/query-dsl/boosting-query.asciidoc +++ b/docs/reference/query-dsl/boosting-query.asciidoc @@ -8,23 +8,19 @@ overall score. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "boosting" : { - "positive" : { - "term" : { - "field1" : "value1" - } - }, - "negative" : { - "term" : { - "field2" : "value2" - } - }, - "negative_boost" : 0.2 - } + "boosting" : { + "positive" : { + "term" : { + "field1" : "value1" + } + }, + "negative" : { + "term" : { + "field2" : "value2" + } + }, + "negative_boost" : 0.2 } } -------------------------------------------------- -// CONSOLE diff --git a/docs/reference/query-dsl/common-terms-query.asciidoc b/docs/reference/query-dsl/common-terms-query.asciidoc index fcc4ace2ec6..a956c33c1ee 100644 --- a/docs/reference/query-dsl/common-terms-query.asciidoc +++ b/docs/reference/query-dsl/common-terms-query.asciidoc @@ -70,19 +70,15 @@ In this example, words that have a document frequency greater than 0.1% [source,js] -------------------------------------------------- -GET /_search { - "query": { - "common": { - "body": { - "query": "this is bonsai cool", - "cutoff_frequency": 0.001 - } - } + "common": { + "body": { + "query": "this is bonsai cool", + "cutoff_frequency": 0.001 } + } } -------------------------------------------------- -// CONSOLE The number of terms which should match can be controlled with the <> @@ -94,44 +90,36 @@ all terms required: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "common": { - "body": { - "query": "nelly the elephant as a cartoon", - "cutoff_frequency": 0.001, - "low_freq_operator": "and" - } - } + "common": { + "body": { + "query": "nelly the elephant as a cartoon", + "cutoff_frequency": 0.001, + "low_freq_operator": "and" } + } } -------------------------------------------------- -// CONSOLE which is roughly equivalent to: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool": { - "must": [ - { "term": { "body": "nelly"}}, - { "term": { "body": "elephant"}}, - { "term": { "body": "cartoon"}} - ], - "should": [ - { "term": { "body": "the"}}, - { "term": { "body": "as"}}, - { "term": { "body": "a"}} - ] - } - } + "bool": { + "must": [ + { "term": { "body": "nelly"}}, + { "term": { "body": "elephant"}}, + { "term": { "body": "cartoon"}} + ], + "should": [ + { "term": { "body": "the"}} + { "term": { "body": "as"}} + { "term": { "body": "a"}} + ] + } } -------------------------------------------------- -// CONSOLE Alternatively use <> @@ -140,49 +128,41 @@ must be present, for instance: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "common": { - "body": { - "query": "nelly the elephant as a cartoon", - "cutoff_frequency": 0.001, - "minimum_should_match": 2 - } - } + "common": { + "body": { + "query": "nelly the elephant as a cartoon", + "cutoff_frequency": 0.001, + "minimum_should_match": 2 } + } } -------------------------------------------------- -// CONSOLE which is roughly equivalent to: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool": { - "must": { - "bool": { - "should": [ - { "term": { "body": "nelly"}}, - { "term": { "body": "elephant"}}, - { "term": { "body": "cartoon"}} - ], - "minimum_should_match": 2 - } - }, - "should": [ - { "term": { "body": "the"}}, - { "term": { "body": "as"}}, - { "term": { "body": "a"}} - ] - } - } + "bool": { + "must": { + "bool": { + "should": [ + { "term": { "body": "nelly"}}, + { "term": { "body": "elephant"}}, + { "term": { "body": "cartoon"}} + ], + "minimum_should_match": 2 + } + }, + "should": [ + { "term": { "body": "the"}} + { "term": { "body": "as"}} + { "term": { "body": "a"}} + ] + } } -------------------------------------------------- -// CONSOLE minimum_should_match @@ -194,58 +174,50 @@ additional parameters (note the change in structure): [source,js] -------------------------------------------------- -GET /_search { - "query": { - "common": { - "body": { - "query": "nelly the elephant not as a cartoon", - "cutoff_frequency": 0.001, - "minimum_should_match": { - "low_freq" : 2, - "high_freq" : 3 - } - } - } + "common": { + "body": { + "query": "nelly the elephant not as a cartoon", + "cutoff_frequency": 0.001, + "minimum_should_match": { + "low_freq" : 2, + "high_freq" : 3 + } } + } } -------------------------------------------------- -// CONSOLE which is roughly equivalent to: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool": { - "must": { - "bool": { - "should": [ - { "term": { "body": "nelly"}}, - { "term": { "body": "elephant"}}, - { "term": { "body": "cartoon"}} - ], - "minimum_should_match": 2 - } - }, - "should": { - "bool": { - "should": [ - { "term": { "body": "the"}}, - { "term": { "body": "not"}}, - { "term": { "body": "as"}}, - { "term": { "body": "a"}} - ], - "minimum_should_match": 3 - } - } - } + "bool": { + "must": { + "bool": { + "should": [ + { "term": { "body": "nelly"}}, + { "term": { "body": "elephant"}}, + { "term": { "body": "cartoon"}} + ], + "minimum_should_match": 2 + } + }, + "should": { + "bool": { + "should": [ + { "term": { "body": "the"}}, + { "term": { "body": "not"}}, + { "term": { "body": "as"}}, + { "term": { "body": "a"}} + ], + "minimum_should_match": 3 + } } + } } -------------------------------------------------- -// CONSOLE In this case it means the high frequency terms have only an impact on relevance when there are at least three of them. But the most @@ -255,44 +227,36 @@ for high frequency terms is when there are only high frequency terms: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "common": { - "body": { - "query": "how not to be", - "cutoff_frequency": 0.001, - "minimum_should_match": { - "low_freq" : 2, - "high_freq" : 3 - } - } - } + "common": { + "body": { + "query": "how not to be", + "cutoff_frequency": 0.001, + "minimum_should_match": { + "low_freq" : 2, + "high_freq" : 3 + } } + } } -------------------------------------------------- -// CONSOLE which is roughly equivalent to: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool": { - "should": [ - { "term": { "body": "how"}}, - { "term": { "body": "not"}}, - { "term": { "body": "to"}}, - { "term": { "body": "be"}} - ], - "minimum_should_match": "3<50%" - } - } + "bool": { + "should": [ + { "term": { "body": "how"}}, + { "term": { "body": "not"}}, + { "term": { "body": "to"}}, + { "term": { "body": "be"}} + ], + "minimum_should_match": "3<50%" + } } -------------------------------------------------- -// CONSOLE The high frequency generated query is then slightly less restrictive than with an `AND`. diff --git a/docs/reference/query-dsl/constant-score-query.asciidoc b/docs/reference/query-dsl/constant-score-query.asciidoc index bced9fc9fbe..8e76ac13ff5 100644 --- a/docs/reference/query-dsl/constant-score-query.asciidoc +++ b/docs/reference/query-dsl/constant-score-query.asciidoc @@ -7,16 +7,12 @@ filter. Maps to Lucene `ConstantScoreQuery`. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "constant_score" : { - "filter" : { - "term" : { "user" : "kimchy"} - }, - "boost" : 1.2 - } + "constant_score" : { + "filter" : { + "term" : { "user" : "kimchy"} + }, + "boost" : 1.2 } } -------------------------------------------------- -// CONSOLE diff --git a/docs/reference/query-dsl/dis-max-query.asciidoc b/docs/reference/query-dsl/dis-max-query.asciidoc index 2f82f2294b3..2938c8db8ea 100644 --- a/docs/reference/query-dsl/dis-max-query.asciidoc +++ b/docs/reference/query-dsl/dis-max-query.asciidoc @@ -27,22 +27,18 @@ This query maps to Lucene `DisjunctionMaxQuery`. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "dis_max" : { - "tie_breaker" : 0.7, - "boost" : 1.2, - "queries" : [ - { - "term" : { "age" : 34 } - }, - { - "term" : { "age" : 35 } - } - ] - } + "dis_max" : { + "tie_breaker" : 0.7, + "boost" : 1.2, + "queries" : [ + { + "term" : { "age" : 34 } + }, + { + "term" : { "age" : 35 } + } + ] } } -------------------------------------------------- -// CONSOLE diff --git a/docs/reference/query-dsl/exists-query.asciidoc b/docs/reference/query-dsl/exists-query.asciidoc index 4971219366f..b484d47f4b6 100644 --- a/docs/reference/query-dsl/exists-query.asciidoc +++ b/docs/reference/query-dsl/exists-query.asciidoc @@ -5,14 +5,10 @@ Returns documents that have at least one non-`null` value in the original field: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "exists" : { "field" : "user" } - } + "exists" : { "field" : "user" } } -------------------------------------------------- -// CONSOLE For instance, these documents would all match the above query: @@ -81,20 +77,14 @@ clause as follows: [source,js] -------------------------------------------------- -GET /_search -{ - "query": { - "bool": { - "must_not": { - "exists": { - "field": "user" - } - } +"bool": { + "must_not": { + "exists": { + "field": "user" } } } -------------------------------------------------- -// CONSOLE This query returns documents that have no value in the user field. diff --git a/docs/reference/query-dsl/function-score-query.asciidoc b/docs/reference/query-dsl/function-score-query.asciidoc index e7e4b8f5877..5f92d8c172c 100644 --- a/docs/reference/query-dsl/function-score-query.asciidoc +++ b/docs/reference/query-dsl/function-score-query.asciidoc @@ -14,20 +14,13 @@ by the query. [source,js] -------------------------------------------------- -GET /_search -{ - "query": { - "function_score": { - "query": {}, - "boost": "5", - "random_score": {}, <1> - "boost_mode":"multiply" - } - } +"function_score": { + "query": {}, + "boost": "boost for the whole query", + "FUNCTION": {}, <1> + "boost_mode":"(multiply|replace|...)" } -------------------------------------------------- -// CONSOLE - <1> See <> for a list of supported functions. Furthermore, several functions can be combined. In this case one can @@ -36,35 +29,30 @@ given filtering query [source,js] -------------------------------------------------- -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 +"function_score": { + "query": {}, + "boost": "boost for the whole query", + "functions": [ + { + "filter": {}, + "FUNCTION": {}, <1> + "weight": number + }, + { + "FUNCTION": {} <1> + }, + { + "filter": {}, + "weight": number } - } + ], + "max_boost": number, + "score_mode": "(multiply|max|...)", + "boost_mode": "(multiply|replace|...)", + "min_score" : number } -------------------------------------------------- -// CONSOLE - -<1> Boost for the whole query. -<2> See <> for a list of supported functions. +<1> See <> for a list of supported functions. NOTE: The scores produced by the filtering query of each function do not matter. @@ -471,36 +459,36 @@ the request would look like this: [source,js] -------------------------------------------------- -GET /_search +GET _search { - "query": { - "function_score": { - "functions": [ - { - "gauss": { - "price": { - "origin": "0", - "scale": "20" - } - } - }, - { - "gauss": { - "location": { - "origin": "11, 12", - "scale": "2km" - } - } + "query": { + "function_score": { + "functions": [ + { + "gauss": { + "price": { + "origin": "0", + "scale": "20" } - ], - "query": { - "match": { - "properties": "balcony" + } + }, + { + "gauss": { + "location": { + "origin": "11, 12", + "scale": "2km" } - }, - "score_mode": "multiply" + } } + ], + "query": { + "match": { + "properties": "balcony" + } + }, + "score_mode": "multiply" } + } } -------------------------------------------------- // CONSOLE diff --git a/docs/reference/query-dsl/fuzzy-query.asciidoc b/docs/reference/query-dsl/fuzzy-query.asciidoc index f320e81b579..48c9c45c0ff 100644 --- a/docs/reference/query-dsl/fuzzy-query.asciidoc +++ b/docs/reference/query-dsl/fuzzy-query.asciidoc @@ -16,35 +16,27 @@ Here is a simple example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "fuzzy" : { "user" : "ki" } - } + "fuzzy" : { "user" : "ki" } } -------------------------------------------------- -// CONSOLE Or with more advanced settings: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "fuzzy" : { - "user" : { - "value" : "ki", - "boost" : 1.0, - "fuzziness" : 2, - "prefix_length" : 0, - "max_expansions": 100 - } + "fuzzy" : { + "user" : { + "value" : "ki", + "boost" : 1.0, + "fuzziness" : 2, + "prefix_length" : 0, + "max_expansions": 100 } } } -------------------------------------------------- -// CONSOLE [float] ===== Parameters @@ -70,4 +62,3 @@ WARNING: This query can be very heavy if `prefix_length` is set to `0` and if `max_expansions` is set to a high number. It could result in every term in the index being examined! - diff --git a/docs/reference/query-dsl/geo-bounding-box-query.asciidoc b/docs/reference/query-dsl/geo-bounding-box-query.asciidoc index 40debb57105..00120a98fc9 100644 --- a/docs/reference/query-dsl/geo-bounding-box-query.asciidoc +++ b/docs/reference/query-dsl/geo-bounding-box-query.asciidoc @@ -6,24 +6,6 @@ bounding box. Assuming the following indexed document: [source,js] -------------------------------------------------- -PUT /my_locations -{ - "mappings": { - "location": { - "properties": { - "pin": { - "properties": { - "location": { - "type": "geo_point" - } - } - } - } - } - } -} - -PUT /my_locations/location/1 { "pin" : { "location" : { @@ -33,32 +15,27 @@ PUT /my_locations/location/1 } } -------------------------------------------------- -// CONSOLE -// TESTSETUP Then the following simple query can be executed with a `geo_bounding_box` filter: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_bounding_box" : { - "pin.location" : { - "top_left" : { - "lat" : 40.73, - "lon" : -74.1 - }, - "bottom_right" : { - "lat" : 40.01, - "lon" : -71.12 - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_bounding_box" : { + "pin.location" : { + "top_left" : { + "lat" : 40.73, + "lon" : -74.1 + }, + "bottom_right" : { + "lat" : 40.01, + "lon" : -71.12 } } } @@ -66,7 +43,6 @@ GET /_search } } -------------------------------------------------- -// CONSOLE [float] ==== Query Options @@ -99,24 +75,21 @@ representation of the geo point, the filter can accept it as well: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_bounding_box" : { - "pin.location" : { - "top_left" : { - "lat" : 40.73, - "lon" : -74.1 - }, - "bottom_right" : { - "lat" : 40.01, - "lon" : -71.12 - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_bounding_box" : { + "pin.location" : { + "top_left" : { + "lat" : 40.73, + "lon" : -74.1 + }, + "bottom_right" : { + "lat" : 40.01, + "lon" : -71.12 } } } @@ -124,7 +97,6 @@ GET /_search } } -------------------------------------------------- -// CONSOLE [float] ===== Lat Lon As Array @@ -134,26 +106,22 @@ conform with http://geojson.org/[GeoJSON]. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_bounding_box" : { - "pin.location" : { - "top_left" : [-74.1, 40.73], - "bottom_right" : [-71.12, 40.01] - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_bounding_box" : { + "pin.location" : { + "top_left" : [-74.1, 40.73], + "bottom_right" : [-71.12, 40.01] } } } } } -------------------------------------------------- -// CONSOLE [float] ===== Lat Lon As String @@ -162,52 +130,44 @@ Format in `lat,lon`. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_bounding_box" : { - "pin.location" : { - "top_left" : "40.73, -74.1", - "bottom_right" : "40.01, -71.12" - } - } - } - } -} -} --------------------------------------------------- -// CONSOLE - -[float] -===== Geohash - -[source,js] --------------------------------------------------- -GET /_search -{ - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_bounding_box" : { - "pin.location" : { - "top_left" : "dr5r9ydj2y73", - "bottom_right" : "drj7teegpus6" - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_bounding_box" : { + "pin.location" : { + "top_left" : "40.73, -74.1", + "bottom_right" : "40.01, -71.12" + } + } + } + } +} +-------------------------------------------------- + +[float] +===== Geohash + +[source,js] +-------------------------------------------------- +{ + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_bounding_box" : { + "pin.location" : { + "top_left" : "dr5r9ydj2y73", + "bottom_right" : "drj7teegpus6" } } } } } -------------------------------------------------- -// CONSOLE [float] ==== Vertices @@ -221,28 +181,24 @@ values separately. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_bounding_box" : { - "pin.location" : { - "top" : 40.73, - "left" : -74.1, - "bottom" : 40.01, - "right" : -71.12 - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_bounding_box" : { + "pin.location" : { + "top" : 40.73, + "left" : -74.1, + "bottom" : 40.01, + "right" : -71.12 } } } } } -------------------------------------------------- -// CONSOLE [float] @@ -271,33 +227,29 @@ are not supported. Here is an example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_bounding_box" : { - "pin.location" : { - "top_left" : { - "lat" : 40.73, - "lon" : -74.1 - }, - "bottom_right" : { - "lat" : 40.10, - "lon" : -71.12 - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_bounding_box" : { + "pin.location" : { + "top_left" : { + "lat" : 40.73, + "lon" : -74.1 }, - "type" : "indexed" - } + "bottom_right" : { + "lat" : 40.10, + "lon" : -71.12 + } + }, + "type" : "indexed" } } } } -------------------------------------------------- -// CONSOLE [float] ==== Ignore Unmapped diff --git a/docs/reference/query-dsl/geo-distance-query.asciidoc b/docs/reference/query-dsl/geo-distance-query.asciidoc index 5e2f0ce43c7..c29391e5b57 100644 --- a/docs/reference/query-dsl/geo-distance-query.asciidoc +++ b/docs/reference/query-dsl/geo-distance-query.asciidoc @@ -2,29 +2,10 @@ === Geo Distance Query Filters documents that include only hits that exists within a specific -distance from a geo point. Assuming the following mapping and indexed -document: +distance from a geo point. Assuming the following indexed json: [source,js] -------------------------------------------------- -PUT /my_locations -{ - "mappings": { - "location": { - "properties": { - "pin": { - "properties": { - "location": { - "type": "geo_point" - } - } - } - } - } - } -} - -PUT /my_locations/location/1 { "pin" : { "location" : { @@ -34,36 +15,29 @@ PUT /my_locations/location/1 } } -------------------------------------------------- -// CONSOLE -// TESTSETUP - Then the following simple query can be executed with a `geo_distance` filter: [source,js] -------------------------------------------------- -GET /my_locations/location/_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_distance" : { - "distance" : "200km", - "pin.location" : { - "lat" : 40, - "lon" : -70 - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : "200km", + "pin.location" : { + "lat" : 40, + "lon" : -70 } } } } } -------------------------------------------------- -// CONSOLE [float] ==== Accepted Formats @@ -76,27 +50,23 @@ representation of the geo point, the filter can accept it as well: [source,js] -------------------------------------------------- -GET /my_locations/location/_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_distance" : { - "distance" : "12km", - "pin.location" : { - "lat" : 40, - "lon" : -70 - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : "12km", + "pin.location" : { + "lat" : 40, + "lon" : -70 } } } } } -------------------------------------------------- -// CONSOLE [float] ===== Lat Lon As Array @@ -106,25 +76,20 @@ conform with http://geojson.org/[GeoJSON]. [source,js] -------------------------------------------------- -GET /my_locations/location/_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_distance" : { - "distance" : "12km", - "pin.location" : [-70, 40] - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : "12km", + "pin.location" : [-70, 40] } } } } -------------------------------------------------- -// CONSOLE - [float] ===== Lat Lon As String @@ -133,48 +98,40 @@ Format in `lat,lon`. [source,js] -------------------------------------------------- -GET /my_locations/location/_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_distance" : { - "distance" : "12km", - "pin.location" : "40,-70" - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : "12km", + "pin.location" : "40,-70" } } } } -------------------------------------------------- -// CONSOLE [float] ===== Geohash [source,js] -------------------------------------------------- -GET /my_locations/location/_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_distance" : { - "distance" : "12km", - "pin.location" : "drm3btev3e86" - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : "12km", + "pin.location" : "drm3btev3e86" } } } } -------------------------------------------------- -// CONSOLE [float] ==== Options diff --git a/docs/reference/query-dsl/geo-distance-range-query.asciidoc b/docs/reference/query-dsl/geo-distance-range-query.asciidoc index c54c50638bc..abf557d68c7 100644 --- a/docs/reference/query-dsl/geo-distance-range-query.asciidoc +++ b/docs/reference/query-dsl/geo-distance-range-query.asciidoc @@ -5,28 +5,24 @@ Filters documents that exists within a range from a specific point: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_distance_range" : { - "from" : "200km", - "to" : "400km", - "pin.location" : { - "lat" : 40, - "lon" : -70 - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_distance_range" : { + "from" : "200km", + "to" : "400km", + "pin.location" : { + "lat" : 40, + "lon" : -70 } } } } } -------------------------------------------------- -// CONSOLE Supports the same point location parameter and query options as the <> diff --git a/docs/reference/query-dsl/geo-polygon-query.asciidoc b/docs/reference/query-dsl/geo-polygon-query.asciidoc index 35278fda4a5..5717c5dc924 100644 --- a/docs/reference/query-dsl/geo-polygon-query.asciidoc +++ b/docs/reference/query-dsl/geo-polygon-query.asciidoc @@ -6,29 +6,25 @@ points. Here is an example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_polygon" : { - "person.location" : { - "points" : [ + "bool" : { + "query" : { + "match_all" : {} + }, + "filter" : { + "geo_polygon" : { + "person.location" : { + "points" : [ {"lat" : 40, "lon" : -70}, {"lat" : 30, "lon" : -80}, {"lat" : 20, "lon" : -90} - ] - } + ] } } } } } -------------------------------------------------- -// CONSOLE [float] ==== Query Options @@ -57,29 +53,25 @@ conform with http://geojson.org/[GeoJSON]. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_polygon" : { - "person.location" : { - "points" : [ - [-70, 40], + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_polygon" : { + "person.location" : { + "points" : [ + [-70, 40], [-80, 30], - [-90, 20] - ] - } + [-90, 20] + ] } } } } } -------------------------------------------------- -// CONSOLE [float] ===== Lat Lon as String @@ -88,58 +80,50 @@ Format in `lat,lon`. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_polygon" : { - "person.location" : { - "points" : [ - "40, -70", - "30, -80", - "20, -90" - ] - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_polygon" : { + "person.location" : { + "points" : [ + "40, -70", + "30, -80", + "20, -90" + ] } } } } } -------------------------------------------------- -// CONSOLE [float] ===== Geohash [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geo_polygon" : { - "person.location" : { - "points" : [ - "drn5x1g8cu2y", - "30, -80", - "20, -90" - ] - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geo_polygon" : { + "person.location" : { + "points" : [ + "drn5x1g8cu2y", + "30, -80", + "20, -90" + ] } } } } } -------------------------------------------------- -// CONSOLE [float] ==== geo_point Type diff --git a/docs/reference/query-dsl/geo-shape-query.asciidoc b/docs/reference/query-dsl/geo-shape-query.asciidoc index 12203061336..a892080dda4 100644 --- a/docs/reference/query-dsl/geo-shape-query.asciidoc +++ b/docs/reference/query-dsl/geo-shape-query.asciidoc @@ -26,10 +26,10 @@ Given a document that looks like this: -------------------------------------------------- { "name": "Wind & Wetter, Berlin, Germany", - "location": { - "type": "Point", - "coordinates": [13.400544, 52.530286] - } + "location": { + "type": "Point", + "coordinates": [13.400544, 52.530286] + } } -------------------------------------------------- @@ -38,7 +38,6 @@ The following query will find the point using the Elasticsearch's [source,js] -------------------------------------------------- -GET /_search { "query":{ "bool": { @@ -60,7 +59,6 @@ GET /_search } } -------------------------------------------------- -// CONSOLE ==== Pre-Indexed Shape @@ -83,30 +81,26 @@ shape: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool": { - "must": { - "match_all": {} - }, - "filter": { - "geo_shape": { - "location": { - "indexed_shape": { - "id": "DEU", - "type": "countries", - "index": "shapes", - "path": "location" - } - } + "bool": { + "must": { + "match_all": {} + }, + "filter": { + "geo_shape": { + "location": { + "indexed_shape": { + "id": "DEU", + "type": "countries", + "index": "shapes", + "path": "location" } } + } } } } -------------------------------------------------- -// CONSOLE ==== Spatial Relations diff --git a/docs/reference/query-dsl/geohash-cell-query.asciidoc b/docs/reference/query-dsl/geohash-cell-query.asciidoc index 27e6319bc71..2dd701fd958 100644 --- a/docs/reference/query-dsl/geohash-cell-query.asciidoc +++ b/docs/reference/query-dsl/geohash-cell-query.asciidoc @@ -13,7 +13,6 @@ setting the `geohash_prefix` option: [source,js] -------------------------------------------------- -PUT /my_index { "mappings" : { "location": { @@ -29,8 +28,6 @@ PUT /my_index } } -------------------------------------------------- -// CONSOLE -// TESTSETUP The geohash cell can defined by all formats of `geo_points`. If such a cell is defined by a latitude and longitude pair the size of the cell needs to be @@ -45,28 +42,24 @@ next to the given cell. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool" : { - "must" : { - "match_all" : {} - }, - "filter" : { - "geohash_cell": { - "pin": { - "lat": 13.4080, - "lon": 52.5186 - }, - "precision": 3, - "neighbors": true - } + "bool" : { + "must" : { + "match_all" : {} + }, + "filter" : { + "geohash_cell": { + "pin": { + "lat": 13.4080, + "lon": 52.5186 + }, + "precision": 3, + "neighbors": true } } } } -------------------------------------------------- -// CONSOLE [float] ==== Ignore Unmapped diff --git a/docs/reference/query-dsl/has-child-query.asciidoc b/docs/reference/query-dsl/has-child-query.asciidoc index 3b8352fd4e0..bfadc33c06c 100644 --- a/docs/reference/query-dsl/has-child-query.asciidoc +++ b/docs/reference/query-dsl/has-child-query.asciidoc @@ -7,21 +7,17 @@ an example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "has_child" : { - "type" : "blog_tag", - "query" : { - "term" : { - "tag" : "something" - } - } + "has_child" : { + "type" : "blog_tag", + "query" : { + "term" : { + "tag" : "something" + } } } } -------------------------------------------------- -// CONSOLE [float] ==== Scoring capabilities @@ -36,22 +32,18 @@ inside the `has_child` query: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "has_child" : { - "type" : "blog_tag", - "score_mode" : "min", - "query" : { - "term" : { - "tag" : "something" - } - } + "has_child" : { + "type" : "blog_tag", + "score_mode" : "min", + "query" : { + "term" : { + "tag" : "something" + } } } } -------------------------------------------------- -// CONSOLE [float] ==== Min/Max Children @@ -62,24 +54,20 @@ a match: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "has_child" : { - "type" : "blog_tag", - "score_mode" : "min", - "min_children": 2, <1> - "max_children": 10, <1> - "query" : { - "term" : { - "tag" : "something" - } + "has_child" : { + "type" : "blog_tag", + "score_mode" : "min", + "min_children": 2, <1> + "max_children": 10, <1> + "query" : { + "term" : { + "tag" : "something" } } } } -------------------------------------------------- -// CONSOLE <1> Both `min_children` and `max_children` are optional. The `min_children` and `max_children` parameters can be combined with diff --git a/docs/reference/query-dsl/has-parent-query.asciidoc b/docs/reference/query-dsl/has-parent-query.asciidoc index 202bcaac432..9896be6a0a5 100644 --- a/docs/reference/query-dsl/has-parent-query.asciidoc +++ b/docs/reference/query-dsl/has-parent-query.asciidoc @@ -9,21 +9,17 @@ in the same manner as the `has_child` query. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "has_parent" : { - "parent_type" : "blog", - "query" : { - "term" : { - "tag" : "something" - } - } + "has_parent" : { + "parent_type" : "blog", + "query" : { + "term" : { + "tag" : "something" + } } } } -------------------------------------------------- -// CONSOLE [float] ==== Scoring capabilities @@ -38,22 +34,18 @@ matching parent document. The score mode can be specified with the [source,js] -------------------------------------------------- -GET /_search { - "query": { - "has_parent" : { - "parent_type" : "blog", - "score" : true, - "query" : { - "term" : { - "tag" : "something" - } - } + "has_parent" : { + "parent_type" : "blog", + "score" : true, + "query" : { + "term" : { + "tag" : "something" + } } } } -------------------------------------------------- -// CONSOLE [float] ==== Ignore Unmapped diff --git a/docs/reference/query-dsl/ids-query.asciidoc b/docs/reference/query-dsl/ids-query.asciidoc index 09541ce51d3..7d08243a78f 100644 --- a/docs/reference/query-dsl/ids-query.asciidoc +++ b/docs/reference/query-dsl/ids-query.asciidoc @@ -6,17 +6,13 @@ uses the <> field. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "ids" : { - "type" : "my_type", - "values" : ["1", "4", "100"] - } + "ids" : { + "type" : "my_type", + "values" : ["1", "4", "100"] } } -------------------------------------------------- -// CONSOLE The `type` is optional and can be omitted, and can also accept an array of values. If no type is specified, all types defined in the index mapping are tried. diff --git a/docs/reference/query-dsl/indices-query.asciidoc b/docs/reference/query-dsl/indices-query.asciidoc index 8f2f958086e..e3b604b7a39 100644 --- a/docs/reference/query-dsl/indices-query.asciidoc +++ b/docs/reference/query-dsl/indices-query.asciidoc @@ -9,18 +9,18 @@ on the list, the alternative `no_match_query` is executed. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "indices" : { - "indices" : ["index1", "index2"], - "query" : { "term" : { "tag" : "wow" } }, - "no_match_query" : { "term" : { "tag" : "kow" } } + "indices" : { + "indices" : ["index1", "index2"], + "query" : { + "term" : { "tag" : "wow" } + }, + "no_match_query" : { + "term" : { "tag" : "kow" } } } } -------------------------------------------------- -// CONSOLE You can use the `index` field to provide a single index. diff --git a/docs/reference/query-dsl/match-all-query.asciidoc b/docs/reference/query-dsl/match-all-query.asciidoc index 6e448828676..d46b08f9e55 100644 --- a/docs/reference/query-dsl/match-all-query.asciidoc +++ b/docs/reference/query-dsl/match-all-query.asciidoc @@ -6,27 +6,15 @@ of `1.0`. [source,js] -------------------------------------------------- -GET /_search -{ - "query": { - "match_all": {} - } -} +{ "match_all": {} } -------------------------------------------------- -// CONSOLE The `_score` can be changed with the `boost` parameter: [source,js] -------------------------------------------------- -GET /_search -{ - "query": { - "match_all": { "boost" : 1.2 } - } -} +{ "match_all": { "boost" : 1.2 }} -------------------------------------------------- -// CONSOLE [[query-dsl-match-none-query]] [float] @@ -36,11 +24,5 @@ This is the inverse of the `match_all` query, which matches no documents. [source,js] -------------------------------------------------- -GET /_search -{ - "query": { - "match_none": {} - } -} +{ "match_none": {} } -------------------------------------------------- -// CONSOLE diff --git a/docs/reference/query-dsl/match-phrase-prefix-query.asciidoc b/docs/reference/query-dsl/match-phrase-prefix-query.asciidoc index e7e0f618652..b715bf8bd6d 100644 --- a/docs/reference/query-dsl/match-phrase-prefix-query.asciidoc +++ b/docs/reference/query-dsl/match-phrase-prefix-query.asciidoc @@ -6,16 +6,12 @@ allows for prefix matches on the last term in the text. For example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "match_phrase_prefix" : { - "message" : "quick brown f" - } + "match_phrase_prefix" : { + "message" : "quick brown f" } } -------------------------------------------------- -// CONSOLE It accepts the same parameters as the phrase type. In addition, it also accepts a `max_expansions` parameter (default `50`) that can control to how @@ -25,19 +21,15 @@ example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "match_phrase_prefix" : { - "message" : { - "query" : "quick brown f", - "max_expansions" : 10 - } + "match_phrase_prefix" : { + "message" : { + "query" : "quick brown f", + "max_expansions" : 10 } } } -------------------------------------------------- -// CONSOLE [IMPORTANT] =================================================== @@ -61,4 +53,4 @@ For better solutions for _search-as-you-type_ see the <> and {guide}/_index_time_search_as_you_type.html[Index-Time Search-as-You-Type]. -=================================================== +=================================================== \ No newline at end of file diff --git a/docs/reference/query-dsl/match-phrase-query.asciidoc b/docs/reference/query-dsl/match-phrase-query.asciidoc index 943d0e84d36..105866be12a 100644 --- a/docs/reference/query-dsl/match-phrase-query.asciidoc +++ b/docs/reference/query-dsl/match-phrase-query.asciidoc @@ -6,16 +6,12 @@ out of the analyzed text. For example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "match_phrase" : { - "message" : "this is a test" - } + "match_phrase" : { + "message" : "this is a test" } } -------------------------------------------------- -// CONSOLE A phrase query matches terms up to a configurable `slop` (which defaults to 0) in any order. Transposed terms have a slop of 2. @@ -26,16 +22,12 @@ definition, or the default search analyzer, for example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "match_phrase" : { - "message" : { - "query" : "this is a test", - "analyzer" : "my_analyzer" - } + "match_phrase" : { + "message" : { + "query" : "this is a test", + "analyzer" : "my_analyzer" } } } -------------------------------------------------- -// CONSOLE diff --git a/docs/reference/query-dsl/match-query.asciidoc b/docs/reference/query-dsl/match-query.asciidoc index c0081f1de9a..3dbb60d1ca2 100644 --- a/docs/reference/query-dsl/match-query.asciidoc +++ b/docs/reference/query-dsl/match-query.asciidoc @@ -7,16 +7,12 @@ them, and constructs a query. For example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "match" : { - "message" : "this is a test" - } + "match" : { + "message" : "this is a test" } } -------------------------------------------------- -// CONSOLE Note, `message` is the name of a field, you can substitute the name of any field (including `_all`) instead. @@ -61,19 +57,15 @@ change in structure, `message` is the field name): [source,js] -------------------------------------------------- -GET /_search { - "query": { - "match" : { - "message" : { - "query" : "this is a test", - "operator" : "and" - } + "match" : { + "message" : { + "query" : "this is a test", + "operator" : "and" } } } -------------------------------------------------- -// CONSOLE [[query-dsl-match-query-zero]] ===== Zero terms query @@ -84,20 +76,16 @@ change that the `zero_terms_query` option can be used, which accepts [source,js] -------------------------------------------------- -GET /_search { - "query": { - "match" : { - "message" : { - "query" : "to be or not to be", - "operator" : "and", - "zero_terms_query": "all" - } + "match" : { + "message" : { + "query" : "to be or not to be", + "operator" : "and", + "zero_terms_query": "all" } } } -------------------------------------------------- -// CONSOLE [[query-dsl-match-query-cutoff]] ===== Cutoff frequency @@ -125,19 +113,16 @@ Here is an example showing a query composed of stopwords exclusively: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "match" : { - "message" : { - "query" : "to be or not to be", - "cutoff_frequency" : 0.001 - } + "match" : { + "message" : { + "query" : "to be or not to be", + "cutoff_frequency" : 0.001 } } } -------------------------------------------------- -// CONSOLE + IMPORTANT: The `cutoff_frequency` option operates on a per-shard-level. This means that when trying it out on test indexes with low document numbers you diff --git a/docs/reference/query-dsl/mlt-query.asciidoc b/docs/reference/query-dsl/mlt-query.asciidoc index b132b49f234..dc525c2d311 100644 --- a/docs/reference/query-dsl/mlt-query.asciidoc +++ b/docs/reference/query-dsl/mlt-query.asciidoc @@ -15,19 +15,15 @@ fields, limiting the number of selected terms to 12. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "more_like_this" : { - "fields" : ["title", "description"], - "like" : "Once upon a time", - "min_term_freq" : 1, - "max_query_terms" : 12 - } + "more_like_this" : { + "fields" : ["title", "description"], + "like" : "Once upon a time", + "min_term_freq" : 1, + "max_query_terms" : 12 } } -------------------------------------------------- -// 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 @@ -35,31 +31,27 @@ similar to the one used in the <>. [source,js] -------------------------------------------------- -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 - } + "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 } } -------------------------------------------------- -// 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 @@ -67,36 +59,32 @@ present in the index, the syntax is similar to < - "fields": [ "subject", "message" ] <2> - } + "multi_match" : { + "query": "this is a test", <1> + "fields": [ "subject", "message" ] <2> } } -------------------------------------------------- -// CONSOLE <1> The query string. <2> The fields to be queried. @@ -27,35 +23,26 @@ Fields can be specified with wildcards, eg: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "multi_match" : { - "query": "Will Smith", - "fields": [ "title", "*_name" ] <1> - } + "multi_match" : { + "query": "Will Smith", + "fields": [ "title", "*_name" ] <1> } } -------------------------------------------------- -// CONSOLE <1> Query the `title`, `first_name` and `last_name` fields. Individual fields can be boosted with the caret (`^`) notation: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "multi_match" : { - "query" : "this is a test", - "fields" : [ "subject^3", "message" ] <1> - } + "multi_match" : { + "query" : "this is a test", + "fields" : [ "subject^3", "message" ] <1> } } -------------------------------------------------- -// CONSOLE - <1> The `subject` field is three times as important as the `message` field. [[multi-match-types]] @@ -95,38 +82,30 @@ find the single best matching field. For instance, this query: [source,js] -------------------------------------------------- -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 } } -------------------------------------------------- -// CONSOLE would be executed as: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "dis_max": { - "queries": [ - { "match": { "subject": "brown fox" }}, - { "match": { "message": "brown fox" }} - ], - "tie_breaker": 0.3 - } + "dis_max": { + "queries": [ + { "match": { "subject": "brown fox" }}, + { "match": { "message": "brown fox" }} + ], + "tie_breaker": 0.3 } } -------------------------------------------------- -// 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 @@ -153,20 +132,15 @@ Take this query for example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "multi_match" : { - "query": "Will Smith", - "type": "best_fields", - "fields": [ "first_name", "last_name" ], - "operator": "and" <1> - } + "multi_match" : { + "query": "Will Smith", + "type": "best_fields", + "fields": [ "first_name", "last_name" ], + "operator": "and" <1> } } -------------------------------------------------- -// CONSOLE - <1> All terms must be present. This query is executed as: @@ -196,37 +170,29 @@ This query: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "multi_match" : { - "query": "quick brown fox", - "type": "most_fields", - "fields": [ "title", "title.original", "title.shingles" ] - } + "multi_match" : { + "query": "quick brown fox", + "type": "most_fields", + "fields": [ "title", "title.original", "title.shingles" ] } } -------------------------------------------------- -// CONSOLE would be executed as: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "bool": { - "should": [ - { "match": { "title": "quick brown fox" }}, - { "match": { "title.original": "quick brown fox" }}, - { "match": { "title.shingles": "quick brown fox" }} - ] - } + "bool": { + "should": [ + { "match": { "title": "quick brown fox" }}, + { "match": { "title.original": "quick brown fox" }}, + { "match": { "title.shingles": "quick brown fox" }} + ] } } -------------------------------------------------- -// CONSOLE The score from each `match` clause is added together, then divided by the number of `match` clauses. @@ -246,36 +212,28 @@ but they use a `match_phrase` or `match_phrase_prefix` query instead of a This query: [source,js] -------------------------------------------------- -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" ] } } -------------------------------------------------- -// CONSOLE would be executed as: [source,js] -------------------------------------------------- -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" }} + ] } } -------------------------------------------------- -// CONSOLE Also, accepts `analyzer`, `boost`, `slop` and `zero_terms_query` as explained in <>. Type `phrase_prefix` additionally accepts @@ -330,19 +288,15 @@ A query like: [source,js] -------------------------------------------------- -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" } } -------------------------------------------------- -// CONSOLE is executed as: @@ -390,21 +344,17 @@ both use an `edge_ngram` analyzer, this query: [source,js] -------------------------------------------------- -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" - ] - } + ] } } -------------------------------------------------- -// CONSOLE would be executed as: @@ -429,33 +379,28 @@ parameter to just one of them: [source,js] -------------------------------------------------- -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" ] + } + } + ] } - } } -------------------------------------------------- -// CONSOLE - <1> Either `will` or `smith` must be present in either of the `first` or `last` fields @@ -464,20 +409,15 @@ parameter in the query. [source,js] -------------------------------------------------- -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" ] } } -------------------------------------------------- -// CONSOLE - <1> Use the `standard` analyzer for all fields. which will be executed as: diff --git a/docs/reference/query-dsl/nested-query.asciidoc b/docs/reference/query-dsl/nested-query.asciidoc index 06720552bde..0b861509c0e 100644 --- a/docs/reference/query-dsl/nested-query.asciidoc +++ b/docs/reference/query-dsl/nested-query.asciidoc @@ -10,45 +10,40 @@ will work with: [source,js] -------------------------------------------------- -PUT /my_index { - "mappings": { - "type1" : { - "properties" : { - "obj1" : { - "type" : "nested" - } + "type1" : { + "properties" : { + "obj1" : { + "type" : "nested" } } } } -------------------------------------------------- -// CONSOLE -// TESTSETUP And here is a sample nested query usage: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "nested" : { - "path" : "obj1", - "score_mode" : "avg", - "query" : { - "bool" : { - "must" : [ - { "match" : {"obj1.name" : "blue"} }, - { "range" : {"obj1.count" : {"gt" : 5}} } - ] - } + "nested" : { + "path" : "obj1", + "score_mode" : "avg", + "query" : { + "bool" : { + "must" : [ + { + "match" : {"obj1.name" : "blue"} + }, + { + "range" : {"obj1.count" : {"gt" : 5}} + } + ] } } } } -------------------------------------------------- -// CONSOLE The query `path` points to the nested object path, and the `query` includes the query that will run on the nested docs matching the diff --git a/docs/reference/query-dsl/parent-id-query.asciidoc b/docs/reference/query-dsl/parent-id-query.asciidoc index 10cf6d05664..1aef5b1948f 100644 --- a/docs/reference/query-dsl/parent-id-query.asciidoc +++ b/docs/reference/query-dsl/parent-id-query.asciidoc @@ -3,48 +3,17 @@ added[5.0.0] -The `parent_id` query can be used to find child documents which belong to a -particular parent. Given the following mapping definition: +The `parent_id` query can be used to find child documents which belong to a particular parent: [source,js] -------------------------------------------------- -PUT /my_index { - "mappings": { - "blog_post": { - "properties": { - "name": { - "type": "keyword" - } - } - }, - "blog_tag": { - "_parent": { - "type": "blog_post" - }, - "_routing": { - "required": true - } - } + "parent_id" : { + "type" : "blog_tag", + "id" : "1" } } -------------------------------------------------- -// CONSOLE -// TESTSETUP - -[source,js] --------------------------------------------------- -GET /_search -{ - "query": { - "parent_id" : { - "type" : "blog_tag", - "id" : "1" - } - } -} --------------------------------------------------- -// CONSOLE The above is functionally equivalent to using the following <> query, but performs @@ -52,21 +21,17 @@ better as it does not need to do a join: [source,js] -------------------------------------------------- -GET /my_index/_search { + "has_parent": { + "type": "blog", "query": { - "has_parent": { - "type": "blog_post", - "query": { - "term": { - "_id": "1" - } - } - } + "term": { + "_id": "1" + } } + } } -------------------------------------------------- -// CONSOLE ==== Parameters diff --git a/docs/reference/query-dsl/percolate-query.asciidoc b/docs/reference/query-dsl/percolate-query.asciidoc index 59d38f101ad..267647c9dbb 100644 --- a/docs/reference/query-dsl/percolate-query.asciidoc +++ b/docs/reference/query-dsl/percolate-query.asciidoc @@ -13,27 +13,26 @@ Create an index with two mappings: [source,js] -------------------------------------------------- -PUT /my-index +curl -XPUT "http://localhost:9200/my-index" -d' { - "mappings": { - "doctype": { - "properties": { - "message": { - "type": "string" - } - } - }, - "queries": { - "properties": { - "query": { - "type": "percolator" - } - } + "mappings": { + "doctype": { + "properties": { + "message": { + "type": "string" } + } + }, + "queries": { + "properties": { + "query": { + "type": "percolator" + } + } } -} + } +}' -------------------------------------------------- -// CONSOLE The `doctype` mapping is the mapping used to preprocess the document defined in the `percolator` query before it @@ -51,24 +50,20 @@ Register a query in the percolator: [source,js] -------------------------------------------------- -PUT /my-index/queries/1 -{ +curl -XPUT 'localhost:9200/my-index/queries/1' -d '{ "query" : { "match" : { "message" : "bonsai tree" } } -} +}' -------------------------------------------------- -// CONSOLE -// TEST[continued] Match a document to the registered percolator queries: [source,js] -------------------------------------------------- -GET /my-index/_search -{ +curl -XGET 'localhost:9200/my-index/_search' -d '{ "query" : { "percolate" : { "field" : "query", @@ -78,10 +73,8 @@ GET /my-index/_search } } } -} +}' -------------------------------------------------- -// CONSOLE -// TEST[continued] The above request will yield the following response: @@ -158,13 +151,12 @@ Index the document we want to percolate: [source,js] -------------------------------------------------- -PUT /my-index/message/1 +curl -XPUT "http://localhost:9200/my-index/message/1" -d' { "message" : "A new bonsai tree in the office" -} +}' -------------------------------------------------- -// CONSOLE -// TEST[continued] + Index response: [source,js] @@ -187,7 +179,7 @@ Percolating an existing document, using the index response as basis to build to [source,js] -------------------------------------------------- -GET /my-index/_search +curl -XGET "http://localhost:9200/my-index/_search" -d' { "query" : { "percolate" : { @@ -199,10 +191,8 @@ GET /my-index/_search "version" : 1 <1> } } -} +}' -------------------------------------------------- -// CONSOLE -// TEST[continued] <1> The version is optional, but useful in certain cases. We can then ensure that we are try to percolate the document we just have indexed. A change may be made after we have indexed, and if that is the @@ -226,39 +216,35 @@ Save a query: [source,js] -------------------------------------------------- -PUT /my-index/queries/1 +curl -XPUT "http://localhost:9200/my-index/queries/1" -d' { "query" : { "match" : { "message" : "brown fox" } } -} +}' -------------------------------------------------- -// CONSOLE -// TEST[continued] Save another query: [source,js] -------------------------------------------------- -PUT /my-index/queries/2 +curl -XPUT "http://localhost:9200/my-index/queries/2" -d' { "query" : { "match" : { "message" : "lazy dog" } } -} +}' -------------------------------------------------- -// CONSOLE -// TEST[continued] Execute a search request with the `percolate` query and highlighting enabled: [source,js] -------------------------------------------------- -GET /my-index/_search +curl -XGET "http://localhost:9200/my-index/_search" -d' { "query" : { "percolate" : { @@ -274,10 +260,8 @@ GET /my-index/_search "message": {} } } -} +}' -------------------------------------------------- -// CONSOLE -// TEST[continued] This will yield the following response. @@ -352,4 +336,4 @@ that are registered to the index that the search request is targeted for, are go in-memory index. This happens on each shard the search request needs to execute. By using `routing` or additional queries the amount of percolator queries that need to be executed can be reduced and thus -the time the search API needs to run can be decreased. +the time the search API needs to run can be decreased. \ No newline at end of file diff --git a/docs/reference/query-dsl/prefix-query.asciidoc b/docs/reference/query-dsl/prefix-query.asciidoc index d2b75d10e5f..cf26e850ad8 100644 --- a/docs/reference/query-dsl/prefix-query.asciidoc +++ b/docs/reference/query-dsl/prefix-query.asciidoc @@ -8,37 +8,28 @@ that starts with `ki`: [source,js] -------------------------------------------------- -GET /_search -{ "query": { +{ "prefix" : { "user" : "ki" } - } } -------------------------------------------------- -// CONSOLE A boost can also be associated with the query: [source,js] -------------------------------------------------- -GET /_search -{ "query": { +{ "prefix" : { "user" : { "value" : "ki", "boost" : 2.0 } } - } } -------------------------------------------------- -// CONSOLE Or : [source,js] -------------------------------------------------- -GET /_search -{ "query": { +{ "prefix" : { "user" : { "prefix" : "ki", "boost" : 2.0 } } - } } -------------------------------------------------- -// CONSOLE This multi term query allows you to control how it gets rewritten using the <> diff --git a/docs/reference/query-dsl/query-string-query.asciidoc b/docs/reference/query-dsl/query-string-query.asciidoc index 60477d6e28a..9ad68ad4f73 100644 --- a/docs/reference/query-dsl/query-string-query.asciidoc +++ b/docs/reference/query-dsl/query-string-query.asciidoc @@ -6,17 +6,13 @@ an example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "query_string" : { - "default_field" : "content", - "query" : "this AND that OR thus" - } + "query_string" : { + "default_field" : "content", + "query" : "this AND that OR thus" } } -------------------------------------------------- -// CONSOLE The `query_string` top level parameters include: @@ -117,33 +113,25 @@ For example, the following query [source,js] -------------------------------------------------- -GET /_search { - "query": { - "query_string" : { - "fields" : ["content", "name"], - "query" : "this AND that" - } + "query_string" : { + "fields" : ["content", "name"], + "query" : "this AND that" } } -------------------------------------------------- -// CONSOLE matches the same words as [source,js] -------------------------------------------------- -GET /_search { - "query": { - "query_string": { - "query": "(content:this OR name:this) AND (content:that OR name:that)" - } + "query_string": { + "query": "(content:this OR name:this) AND (content:that OR name:that)" } } -------------------------------------------------- -// CONSOLE Since several queries are generated from the individual search terms, combining them can be automatically done using either a `dis_max` query or a @@ -152,18 +140,14 @@ notation): [source,js] -------------------------------------------------- -GET /_search { - "query": { - "query_string" : { - "fields" : ["content", "name^5"], - "query" : "this AND that OR thus", - "use_dis_max" : true - } + "query_string" : { + "fields" : ["content", "name^5"], + "query" : "this AND that OR thus", + "use_dis_max" : true } } -------------------------------------------------- -// CONSOLE Simple wildcard can also be used to search "within" specific inner elements of the document. For example, if we have a `city` object with @@ -172,18 +156,14 @@ search on all "city" fields: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "query_string" : { - "fields" : ["city.*"], - "query" : "this AND that OR thus", - "use_dis_max" : true - } + "query_string" : { + "fields" : ["city.*"], + "query" : "this AND that OR thus", + "use_dis_max" : true } } -------------------------------------------------- -// CONSOLE Another option is to provide the wildcard fields search in the query string itself (properly escaping the `*` sign), for example: @@ -208,17 +188,13 @@ introduced fields included). For example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "query_string" : { - "fields" : ["content", "name.*^5"], - "query" : "this AND that OR thus", - "use_dis_max" : true - } + "query_string" : { + "fields" : ["content", "name.*^5"], + "query" : "this AND that OR thus", + "use_dis_max" : true } } -------------------------------------------------- -// CONSOLE include::query-string-syntax.asciidoc[] diff --git a/docs/reference/query-dsl/query_filter_context.asciidoc b/docs/reference/query-dsl/query_filter_context.asciidoc index 79f8c4bd960..6fadc36aa73 100644 --- a/docs/reference/query-dsl/query_filter_context.asciidoc +++ b/docs/reference/query-dsl/query_filter_context.asciidoc @@ -47,7 +47,7 @@ conditions are met: [source,js] ------------------------------------ -GET /_search +GET _search { "query": { <1> "bool": { <2> @@ -63,7 +63,6 @@ GET /_search } } ------------------------------------ -// 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 a0005ff3ff2..eaf1dca8181 100644 --- a/docs/reference/query-dsl/range-query.asciidoc +++ b/docs/reference/query-dsl/range-query.asciidoc @@ -9,20 +9,16 @@ a `NumericRangeQuery`. The following example returns all documents where [source,js] -------------------------------------------------- -GET _search { - "query": { - "range" : { - "age" : { - "gte" : 10, - "lte" : 20, - "boost" : 2.0 - } + "range" : { + "age" : { + "gte" : 10, + "lte" : 20, + "boost" : 2.0 } } } -------------------------------------------------- -// CONSOLE The `range` query accepts the following parameters: @@ -42,19 +38,15 @@ specified using <>: [source,js] -------------------------------------------------- -GET _search { - "query": { - "range" : { - "date" : { - "gte" : "now-1d/d", - "lt" : "now/d" - } + "range" : { + "date" : { + "gte" : "now-1d/d", + "lt" : "now/d" } } } -------------------------------------------------- -// CONSOLE ===== Date math and rounding @@ -94,20 +86,16 @@ passing the `format` parameter to the `range` query: [source,js] -------------------------------------------------- -GET _search { - "query": { - "range" : { - "born" : { - "gte": "01/01/2012", - "lte": "2013", - "format": "dd/MM/yyyy||yyyy" - } + "range" : { + "born" : { + "gte": "01/01/2012", + "lte": "2013", + "format": "dd/MM/yyyy||yyyy" } } } -------------------------------------------------- -// CONSOLE ===== Time zone in range queries @@ -117,19 +105,15 @@ accepts it), or it can be specified as the `time_zone` parameter: [source,js] -------------------------------------------------- -GET _search { - "query": { - "range" : { - "timestamp" : { - "gte": "2015-01-01 00:00:00", <1> - "lte": "now", <2> - "time_zone": "+01:00" - } + "range" : { + "timestamp" : { + "gte": "2015-01-01 00:00:00", <1> + "lte": "now", <2> + "time_zone": "+01:00" } } } -------------------------------------------------- -// 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/regexp-query.asciidoc b/docs/reference/query-dsl/regexp-query.asciidoc index 2d57f1d7dd0..692caf43480 100644 --- a/docs/reference/query-dsl/regexp-query.asciidoc +++ b/docs/reference/query-dsl/regexp-query.asciidoc @@ -15,52 +15,40 @@ matchers like `.*?+` will mostly lower performance. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "regexp":{ - "name.first": "s.*y" - } + "regexp":{ + "name.first": "s.*y" } } -------------------------------------------------- -// CONSOLE Boosting is also supported [source,js] -------------------------------------------------- -GET /_search { - "query": { - "regexp":{ - "name.first":{ - "value":"s.*y", - "boost":1.2 - } + "regexp":{ + "name.first":{ + "value":"s.*y", + "boost":1.2 } } } -------------------------------------------------- -// CONSOLE You can also use special flags [source,js] -------------------------------------------------- -GET /_search { - "query": { - "regexp":{ - "name.first": { - "value": "s.*y", - "flags" : "INTERSECTION|COMPLEMENT|EMPTY" - } + "regexp":{ + "name.first": { + "value": "s.*y", + "flags" : "INTERSECTION|COMPLEMENT|EMPTY" } } } -------------------------------------------------- -// CONSOLE Possible flags are `ALL` (default), `ANYSTRING`, `COMPLEMENT`, `EMPTY`, `INTERSECTION`, `INTERVAL`, or `NONE`. Please check the @@ -76,19 +64,16 @@ this limit to allow more complex regular expressions to execute. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "regexp":{ - "name.first": { - "value": "s.*y", - "flags" : "INTERSECTION|COMPLEMENT|EMPTY", - "max_determinized_states": 20000 - } + "regexp":{ + "name.first": { + "value": "s.*y", + "flags" : "INTERSECTION|COMPLEMENT|EMPTY", + "max_determinized_states": 20000 } } } -------------------------------------------------- -// CONSOLE + include::regexp-syntax.asciidoc[] diff --git a/docs/reference/query-dsl/script-query.asciidoc b/docs/reference/query-dsl/script-query.asciidoc index ee06a1b64bd..223460f723d 100644 --- a/docs/reference/query-dsl/script-query.asciidoc +++ b/docs/reference/query-dsl/script-query.asciidoc @@ -7,20 +7,17 @@ context, for example: [source,js] ---------------------------------------------- -GET /_search -{ - "query": { - "bool" : { - "must" : { - "script" : { - "script" : "doc['num1'].value > 1" - } - } +"bool" : { + "must" : { + ... + }, + "filter" : { + "script" : { + "script" : "doc['num1'].value > 1" } } } ---------------------------------------------- -// CONSOLE [float] ==== Custom Parameters @@ -31,23 +28,20 @@ to use the ability to pass parameters to the script itself, for example: [source,js] ---------------------------------------------- -GET /_search -{ - "query": { - "bool" : { - "must" : { - "script" : { - "script" : { - "inline" : "doc['num1'].value > param1", - "params" : { - "param1" : 5 - } - } +"bool" : { + "must" : { + ... + }, + "filter" : { + "script" : { + "script" : { + "inline" : "doc['num1'].value > param1" + "params" : { + "param1" : 5 } } } } } ---------------------------------------------- -// CONSOLE diff --git a/docs/reference/query-dsl/simple-query-string-query.asciidoc b/docs/reference/query-dsl/simple-query-string-query.asciidoc index 796f2517fea..572c0661fa4 100644 --- a/docs/reference/query-dsl/simple-query-string-query.asciidoc +++ b/docs/reference/query-dsl/simple-query-string-query.asciidoc @@ -8,19 +8,15 @@ an example: [source,js] -------------------------------------------------- -GET /_search { - "query": { "simple_query_string" : { "query": "\"fried eggs\" +(eggplant | potato) -frittata", "analyzer": "snowball", "fields": ["body^5","_all"], "default_operator": "and" } - } } -------------------------------------------------- -// CONSOLE The `simple_query_string` top level parameters include: @@ -98,17 +94,13 @@ introduced fields included). For example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "simple_query_string" : { - "fields" : ["content", "name.*^5"], - "query" : "foo bar baz" - } + "simple_query_string" : { + "fields" : ["content", "name.*^5"], + "query" : "foo bar baz" } } -------------------------------------------------- -// CONSOLE [float] ==== Flags @@ -118,17 +110,13 @@ should be enabled. It is specified as a `|`-delimited string with the [source,js] -------------------------------------------------- -GET /_search { - "query": { - "simple_query_string" : { - "query" : "foo | bar + baz*", - "flags" : "OR|AND|PREFIX" - } + "simple_query_string" : { + "query" : "foo | bar + baz*", + "flags" : "OR|AND|PREFIX" } } -------------------------------------------------- -// CONSOLE The available flags are: `ALL`, `NONE`, `AND`, `OR`, `NOT`, `PREFIX`, `PHRASE`, `PRECEDENCE`, `ESCAPE`, `WHITESPACE`, `FUZZY`, `NEAR`, and `SLOP`. diff --git a/docs/reference/query-dsl/span-containing-query.asciidoc b/docs/reference/query-dsl/span-containing-query.asciidoc index 638c6999233..965bf855b6f 100644 --- a/docs/reference/query-dsl/span-containing-query.asciidoc +++ b/docs/reference/query-dsl/span-containing-query.asciidoc @@ -6,28 +6,24 @@ query maps to Lucene `SpanContainingQuery`. Here is an example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "span_containing" : { - "little" : { - "span_term" : { "field1" : "foo" } - }, - "big" : { - "span_near" : { - "clauses" : [ - { "span_term" : { "field1" : "bar" } }, - { "span_term" : { "field1" : "baz" } } - ], - "slop" : 5, - "in_order" : true - } + "span_containing" : { + "little" : { + "span_term" : { "field1" : "foo" } + }, + "big" : { + "span_near" : { + "clauses" : [ + { "span_term" : { "field1" : "bar" } }, + { "span_term" : { "field1" : "baz" } } + ], + "slop" : 5, + "in_order" : true } } } } -------------------------------------------------- -// CONSOLE The `big` and `little` clauses can be any span type query. Matching spans from `big` that contain matches from `little` are returned. diff --git a/docs/reference/query-dsl/span-first-query.asciidoc b/docs/reference/query-dsl/span-first-query.asciidoc index dba7932661d..74fe7ff88ba 100644 --- a/docs/reference/query-dsl/span-first-query.asciidoc +++ b/docs/reference/query-dsl/span-first-query.asciidoc @@ -6,19 +6,15 @@ to Lucene `SpanFirstQuery`. Here is an example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "span_first" : { - "match" : { - "span_term" : { "user" : "kimchy" } - }, - "end" : 3 - } + "span_first" : { + "match" : { + "span_term" : { "user" : "kimchy" } + }, + "end" : 3 } } -------------------------------------------------- -// 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-multi-term-query.asciidoc b/docs/reference/query-dsl/span-multi-term-query.asciidoc index 3d1672753d2..af3da5cf7dd 100644 --- a/docs/reference/query-dsl/span-multi-term-query.asciidoc +++ b/docs/reference/query-dsl/span-multi-term-query.asciidoc @@ -7,32 +7,24 @@ it can be nested. Example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "span_multi":{ - "match":{ - "prefix" : { "user" : { "value" : "ki" } } - } + "span_multi":{ + "match":{ + "prefix" : { "user" : { "value" : "ki" } } } } } -------------------------------------------------- -// CONSOLE A boost can also be associated with the query: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "span_multi":{ - "match":{ - "prefix" : { "user" : { "value" : "ki", "boost" : 1.08 } } - } + "span_multi":{ + "match":{ + "prefix" : { "user" : { "value" : "ki", "boost" : 1.08 } } } } } -------------------------------------------------- -// CONSOLE diff --git a/docs/reference/query-dsl/span-near-query.asciidoc b/docs/reference/query-dsl/span-near-query.asciidoc index e69be783e3d..258bc3b51ad 100644 --- a/docs/reference/query-dsl/span-near-query.asciidoc +++ b/docs/reference/query-dsl/span-near-query.asciidoc @@ -8,22 +8,18 @@ matches are required to be in-order. The span near query maps to Lucene [source,js] -------------------------------------------------- -GET /_search { - "query": { - "span_near" : { - "clauses" : [ - { "span_term" : { "field" : "value1" } }, - { "span_term" : { "field" : "value2" } }, - { "span_term" : { "field" : "value3" } } - ], - "slop" : 12, - "in_order" : false - } + "span_near" : { + "clauses" : [ + { "span_term" : { "field" : "value1" } }, + { "span_term" : { "field" : "value2" } }, + { "span_term" : { "field" : "value3" } } + ], + "slop" : 12, + "in_order" : false } } -------------------------------------------------- -// CONSOLE The `clauses` element is a list of one or more other span type queries and the `slop` controls the maximum number of intervening unmatched diff --git a/docs/reference/query-dsl/span-not-query.asciidoc b/docs/reference/query-dsl/span-not-query.asciidoc index 5a648bd4b0e..73186985b0d 100644 --- a/docs/reference/query-dsl/span-not-query.asciidoc +++ b/docs/reference/query-dsl/span-not-query.asciidoc @@ -6,28 +6,24 @@ query maps to Lucene `SpanNotQuery`. Here is an example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "span_not" : { - "include" : { - "span_term" : { "field1" : "hoya" } - }, - "exclude" : { - "span_near" : { - "clauses" : [ - { "span_term" : { "field1" : "la" } }, - { "span_term" : { "field1" : "hoya" } } - ], - "slop" : 0, - "in_order" : true - } + "span_not" : { + "include" : { + "span_term" : { "field1" : "hoya" } + }, + "exclude" : { + "span_near" : { + "clauses" : [ + { "span_term" : { "field1" : "la" } }, + { "span_term" : { "field1" : "hoya" } } + ], + "slop" : 0, + "in_order" : true } } } } -------------------------------------------------- -// CONSOLE The `include` and `exclude` clauses can be any span type query. The `include` clause is the span query whose matches are filtered, and the diff --git a/docs/reference/query-dsl/span-or-query.asciidoc b/docs/reference/query-dsl/span-or-query.asciidoc index 470935d6f5c..72a4ce8724b 100644 --- a/docs/reference/query-dsl/span-or-query.asciidoc +++ b/docs/reference/query-dsl/span-or-query.asciidoc @@ -6,19 +6,15 @@ Matches the union of its span clauses. The span or query maps to Lucene [source,js] -------------------------------------------------- -GET /_search { - "query": { - "span_or" : { - "clauses" : [ - { "span_term" : { "field" : "value1" } }, - { "span_term" : { "field" : "value2" } }, - { "span_term" : { "field" : "value3" } } - ] - } + "span_or" : { + "clauses" : [ + { "span_term" : { "field" : "value1" } }, + { "span_term" : { "field" : "value2" } }, + { "span_term" : { "field" : "value3" } } + ] } } -------------------------------------------------- -// CONSOLE The `clauses` element is a list of one or more other span type queries. diff --git a/docs/reference/query-dsl/span-term-query.asciidoc b/docs/reference/query-dsl/span-term-query.asciidoc index 1b12a3c35f7..9de86d48684 100644 --- a/docs/reference/query-dsl/span-term-query.asciidoc +++ b/docs/reference/query-dsl/span-term-query.asciidoc @@ -6,37 +6,25 @@ Matches spans containing a term. The span term query maps to Lucene [source,js] -------------------------------------------------- -GET /_search { - "query": { - "span_term" : { "user" : "kimchy" } - } + "span_term" : { "user" : "kimchy" } } -------------------------------------------------- -// CONSOLE A boost can also be associated with the query: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "span_term" : { "user" : { "value" : "kimchy", "boost" : 2.0 } } - } + "span_term" : { "user" : { "value" : "kimchy", "boost" : 2.0 } } } -------------------------------------------------- -// CONSOLE Or : [source,js] -------------------------------------------------- -GET /_search { - "query": { - "span_term" : { "user" : { "term" : "kimchy", "boost" : 2.0 } } - } + "span_term" : { "user" : { "term" : "kimchy", "boost" : 2.0 } } } -------------------------------------------------- -// CONSOLE diff --git a/docs/reference/query-dsl/span-within-query.asciidoc b/docs/reference/query-dsl/span-within-query.asciidoc index b70835c4134..dc5c4bbfdfd 100644 --- a/docs/reference/query-dsl/span-within-query.asciidoc +++ b/docs/reference/query-dsl/span-within-query.asciidoc @@ -6,28 +6,24 @@ query maps to Lucene `SpanWithinQuery`. Here is an example: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "span_within" : { - "little" : { - "span_term" : { "field1" : "foo" } - }, - "big" : { - "span_near" : { - "clauses" : [ - { "span_term" : { "field1" : "bar" } }, - { "span_term" : { "field1" : "baz" } } - ], - "slop" : 5, - "in_order" : true - } + "span_within" : { + "little" : { + "span_term" : { "field1" : "foo" } + }, + "big" : { + "span_near" : { + "clauses" : [ + { "span_term" : { "field1" : "bar" } }, + { "span_term" : { "field1" : "baz" } } + ], + "slop" : 5, + "in_order" : true } } } } -------------------------------------------------- -// CONSOLE The `big` and `little` clauses can be any span type query. Matching spans from `little` that are enclosed within `big` are returned. diff --git a/docs/reference/query-dsl/template-query.asciidoc b/docs/reference/query-dsl/template-query.asciidoc index f66dbe56d3e..35365e6f9b2 100644 --- a/docs/reference/query-dsl/template-query.asciidoc +++ b/docs/reference/query-dsl/template-query.asciidoc @@ -19,8 +19,8 @@ GET /_search } } } + ------------------------------------------ -// CONSOLE The above request is translated into: @@ -34,8 +34,8 @@ GET /_search } } } + ------------------------------------------ -// CONSOLE Alternatively passing the template as an escaped string works as well: @@ -53,8 +53,6 @@ GET /_search } } ------------------------------------------ -// CONSOLE - <1> New line characters (`\n`) should be escaped as `\\n` or removed, and quotes (`"`) should be escaped as `\\"`. @@ -79,8 +77,6 @@ GET /_search } } ------------------------------------------ -// CONSOLE - <1> Name of the query template in `config/scripts/`, i.e., `my_template.mustache`. Alternatively, you can register a query template in the cluster state with: @@ -89,10 +85,9 @@ Alternatively, you can register a query template in the cluster state with: ------------------------------------------ PUT /_search/template/my_template { - "template": { "match": { "text": "{{query_string}}" }} + "template": { "match": { "text": "{{query_string}}" }}, } ------------------------------------------ -// CONSOLE and refer to it in the `template` query with the `id` parameter: @@ -111,13 +106,9 @@ GET /_search } } ------------------------------------------ -// CONSOLE -// TEST[continued] - <1> Name of the query template in `config/scripts/`, i.e., `my_template.mustache`. There is also a dedicated `template` endpoint, allows you to template an entire search request. Please see <> for more details. - diff --git a/docs/reference/query-dsl/terms-query.asciidoc b/docs/reference/query-dsl/terms-query.asciidoc index e00c18bb56f..08df1e6fece 100644 --- a/docs/reference/query-dsl/terms-query.asciidoc +++ b/docs/reference/query-dsl/terms-query.asciidoc @@ -6,18 +6,14 @@ Filters documents that have fields that match any of the provided terms [source,js] -------------------------------------------------- -GET /_search { - "query": { - "constant_score" : { - "filter" : { - "terms" : { "user" : ["kimchy", "elasticsearch"]} - } + "constant_score" : { + "filter" : { + "terms" : { "user" : ["kimchy", "elasticsearch"]} } } } -------------------------------------------------- -// CONSOLE The `terms` query is also aliased with `in` as the filter name for simpler usage deprecated[5.0.0,use `terms` instead]. @@ -67,37 +63,33 @@ possible, reducing the need for networking. [float] ===== Terms lookup twitter example -At first we index the information for user with id 2, specifically, its -followers, than index a tweet from user with id 1. Finally we search on -all the tweets that match the followers of user 2. [source,js] -------------------------------------------------- -PUT /users/user/2 -{ - "followers" : ["1", "3"] -} +# index the information for user with id 2, specifically, its followers +curl -XPUT localhost:9200/users/user/2 -d '{ + "followers" : ["1", "3"] +}' -PUT /tweets/tweet/1 -{ - "user" : "1" -} +# index a tweet, from user with id 1 +curl -XPUT localhost:9200/tweets/tweet/1 -d '{ + "user" : "1" +}' -GET /tweets/_search -{ - "query" : { - "terms" : { - "user" : { - "index" : "users", - "type" : "user", - "id" : "2", - "path" : "followers" - } - } +# search on all the tweets that match the followers of user 2 +curl -XGET localhost:9200/tweets/_search -d '{ + "query" : { + "terms" : { + "user" : { + "index" : "users", + "type" : "user", + "id" : "2", + "path" : "followers" + } } -} + } +}' -------------------------------------------------- -// CONSOLE The structure of the external terms document can also include array of inner objects, for example: diff --git a/docs/reference/query-dsl/type-query.asciidoc b/docs/reference/query-dsl/type-query.asciidoc index 05e909bc366..d3ef1a30fb1 100644 --- a/docs/reference/query-dsl/type-query.asciidoc +++ b/docs/reference/query-dsl/type-query.asciidoc @@ -5,13 +5,9 @@ Filters documents matching the provided document / mapping type. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "type" : { - "value" : "my_type" - } + "type" : { + "value" : "my_type" } } -------------------------------------------------- -// CONSOLE diff --git a/docs/reference/query-dsl/wildcard-query.asciidoc b/docs/reference/query-dsl/wildcard-query.asciidoc index ad82c029d8c..d72dbec2481 100644 --- a/docs/reference/query-dsl/wildcard-query.asciidoc +++ b/docs/reference/query-dsl/wildcard-query.asciidoc @@ -11,40 +11,28 @@ query maps to Lucene `WildcardQuery`. [source,js] -------------------------------------------------- -GET /_search { - "query": { - "wildcard" : { "user" : "ki*y" } - } + "wildcard" : { "user" : "ki*y" } } -------------------------------------------------- -// CONSOLE A boost can also be associated with the query: [source,js] -------------------------------------------------- -GET /_search { - "query": { - "wildcard" : { "user" : { "value" : "ki*y", "boost" : 2.0 } } - } + "wildcard" : { "user" : { "value" : "ki*y", "boost" : 2.0 } } } -------------------------------------------------- -// CONSOLE Or : [source,js] -------------------------------------------------- -GET /_search { - "query": { - "wildcard" : { "user" : { "wildcard" : "ki*y", "boost" : 2.0 } } - } + "wildcard" : { "user" : { "wildcard" : "ki*y", "boost" : 2.0 } } } -------------------------------------------------- -// CONSOLE This multi term query allows to control how it gets rewritten using the <>