CONSOLE is the new AUTOSENSE

This commit is contained in:
Isabel Drost-Fromm 2016-05-10 12:42:17 +02:00
parent e486560ea8
commit a865090cf3
14 changed files with 313 additions and 310 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <<docs-multi-get,Multi GET API>>.
--------------------------------------------------
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 <<docs-termvectors-artificial-doc
--------------------------------------------------
GET /_search
{
"query": {
"more_like_this" : {
"fields" : ["name.first", "name.last"],
"like" : [
{
"_index" : "marvel",
"_type" : "quotes",
"doc" : {
"name": {
"first": "Ben",
"last": "Grimm"
},
"tweet": "You got no idea what I'd... what I'd give to be invisible."
}
},
{
"_index" : "marvel",
"_type" : "quotes",
"_id" : "2"
"query": {
"more_like_this" : {
"fields" : ["name.first", "name.last"],
"like" : [
{
"_index" : "marvel",
"_type" : "quotes",
"doc" : {
"name": {
"first": "Ben",
"last": "Grimm"
},
"tweet": "You got no idea what I'd... what I'd give to be invisible."
}
},
{
"_index" : "marvel",
"_type" : "quotes",
"_id" : "2"
}
],
"min_term_freq" : 1,
"max_query_terms" : 12
}
],
"min_term_freq" : 1,
"max_query_terms" : 12
}
}
}
--------------------------------------------------
// AUTOSENSE
// CONSOLE
==== How it Works
@ -125,32 +125,32 @@ default, but there will be no speed up on analysis for these fields.
--------------------------------------------------
PUT /imdb
{
"mappings": {
"movies": {
"properties": {
"title": {
"type": "text",
"term_vector": "yes"
},
"description": {
"type": "text"
},
"tags": {
"type": "text",
"fields" : {
"raw": {
"type" : "text",
"analyzer": "keyword",
"term_vector" : "yes"
"mappings": {
"movies": {
"properties": {
"title": {
"type": "text",
"term_vector": "yes"
},
"description": {
"type": "text"
},
"tags": {
"type": "text",
"fields" : {
"raw": {
"type" : "text",
"analyzer": "keyword",
"term_vector" : "yes"
}
}
}
}
}
}
}
}
}
}
--------------------------------------------------
// AUTOSENSE
// CONSOLE
==== Parameters

View File

@ -16,7 +16,7 @@ GET /_search
}
}
--------------------------------------------------
// AUTOSENSE
// CONSOLE
<1> 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 <<query-dsl-match-query>>. 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.

View File

@ -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
<<query-dsl-multi-term-rewrite,rewrite>>

View File

@ -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

View File

@ -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).

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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`.

View File

@ -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