mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
Merge pull request #18544 from MaineC/docs/add_autosense_to_query_dsl
Add back doc execution to query dsl.
This commit is contained in:
commit
d76f87155a
46 changed files with 1391 additions and 853 deletions
|
@ -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
|
This first query assigns a score of `0` to all documents, as no scoring
|
||||||
query has been specified:
|
query has been specified:
|
||||||
|
|
||||||
[source,json]
|
[source,js]
|
||||||
---------------------------------
|
---------------------------------
|
||||||
GET _search
|
GET _search
|
||||||
{
|
{
|
||||||
|
@ -101,7 +101,7 @@ GET _search
|
||||||
This `bool` query has a `match_all` query, which assigns a score of `1.0` to
|
This `bool` query has a `match_all` query, which assigns a score of `1.0` to
|
||||||
all documents.
|
all documents.
|
||||||
|
|
||||||
[source,json]
|
[source,js]
|
||||||
---------------------------------
|
---------------------------------
|
||||||
GET _search
|
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
|
The `constant_score` query assigns a score of `1.0` to all documents matched
|
||||||
by the filter.
|
by the filter.
|
||||||
|
|
||||||
[source,json]
|
[source,js]
|
||||||
---------------------------------
|
---------------------------------
|
||||||
GET _search
|
GET _search
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,19 +8,23 @@ overall score.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"boosting" : {
|
"query": {
|
||||||
"positive" : {
|
"boosting" : {
|
||||||
"term" : {
|
"positive" : {
|
||||||
"field1" : "value1"
|
"term" : {
|
||||||
}
|
"field1" : "value1"
|
||||||
},
|
}
|
||||||
"negative" : {
|
},
|
||||||
"term" : {
|
"negative" : {
|
||||||
"field2" : "value2"
|
"term" : {
|
||||||
}
|
"field2" : "value2"
|
||||||
},
|
}
|
||||||
"negative_boost" : 0.2
|
},
|
||||||
|
"negative_boost" : 0.2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
|
@ -70,15 +70,19 @@ In this example, words that have a document frequency greater than 0.1%
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"common": {
|
"query": {
|
||||||
"body": {
|
"common": {
|
||||||
"query": "this is bonsai cool",
|
"body": {
|
||||||
"cutoff_frequency": 0.001
|
"query": "this is bonsai cool",
|
||||||
|
"cutoff_frequency": 0.001
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The number of terms which should match can be controlled with the
|
The number of terms which should match can be controlled with the
|
||||||
<<query-dsl-minimum-should-match,`minimum_should_match`>>
|
<<query-dsl-minimum-should-match,`minimum_should_match`>>
|
||||||
|
@ -90,36 +94,44 @@ all terms required:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"common": {
|
"query": {
|
||||||
"body": {
|
"common": {
|
||||||
"query": "nelly the elephant as a cartoon",
|
"body": {
|
||||||
"cutoff_frequency": 0.001,
|
"query": "nelly the elephant as a cartoon",
|
||||||
"low_freq_operator": "and"
|
"cutoff_frequency": 0.001,
|
||||||
|
"low_freq_operator": "and"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
which is roughly equivalent to:
|
which is roughly equivalent to:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool": {
|
"query": {
|
||||||
"must": [
|
"bool": {
|
||||||
{ "term": { "body": "nelly"}},
|
"must": [
|
||||||
{ "term": { "body": "elephant"}},
|
{ "term": { "body": "nelly"}},
|
||||||
{ "term": { "body": "cartoon"}}
|
{ "term": { "body": "elephant"}},
|
||||||
],
|
{ "term": { "body": "cartoon"}}
|
||||||
"should": [
|
],
|
||||||
{ "term": { "body": "the"}}
|
"should": [
|
||||||
{ "term": { "body": "as"}}
|
{ "term": { "body": "the"}},
|
||||||
{ "term": { "body": "a"}}
|
{ "term": { "body": "as"}},
|
||||||
]
|
{ "term": { "body": "a"}}
|
||||||
}
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
Alternatively use
|
Alternatively use
|
||||||
<<query-dsl-minimum-should-match,`minimum_should_match`>>
|
<<query-dsl-minimum-should-match,`minimum_should_match`>>
|
||||||
|
@ -128,41 +140,49 @@ must be present, for instance:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"common": {
|
"query": {
|
||||||
"body": {
|
"common": {
|
||||||
"query": "nelly the elephant as a cartoon",
|
"body": {
|
||||||
"cutoff_frequency": 0.001,
|
"query": "nelly the elephant as a cartoon",
|
||||||
"minimum_should_match": 2
|
"cutoff_frequency": 0.001,
|
||||||
|
"minimum_should_match": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
which is roughly equivalent to:
|
which is roughly equivalent to:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool": {
|
"query": {
|
||||||
"must": {
|
"bool": {
|
||||||
"bool": {
|
"must": {
|
||||||
"should": [
|
"bool": {
|
||||||
{ "term": { "body": "nelly"}},
|
"should": [
|
||||||
{ "term": { "body": "elephant"}},
|
{ "term": { "body": "nelly"}},
|
||||||
{ "term": { "body": "cartoon"}}
|
{ "term": { "body": "elephant"}},
|
||||||
],
|
{ "term": { "body": "cartoon"}}
|
||||||
"minimum_should_match": 2
|
],
|
||||||
}
|
"minimum_should_match": 2
|
||||||
},
|
}
|
||||||
"should": [
|
},
|
||||||
{ "term": { "body": "the"}}
|
"should": [
|
||||||
{ "term": { "body": "as"}}
|
{ "term": { "body": "the"}},
|
||||||
{ "term": { "body": "a"}}
|
{ "term": { "body": "as"}},
|
||||||
]
|
{ "term": { "body": "a"}}
|
||||||
}
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
minimum_should_match
|
minimum_should_match
|
||||||
|
|
||||||
|
@ -174,50 +194,58 @@ additional parameters (note the change in structure):
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"common": {
|
"query": {
|
||||||
"body": {
|
"common": {
|
||||||
"query": "nelly the elephant not as a cartoon",
|
"body": {
|
||||||
"cutoff_frequency": 0.001,
|
"query": "nelly the elephant not as a cartoon",
|
||||||
"minimum_should_match": {
|
"cutoff_frequency": 0.001,
|
||||||
"low_freq" : 2,
|
"minimum_should_match": {
|
||||||
"high_freq" : 3
|
"low_freq" : 2,
|
||||||
}
|
"high_freq" : 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
which is roughly equivalent to:
|
which is roughly equivalent to:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool": {
|
"query": {
|
||||||
"must": {
|
"bool": {
|
||||||
"bool": {
|
"must": {
|
||||||
"should": [
|
"bool": {
|
||||||
{ "term": { "body": "nelly"}},
|
"should": [
|
||||||
{ "term": { "body": "elephant"}},
|
{ "term": { "body": "nelly"}},
|
||||||
{ "term": { "body": "cartoon"}}
|
{ "term": { "body": "elephant"}},
|
||||||
],
|
{ "term": { "body": "cartoon"}}
|
||||||
"minimum_should_match": 2
|
],
|
||||||
}
|
"minimum_should_match": 2
|
||||||
},
|
}
|
||||||
"should": {
|
},
|
||||||
"bool": {
|
"should": {
|
||||||
"should": [
|
"bool": {
|
||||||
{ "term": { "body": "the"}},
|
"should": [
|
||||||
{ "term": { "body": "not"}},
|
{ "term": { "body": "the"}},
|
||||||
{ "term": { "body": "as"}},
|
{ "term": { "body": "not"}},
|
||||||
{ "term": { "body": "a"}}
|
{ "term": { "body": "as"}},
|
||||||
],
|
{ "term": { "body": "a"}}
|
||||||
"minimum_should_match": 3
|
],
|
||||||
}
|
"minimum_should_match": 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
In this case it means the high frequency terms have only an impact on
|
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
|
relevance when there are at least three of them. But the most
|
||||||
|
@ -227,36 +255,44 @@ for high frequency terms is when there are only high frequency terms:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"common": {
|
"query": {
|
||||||
"body": {
|
"common": {
|
||||||
"query": "how not to be",
|
"body": {
|
||||||
"cutoff_frequency": 0.001,
|
"query": "how not to be",
|
||||||
"minimum_should_match": {
|
"cutoff_frequency": 0.001,
|
||||||
"low_freq" : 2,
|
"minimum_should_match": {
|
||||||
"high_freq" : 3
|
"low_freq" : 2,
|
||||||
}
|
"high_freq" : 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
which is roughly equivalent to:
|
which is roughly equivalent to:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool": {
|
"query": {
|
||||||
"should": [
|
"bool": {
|
||||||
{ "term": { "body": "how"}},
|
"should": [
|
||||||
{ "term": { "body": "not"}},
|
{ "term": { "body": "how"}},
|
||||||
{ "term": { "body": "to"}},
|
{ "term": { "body": "not"}},
|
||||||
{ "term": { "body": "be"}}
|
{ "term": { "body": "to"}},
|
||||||
],
|
{ "term": { "body": "be"}}
|
||||||
"minimum_should_match": "3<50%"
|
],
|
||||||
}
|
"minimum_should_match": "3<50%"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The high frequency generated query is then slightly less restrictive
|
The high frequency generated query is then slightly less restrictive
|
||||||
than with an `AND`.
|
than with an `AND`.
|
||||||
|
|
|
@ -7,12 +7,16 @@ filter. Maps to Lucene `ConstantScoreQuery`.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"constant_score" : {
|
"query": {
|
||||||
"filter" : {
|
"constant_score" : {
|
||||||
"term" : { "user" : "kimchy"}
|
"filter" : {
|
||||||
},
|
"term" : { "user" : "kimchy"}
|
||||||
"boost" : 1.2
|
},
|
||||||
|
"boost" : 1.2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
|
@ -27,18 +27,22 @@ This query maps to Lucene `DisjunctionMaxQuery`.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"dis_max" : {
|
"query": {
|
||||||
"tie_breaker" : 0.7,
|
"dis_max" : {
|
||||||
"boost" : 1.2,
|
"tie_breaker" : 0.7,
|
||||||
"queries" : [
|
"boost" : 1.2,
|
||||||
{
|
"queries" : [
|
||||||
"term" : { "age" : 34 }
|
{
|
||||||
},
|
"term" : { "age" : 34 }
|
||||||
{
|
},
|
||||||
"term" : { "age" : 35 }
|
{
|
||||||
}
|
"term" : { "age" : 35 }
|
||||||
]
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
|
@ -5,10 +5,14 @@ Returns documents that have at least one non-`null` value in the original field:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"exists" : { "field" : "user" }
|
"query": {
|
||||||
|
"exists" : { "field" : "user" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
For instance, these documents would all match the above query:
|
For instance, these documents would all match the above query:
|
||||||
|
|
||||||
|
@ -77,14 +81,20 @@ clause as follows:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
"bool": {
|
GET /_search
|
||||||
"must_not": {
|
{
|
||||||
"exists": {
|
"query": {
|
||||||
"field": "user"
|
"bool": {
|
||||||
|
"must_not": {
|
||||||
|
"exists": {
|
||||||
|
"field": "user"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
This query returns documents that have no value in the user field.
|
This query returns documents that have no value in the user field.
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,20 @@ by the query.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
"function_score": {
|
GET /_search
|
||||||
"query": {},
|
{
|
||||||
"boost": "boost for the whole query",
|
"query": {
|
||||||
"FUNCTION": {}, <1>
|
"function_score": {
|
||||||
"boost_mode":"(multiply|replace|...)"
|
"query": {},
|
||||||
|
"boost": "5",
|
||||||
|
"random_score": {}, <1>
|
||||||
|
"boost_mode":"multiply"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
<1> See <<score-functions>> for a list of supported functions.
|
<1> See <<score-functions>> for a list of supported functions.
|
||||||
|
|
||||||
Furthermore, several functions can be combined. In this case one can
|
Furthermore, several functions can be combined. In this case one can
|
||||||
|
@ -29,30 +36,35 @@ given filtering query
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
"function_score": {
|
GET /_search
|
||||||
"query": {},
|
{
|
||||||
"boost": "boost for the whole query",
|
"query": {
|
||||||
"functions": [
|
"function_score": {
|
||||||
{
|
"query": {},
|
||||||
"filter": {},
|
"boost": "5", <1>
|
||||||
"FUNCTION": {}, <1>
|
"functions": [
|
||||||
"weight": number
|
{
|
||||||
},
|
"filter": {},
|
||||||
{
|
"random_score": {}, <2>
|
||||||
"FUNCTION": {} <1>
|
"weight": 23
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filter": {},
|
"filter": {},
|
||||||
"weight": number
|
"weight": 42
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"max_boost": 42,
|
||||||
|
"score_mode": "max",
|
||||||
|
"boost_mode": "multiply",
|
||||||
|
"min_score" : 42
|
||||||
}
|
}
|
||||||
],
|
}
|
||||||
"max_boost": number,
|
|
||||||
"score_mode": "(multiply|max|...)",
|
|
||||||
"boost_mode": "(multiply|replace|...)",
|
|
||||||
"min_score" : number
|
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
<1> See <<score-functions>> for a list of supported functions.
|
// CONSOLE
|
||||||
|
|
||||||
|
<1> Boost for the whole query.
|
||||||
|
<2> See <<score-functions>> for a list of supported functions.
|
||||||
|
|
||||||
NOTE: The scores produced by the filtering query of each function do not matter.
|
NOTE: The scores produced by the filtering query of each function do not matter.
|
||||||
|
|
||||||
|
@ -459,36 +471,36 @@ the request would look like this:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
GET _search
|
GET /_search
|
||||||
{
|
{
|
||||||
"query": {
|
"query": {
|
||||||
"function_score": {
|
"function_score": {
|
||||||
"functions": [
|
"functions": [
|
||||||
{
|
{
|
||||||
"gauss": {
|
"gauss": {
|
||||||
"price": {
|
"price": {
|
||||||
"origin": "0",
|
"origin": "0",
|
||||||
"scale": "20"
|
"scale": "20"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"gauss": {
|
||||||
|
"location": {
|
||||||
|
"origin": "11, 12",
|
||||||
|
"scale": "2km"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
],
|
||||||
},
|
"query": {
|
||||||
{
|
"match": {
|
||||||
"gauss": {
|
"properties": "balcony"
|
||||||
"location": {
|
|
||||||
"origin": "11, 12",
|
|
||||||
"scale": "2km"
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"score_mode": "multiply"
|
||||||
}
|
}
|
||||||
],
|
|
||||||
"query": {
|
|
||||||
"match": {
|
|
||||||
"properties": "balcony"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"score_mode": "multiply"
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
// CONSOLE
|
// CONSOLE
|
||||||
|
|
|
@ -16,27 +16,35 @@ Here is a simple example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"fuzzy" : { "user" : "ki" }
|
"query": {
|
||||||
|
"fuzzy" : { "user" : "ki" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
Or with more advanced settings:
|
Or with more advanced settings:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"fuzzy" : {
|
"query": {
|
||||||
"user" : {
|
"fuzzy" : {
|
||||||
"value" : "ki",
|
"user" : {
|
||||||
"boost" : 1.0,
|
"value" : "ki",
|
||||||
"fuzziness" : 2,
|
"boost" : 1.0,
|
||||||
"prefix_length" : 0,
|
"fuzziness" : 2,
|
||||||
"max_expansions": 100
|
"prefix_length" : 0,
|
||||||
|
"max_expansions": 100
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
===== Parameters
|
===== Parameters
|
||||||
|
@ -62,3 +70,4 @@ 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
|
`max_expansions` is set to a high number. It could result in every term in the
|
||||||
index being examined!
|
index being examined!
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,24 @@ bounding box. Assuming the following indexed document:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
PUT /my_locations
|
||||||
|
{
|
||||||
|
"mappings": {
|
||||||
|
"location": {
|
||||||
|
"properties": {
|
||||||
|
"pin": {
|
||||||
|
"properties": {
|
||||||
|
"location": {
|
||||||
|
"type": "geo_point"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PUT /my_locations/location/1
|
||||||
{
|
{
|
||||||
"pin" : {
|
"pin" : {
|
||||||
"location" : {
|
"location" : {
|
||||||
|
@ -15,27 +33,32 @@ bounding box. Assuming the following indexed document:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TESTSETUP
|
||||||
|
|
||||||
Then the following simple query can be executed with a
|
Then the following simple query can be executed with a
|
||||||
`geo_bounding_box` filter:
|
`geo_bounding_box` filter:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_bounding_box" : {
|
"filter" : {
|
||||||
"pin.location" : {
|
"geo_bounding_box" : {
|
||||||
"top_left" : {
|
"pin.location" : {
|
||||||
"lat" : 40.73,
|
"top_left" : {
|
||||||
"lon" : -74.1
|
"lat" : 40.73,
|
||||||
},
|
"lon" : -74.1
|
||||||
"bottom_right" : {
|
},
|
||||||
"lat" : 40.01,
|
"bottom_right" : {
|
||||||
"lon" : -71.12
|
"lat" : 40.01,
|
||||||
|
"lon" : -71.12
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +66,7 @@ Then the following simple query can be executed with a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
==== Query Options
|
==== Query Options
|
||||||
|
@ -75,21 +99,24 @@ representation of the geo point, the filter can accept it as well:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_bounding_box" : {
|
"filter" : {
|
||||||
"pin.location" : {
|
"geo_bounding_box" : {
|
||||||
"top_left" : {
|
"pin.location" : {
|
||||||
"lat" : 40.73,
|
"top_left" : {
|
||||||
"lon" : -74.1
|
"lat" : 40.73,
|
||||||
},
|
"lon" : -74.1
|
||||||
"bottom_right" : {
|
},
|
||||||
"lat" : 40.01,
|
"bottom_right" : {
|
||||||
"lon" : -71.12
|
"lat" : 40.01,
|
||||||
|
"lon" : -71.12
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,6 +124,7 @@ representation of the geo point, the filter can accept it as well:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
===== Lat Lon As Array
|
===== Lat Lon As Array
|
||||||
|
@ -106,22 +134,26 @@ conform with http://geojson.org/[GeoJSON].
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_bounding_box" : {
|
"filter" : {
|
||||||
"pin.location" : {
|
"geo_bounding_box" : {
|
||||||
"top_left" : [-74.1, 40.73],
|
"pin.location" : {
|
||||||
"bottom_right" : [-71.12, 40.01]
|
"top_left" : [-74.1, 40.73],
|
||||||
|
"bottom_right" : [-71.12, 40.01]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
===== Lat Lon As String
|
===== Lat Lon As String
|
||||||
|
@ -130,44 +162,52 @@ Format in `lat,lon`.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_bounding_box" : {
|
"filter" : {
|
||||||
"pin.location" : {
|
"geo_bounding_box" : {
|
||||||
"top_left" : "40.73, -74.1",
|
"pin.location" : {
|
||||||
"bottom_right" : "40.01, -71.12"
|
"top_left" : "40.73, -74.1",
|
||||||
|
"bottom_right" : "40.01, -71.12"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
===== Geohash
|
===== Geohash
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_bounding_box" : {
|
"filter" : {
|
||||||
"pin.location" : {
|
"geo_bounding_box" : {
|
||||||
"top_left" : "dr5r9ydj2y73",
|
"pin.location" : {
|
||||||
"bottom_right" : "drj7teegpus6"
|
"top_left" : "dr5r9ydj2y73",
|
||||||
|
"bottom_right" : "drj7teegpus6"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
==== Vertices
|
==== Vertices
|
||||||
|
@ -181,24 +221,28 @@ values separately.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_bounding_box" : {
|
"filter" : {
|
||||||
"pin.location" : {
|
"geo_bounding_box" : {
|
||||||
"top" : 40.73,
|
"pin.location" : {
|
||||||
"left" : -74.1,
|
"top" : 40.73,
|
||||||
"bottom" : 40.01,
|
"left" : -74.1,
|
||||||
"right" : -71.12
|
"bottom" : 40.01,
|
||||||
|
"right" : -71.12
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
|
@ -227,29 +271,33 @@ are not supported. Here is an example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_bounding_box" : {
|
"filter" : {
|
||||||
"pin.location" : {
|
"geo_bounding_box" : {
|
||||||
"top_left" : {
|
"pin.location" : {
|
||||||
"lat" : 40.73,
|
"top_left" : {
|
||||||
"lon" : -74.1
|
"lat" : 40.73,
|
||||||
|
"lon" : -74.1
|
||||||
|
},
|
||||||
|
"bottom_right" : {
|
||||||
|
"lat" : 40.10,
|
||||||
|
"lon" : -71.12
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"bottom_right" : {
|
"type" : "indexed"
|
||||||
"lat" : 40.10,
|
}
|
||||||
"lon" : -71.12
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"type" : "indexed"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
==== Ignore Unmapped
|
==== Ignore Unmapped
|
||||||
|
|
|
@ -2,10 +2,29 @@
|
||||||
=== Geo Distance Query
|
=== Geo Distance Query
|
||||||
|
|
||||||
Filters documents that include only hits that exists within a specific
|
Filters documents that include only hits that exists within a specific
|
||||||
distance from a geo point. Assuming the following indexed json:
|
distance from a geo point. Assuming the following mapping and indexed
|
||||||
|
document:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
PUT /my_locations
|
||||||
|
{
|
||||||
|
"mappings": {
|
||||||
|
"location": {
|
||||||
|
"properties": {
|
||||||
|
"pin": {
|
||||||
|
"properties": {
|
||||||
|
"location": {
|
||||||
|
"type": "geo_point"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PUT /my_locations/location/1
|
||||||
{
|
{
|
||||||
"pin" : {
|
"pin" : {
|
||||||
"location" : {
|
"location" : {
|
||||||
|
@ -15,29 +34,36 @@ distance from a geo point. Assuming the following indexed json:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TESTSETUP
|
||||||
|
|
||||||
|
|
||||||
Then the following simple query can be executed with a `geo_distance`
|
Then the following simple query can be executed with a `geo_distance`
|
||||||
filter:
|
filter:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /my_locations/location/_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_distance" : {
|
"filter" : {
|
||||||
"distance" : "200km",
|
"geo_distance" : {
|
||||||
"pin.location" : {
|
"distance" : "200km",
|
||||||
"lat" : 40,
|
"pin.location" : {
|
||||||
"lon" : -70
|
"lat" : 40,
|
||||||
|
"lon" : -70
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
==== Accepted Formats
|
==== Accepted Formats
|
||||||
|
@ -50,23 +76,27 @@ representation of the geo point, the filter can accept it as well:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /my_locations/location/_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_distance" : {
|
"filter" : {
|
||||||
"distance" : "12km",
|
"geo_distance" : {
|
||||||
"pin.location" : {
|
"distance" : "12km",
|
||||||
"lat" : 40,
|
"pin.location" : {
|
||||||
"lon" : -70
|
"lat" : 40,
|
||||||
|
"lon" : -70
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
===== Lat Lon As Array
|
===== Lat Lon As Array
|
||||||
|
@ -76,20 +106,25 @@ conform with http://geojson.org/[GeoJSON].
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /my_locations/location/_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_distance" : {
|
"filter" : {
|
||||||
"distance" : "12km",
|
"geo_distance" : {
|
||||||
"pin.location" : [-70, 40]
|
"distance" : "12km",
|
||||||
|
"pin.location" : [-70, 40]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
===== Lat Lon As String
|
===== Lat Lon As String
|
||||||
|
@ -98,40 +133,48 @@ Format in `lat,lon`.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /my_locations/location/_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_distance" : {
|
"filter" : {
|
||||||
"distance" : "12km",
|
"geo_distance" : {
|
||||||
"pin.location" : "40,-70"
|
"distance" : "12km",
|
||||||
|
"pin.location" : "40,-70"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
===== Geohash
|
===== Geohash
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /my_locations/location/_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_distance" : {
|
"filter" : {
|
||||||
"distance" : "12km",
|
"geo_distance" : {
|
||||||
"pin.location" : "drm3btev3e86"
|
"distance" : "12km",
|
||||||
|
"pin.location" : "drm3btev3e86"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
==== Options
|
==== Options
|
||||||
|
|
|
@ -5,24 +5,28 @@ Filters documents that exists within a range from a specific point:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_distance_range" : {
|
"filter" : {
|
||||||
"from" : "200km",
|
"geo_distance_range" : {
|
||||||
"to" : "400km",
|
"from" : "200km",
|
||||||
"pin.location" : {
|
"to" : "400km",
|
||||||
"lat" : 40,
|
"pin.location" : {
|
||||||
"lon" : -70
|
"lat" : 40,
|
||||||
|
"lon" : -70
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
Supports the same point location parameter and query options as the
|
Supports the same point location parameter and query options as the
|
||||||
<<query-dsl-geo-distance-query,geo_distance>>
|
<<query-dsl-geo-distance-query,geo_distance>>
|
||||||
|
|
|
@ -6,25 +6,29 @@ points. Here is an example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"query" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_polygon" : {
|
"filter" : {
|
||||||
"person.location" : {
|
"geo_polygon" : {
|
||||||
"points" : [
|
"person.location" : {
|
||||||
|
"points" : [
|
||||||
{"lat" : 40, "lon" : -70},
|
{"lat" : 40, "lon" : -70},
|
||||||
{"lat" : 30, "lon" : -80},
|
{"lat" : 30, "lon" : -80},
|
||||||
{"lat" : 20, "lon" : -90}
|
{"lat" : 20, "lon" : -90}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
==== Query Options
|
==== Query Options
|
||||||
|
@ -53,25 +57,29 @@ conform with http://geojson.org/[GeoJSON].
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_polygon" : {
|
"filter" : {
|
||||||
"person.location" : {
|
"geo_polygon" : {
|
||||||
"points" : [
|
"person.location" : {
|
||||||
[-70, 40],
|
"points" : [
|
||||||
|
[-70, 40],
|
||||||
[-80, 30],
|
[-80, 30],
|
||||||
[-90, 20]
|
[-90, 20]
|
||||||
]
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
===== Lat Lon as String
|
===== Lat Lon as String
|
||||||
|
@ -80,50 +88,58 @@ Format in `lat,lon`.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_polygon" : {
|
"filter" : {
|
||||||
"person.location" : {
|
"geo_polygon" : {
|
||||||
"points" : [
|
"person.location" : {
|
||||||
"40, -70",
|
"points" : [
|
||||||
"30, -80",
|
"40, -70",
|
||||||
"20, -90"
|
"30, -80",
|
||||||
]
|
"20, -90"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
===== Geohash
|
===== Geohash
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geo_polygon" : {
|
"filter" : {
|
||||||
"person.location" : {
|
"geo_polygon" : {
|
||||||
"points" : [
|
"person.location" : {
|
||||||
"drn5x1g8cu2y",
|
"points" : [
|
||||||
"30, -80",
|
"drn5x1g8cu2y",
|
||||||
"20, -90"
|
"30, -80",
|
||||||
]
|
"20, -90"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
==== geo_point Type
|
==== geo_point Type
|
||||||
|
|
|
@ -26,10 +26,10 @@ Given a document that looks like this:
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
{
|
{
|
||||||
"name": "Wind & Wetter, Berlin, Germany",
|
"name": "Wind & Wetter, Berlin, Germany",
|
||||||
"location": {
|
"location": {
|
||||||
"type": "Point",
|
"type": "Point",
|
||||||
"coordinates": [13.400544, 52.530286]
|
"coordinates": [13.400544, 52.530286]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ The following query will find the point using the Elasticsearch's
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"query":{
|
"query":{
|
||||||
"bool": {
|
"bool": {
|
||||||
|
@ -59,6 +60,7 @@ The following query will find the point using the Elasticsearch's
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
==== Pre-Indexed Shape
|
==== Pre-Indexed Shape
|
||||||
|
|
||||||
|
@ -81,26 +83,30 @@ shape:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool": {
|
"query": {
|
||||||
"must": {
|
"bool": {
|
||||||
"match_all": {}
|
"must": {
|
||||||
},
|
"match_all": {}
|
||||||
"filter": {
|
},
|
||||||
"geo_shape": {
|
"filter": {
|
||||||
"location": {
|
"geo_shape": {
|
||||||
"indexed_shape": {
|
"location": {
|
||||||
"id": "DEU",
|
"indexed_shape": {
|
||||||
"type": "countries",
|
"id": "DEU",
|
||||||
"index": "shapes",
|
"type": "countries",
|
||||||
"path": "location"
|
"index": "shapes",
|
||||||
|
"path": "location"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
==== Spatial Relations
|
==== Spatial Relations
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ setting the `geohash_prefix` option:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
PUT /my_index
|
||||||
{
|
{
|
||||||
"mappings" : {
|
"mappings" : {
|
||||||
"location": {
|
"location": {
|
||||||
|
@ -28,6 +29,8 @@ setting the `geohash_prefix` option:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TESTSETUP
|
||||||
|
|
||||||
The geohash cell can defined by all formats of `geo_points`. If such a cell is
|
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
|
defined by a latitude and longitude pair the size of the cell needs to be
|
||||||
|
@ -42,24 +45,28 @@ next to the given cell.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool" : {
|
"query": {
|
||||||
"must" : {
|
"bool" : {
|
||||||
"match_all" : {}
|
"must" : {
|
||||||
},
|
"match_all" : {}
|
||||||
"filter" : {
|
},
|
||||||
"geohash_cell": {
|
"filter" : {
|
||||||
"pin": {
|
"geohash_cell": {
|
||||||
"lat": 13.4080,
|
"pin": {
|
||||||
"lon": 52.5186
|
"lat": 13.4080,
|
||||||
},
|
"lon": 52.5186
|
||||||
"precision": 3,
|
},
|
||||||
"neighbors": true
|
"precision": 3,
|
||||||
|
"neighbors": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
==== Ignore Unmapped
|
==== Ignore Unmapped
|
||||||
|
|
|
@ -7,17 +7,21 @@ an example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"has_child" : {
|
"query": {
|
||||||
"type" : "blog_tag",
|
"has_child" : {
|
||||||
"query" : {
|
"type" : "blog_tag",
|
||||||
"term" : {
|
"query" : {
|
||||||
"tag" : "something"
|
"term" : {
|
||||||
}
|
"tag" : "something"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
==== Scoring capabilities
|
==== Scoring capabilities
|
||||||
|
@ -32,18 +36,22 @@ inside the `has_child` query:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"has_child" : {
|
"query": {
|
||||||
"type" : "blog_tag",
|
"has_child" : {
|
||||||
"score_mode" : "min",
|
"type" : "blog_tag",
|
||||||
"query" : {
|
"score_mode" : "min",
|
||||||
"term" : {
|
"query" : {
|
||||||
"tag" : "something"
|
"term" : {
|
||||||
}
|
"tag" : "something"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
==== Min/Max Children
|
==== Min/Max Children
|
||||||
|
@ -54,20 +62,24 @@ a match:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"has_child" : {
|
"query": {
|
||||||
"type" : "blog_tag",
|
"has_child" : {
|
||||||
"score_mode" : "min",
|
"type" : "blog_tag",
|
||||||
"min_children": 2, <1>
|
"score_mode" : "min",
|
||||||
"max_children": 10, <1>
|
"min_children": 2, <1>
|
||||||
"query" : {
|
"max_children": 10, <1>
|
||||||
"term" : {
|
"query" : {
|
||||||
"tag" : "something"
|
"term" : {
|
||||||
|
"tag" : "something"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
<1> Both `min_children` and `max_children` are optional.
|
<1> Both `min_children` and `max_children` are optional.
|
||||||
|
|
||||||
The `min_children` and `max_children` parameters can be combined with
|
The `min_children` and `max_children` parameters can be combined with
|
||||||
|
|
|
@ -9,17 +9,21 @@ in the same manner as the `has_child` query.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"has_parent" : {
|
"query": {
|
||||||
"parent_type" : "blog",
|
"has_parent" : {
|
||||||
"query" : {
|
"parent_type" : "blog",
|
||||||
"term" : {
|
"query" : {
|
||||||
"tag" : "something"
|
"term" : {
|
||||||
}
|
"tag" : "something"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
==== Scoring capabilities
|
==== Scoring capabilities
|
||||||
|
@ -34,18 +38,22 @@ matching parent document. The score mode can be specified with the
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"has_parent" : {
|
"query": {
|
||||||
"parent_type" : "blog",
|
"has_parent" : {
|
||||||
"score" : true,
|
"parent_type" : "blog",
|
||||||
"query" : {
|
"score" : true,
|
||||||
"term" : {
|
"query" : {
|
||||||
"tag" : "something"
|
"term" : {
|
||||||
}
|
"tag" : "something"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
==== Ignore Unmapped
|
==== Ignore Unmapped
|
||||||
|
|
|
@ -6,13 +6,17 @@ uses the <<mapping-uid-field,_uid>> field.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"ids" : {
|
"query": {
|
||||||
"type" : "my_type",
|
"ids" : {
|
||||||
"values" : ["1", "4", "100"]
|
"type" : "my_type",
|
||||||
|
"values" : ["1", "4", "100"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The `type` is optional and can be omitted, and can also accept an array
|
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.
|
of values. If no type is specified, all types defined in the index mapping are tried.
|
||||||
|
|
|
@ -9,18 +9,18 @@ on the list, the alternative `no_match_query` is executed.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"indices" : {
|
"query": {
|
||||||
"indices" : ["index1", "index2"],
|
"indices" : {
|
||||||
"query" : {
|
"indices" : ["index1", "index2"],
|
||||||
"term" : { "tag" : "wow" }
|
"query" : { "term" : { "tag" : "wow" } },
|
||||||
},
|
"no_match_query" : { "term" : { "tag" : "kow" } }
|
||||||
"no_match_query" : {
|
|
||||||
"term" : { "tag" : "kow" }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
You can use the `index` field to provide a single index.
|
You can use the `index` field to provide a single index.
|
||||||
|
|
||||||
|
|
|
@ -6,15 +6,27 @@ of `1.0`.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
{ "match_all": {} }
|
GET /_search
|
||||||
|
{
|
||||||
|
"query": {
|
||||||
|
"match_all": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The `_score` can be changed with the `boost` parameter:
|
The `_score` can be changed with the `boost` parameter:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
{ "match_all": { "boost" : 1.2 }}
|
GET /_search
|
||||||
|
{
|
||||||
|
"query": {
|
||||||
|
"match_all": { "boost" : 1.2 }
|
||||||
|
}
|
||||||
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[[query-dsl-match-none-query]]
|
[[query-dsl-match-none-query]]
|
||||||
[float]
|
[float]
|
||||||
|
@ -24,5 +36,11 @@ This is the inverse of the `match_all` query, which matches no documents.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
{ "match_none": {} }
|
GET /_search
|
||||||
|
{
|
||||||
|
"query": {
|
||||||
|
"match_none": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
|
@ -6,12 +6,16 @@ allows for prefix matches on the last term in the text. For example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"match_phrase_prefix" : {
|
"query": {
|
||||||
"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
|
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
|
accepts a `max_expansions` parameter (default `50`) that can control to how
|
||||||
|
@ -21,15 +25,19 @@ example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"match_phrase_prefix" : {
|
"query": {
|
||||||
"message" : {
|
"match_phrase_prefix" : {
|
||||||
"query" : "quick brown f",
|
"message" : {
|
||||||
"max_expansions" : 10
|
"query" : "quick brown f",
|
||||||
|
"max_expansions" : 10
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[IMPORTANT]
|
[IMPORTANT]
|
||||||
===================================================
|
===================================================
|
||||||
|
|
|
@ -6,12 +6,16 @@ out of the analyzed text. For example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"match_phrase" : {
|
"query": {
|
||||||
"message" : "this is a test"
|
"match_phrase" : {
|
||||||
|
"message" : "this is a test"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
A phrase query matches terms up to a configurable `slop`
|
A phrase query matches terms up to a configurable `slop`
|
||||||
(which defaults to 0) in any order. Transposed terms have a slop of 2.
|
(which defaults to 0) in any order. Transposed terms have a slop of 2.
|
||||||
|
@ -22,12 +26,16 @@ definition, or the default search analyzer, for example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"match_phrase" : {
|
"query": {
|
||||||
"message" : {
|
"match_phrase" : {
|
||||||
"query" : "this is a test",
|
"message" : {
|
||||||
"analyzer" : "my_analyzer"
|
"query" : "this is a test",
|
||||||
|
"analyzer" : "my_analyzer"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
|
@ -7,12 +7,16 @@ them, and constructs a query. For example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"match" : {
|
"query": {
|
||||||
"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
|
Note, `message` is the name of a field, you can substitute the name of
|
||||||
any field (including `_all`) instead.
|
any field (including `_all`) instead.
|
||||||
|
@ -57,15 +61,19 @@ change in structure, `message` is the field name):
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"match" : {
|
"query": {
|
||||||
"message" : {
|
"match" : {
|
||||||
"query" : "this is a test",
|
"message" : {
|
||||||
"operator" : "and"
|
"query" : "this is a test",
|
||||||
|
"operator" : "and"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[[query-dsl-match-query-zero]]
|
[[query-dsl-match-query-zero]]
|
||||||
===== Zero terms query
|
===== Zero terms query
|
||||||
|
@ -76,16 +84,20 @@ change that the `zero_terms_query` option can be used, which accepts
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"match" : {
|
"query": {
|
||||||
"message" : {
|
"match" : {
|
||||||
"query" : "to be or not to be",
|
"message" : {
|
||||||
"operator" : "and",
|
"query" : "to be or not to be",
|
||||||
"zero_terms_query": "all"
|
"operator" : "and",
|
||||||
|
"zero_terms_query": "all"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[[query-dsl-match-query-cutoff]]
|
[[query-dsl-match-query-cutoff]]
|
||||||
===== Cutoff frequency
|
===== Cutoff frequency
|
||||||
|
@ -113,16 +125,19 @@ Here is an example showing a query composed of stopwords exclusively:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"match" : {
|
"query": {
|
||||||
"message" : {
|
"match" : {
|
||||||
"query" : "to be or not to be",
|
"message" : {
|
||||||
"cutoff_frequency" : 0.001
|
"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
|
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
|
that when trying it out on test indexes with low document numbers you
|
||||||
|
|
|
@ -15,15 +15,19 @@ fields, limiting the number of selected terms to 12.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"more_like_this" : {
|
"query": {
|
||||||
"fields" : ["title", "description"],
|
"more_like_this" : {
|
||||||
"like" : "Once upon a time",
|
"fields" : ["title", "description"],
|
||||||
"min_term_freq" : 1,
|
"like" : "Once upon a time",
|
||||||
"max_query_terms" : 12
|
"min_term_freq" : 1,
|
||||||
|
"max_query_terms" : 12
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
A more complicated use case consists of mixing texts with documents already
|
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
|
existing in the index. In this case, the syntax to specify a document is
|
||||||
|
@ -31,27 +35,31 @@ similar to the one used in the <<docs-multi-get,Multi GET API>>.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"more_like_this" : {
|
"query": {
|
||||||
"fields" : ["title", "description"],
|
"more_like_this" : {
|
||||||
"like" : [
|
"fields" : ["title", "description"],
|
||||||
{
|
"like" : [
|
||||||
"_index" : "imdb",
|
{
|
||||||
"_type" : "movies",
|
"_index" : "imdb",
|
||||||
"_id" : "1"
|
"_type" : "movies",
|
||||||
},
|
"_id" : "1"
|
||||||
{
|
},
|
||||||
"_index" : "imdb",
|
{
|
||||||
"_type" : "movies",
|
"_index" : "imdb",
|
||||||
"_id" : "2"
|
"_type" : "movies",
|
||||||
},
|
"_id" : "2"
|
||||||
"and potentially some more text here as well"
|
},
|
||||||
],
|
"and potentially some more text here as well"
|
||||||
"min_term_freq" : 1,
|
],
|
||||||
"max_query_terms" : 12
|
"min_term_freq" : 1,
|
||||||
|
"max_query_terms" : 12
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
Finally, users can mix some texts, a chosen set of documents but also provide
|
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
|
documents not necessarily present in the index. To provide documents not
|
||||||
|
@ -59,32 +67,36 @@ present in the index, the syntax is similar to <<docs-termvectors-artificial-doc
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"more_like_this" : {
|
"query": {
|
||||||
"fields" : ["name.first", "name.last"],
|
"more_like_this" : {
|
||||||
"like" : [
|
"fields" : ["name.first", "name.last"],
|
||||||
{
|
"like" : [
|
||||||
"_index" : "marvel",
|
{
|
||||||
"_type" : "quotes",
|
"_index" : "marvel",
|
||||||
"doc" : {
|
"_type" : "quotes",
|
||||||
"name": {
|
"doc" : {
|
||||||
"first": "Ben",
|
"name": {
|
||||||
"last": "Grimm"
|
"first": "Ben",
|
||||||
},
|
"last": "Grimm"
|
||||||
"tweet": "You got no idea what I'd... what I'd give to be invisible."
|
},
|
||||||
}
|
"tweet": "You got no idea what I'd... what I'd give to be invisible."
|
||||||
},
|
}
|
||||||
{
|
},
|
||||||
"_index" : "marvel",
|
{
|
||||||
"_type" : "quotes",
|
"_index" : "marvel",
|
||||||
"_id" : "2"
|
"_type" : "quotes",
|
||||||
|
"_id" : "2"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"min_term_freq" : 1,
|
||||||
|
"max_query_terms" : 12
|
||||||
}
|
}
|
||||||
],
|
|
||||||
"min_term_freq" : 1,
|
|
||||||
"max_query_terms" : 12
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
==== How it Works
|
==== How it Works
|
||||||
|
|
||||||
|
@ -111,32 +123,34 @@ default, but there will be no speed up on analysis for these fields.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -s -XPUT 'http://localhost:9200/imdb/' -d '{
|
PUT /imdb
|
||||||
"mappings": {
|
{
|
||||||
"movies": {
|
"mappings": {
|
||||||
"properties": {
|
"movies": {
|
||||||
"title": {
|
"properties": {
|
||||||
"type": "text",
|
"title": {
|
||||||
"term_vector": "yes"
|
"type": "text",
|
||||||
},
|
"term_vector": "yes"
|
||||||
"description": {
|
},
|
||||||
"type": "text"
|
"description": {
|
||||||
},
|
"type": "text"
|
||||||
"tags": {
|
},
|
||||||
"type": "text",
|
"tags": {
|
||||||
"fields" : {
|
"type": "text",
|
||||||
"raw": {
|
"fields" : {
|
||||||
"type" : "text",
|
"raw": {
|
||||||
"analyzer": "keyword",
|
"type" : "text",
|
||||||
"term_vector" : "yes"
|
"analyzer": "keyword",
|
||||||
|
"term_vector" : "yes"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
==== Parameters
|
==== Parameters
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,17 @@ to allow multi-field queries:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"multi_match" : {
|
"query": {
|
||||||
"query": "this is a test", <1>
|
"multi_match" : {
|
||||||
"fields": [ "subject", "message" ] <2>
|
"query": "this is a test", <1>
|
||||||
|
"fields": [ "subject", "message" ] <2>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
<1> The query string.
|
<1> The query string.
|
||||||
<2> The fields to be queried.
|
<2> The fields to be queried.
|
||||||
|
|
||||||
|
@ -23,26 +27,35 @@ Fields can be specified with wildcards, eg:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"multi_match" : {
|
"query": {
|
||||||
"query": "Will Smith",
|
"multi_match" : {
|
||||||
"fields": [ "title", "*_name" ] <1>
|
"query": "Will Smith",
|
||||||
|
"fields": [ "title", "*_name" ] <1>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
<1> Query the `title`, `first_name` and `last_name` fields.
|
<1> Query the `title`, `first_name` and `last_name` fields.
|
||||||
|
|
||||||
Individual fields can be boosted with the caret (`^`) notation:
|
Individual fields can be boosted with the caret (`^`) notation:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"multi_match" : {
|
"query": {
|
||||||
"query" : "this is a test",
|
"multi_match" : {
|
||||||
"fields" : [ "subject^3", "message" ] <1>
|
"query" : "this is a test",
|
||||||
|
"fields" : [ "subject^3", "message" ] <1>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
<1> The `subject` field is three times as important as the `message` field.
|
<1> The `subject` field is three times as important as the `message` field.
|
||||||
|
|
||||||
[[multi-match-types]]
|
[[multi-match-types]]
|
||||||
|
@ -82,30 +95,38 @@ find the single best matching field. For instance, this query:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"multi_match" : {
|
"query": {
|
||||||
"query": "brown fox",
|
"multi_match" : {
|
||||||
"type": "best_fields",
|
"query": "brown fox",
|
||||||
"fields": [ "subject", "message" ],
|
"type": "best_fields",
|
||||||
"tie_breaker": 0.3
|
"fields": [ "subject", "message" ],
|
||||||
|
"tie_breaker": 0.3
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
would be executed as:
|
would be executed as:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"dis_max": {
|
"query": {
|
||||||
"queries": [
|
"dis_max": {
|
||||||
{ "match": { "subject": "brown fox" }},
|
"queries": [
|
||||||
{ "match": { "message": "brown fox" }}
|
{ "match": { "subject": "brown fox" }},
|
||||||
],
|
{ "match": { "message": "brown fox" }}
|
||||||
"tie_breaker": 0.3
|
],
|
||||||
|
"tie_breaker": 0.3
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
Normally the `best_fields` type uses the score of the *single* best matching
|
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
|
field, but if `tie_breaker` is specified, then it calculates the score as
|
||||||
|
@ -132,15 +153,20 @@ Take this query for example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"multi_match" : {
|
"query": {
|
||||||
"query": "Will Smith",
|
"multi_match" : {
|
||||||
"type": "best_fields",
|
"query": "Will Smith",
|
||||||
"fields": [ "first_name", "last_name" ],
|
"type": "best_fields",
|
||||||
"operator": "and" <1>
|
"fields": [ "first_name", "last_name" ],
|
||||||
|
"operator": "and" <1>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
<1> All terms must be present.
|
<1> All terms must be present.
|
||||||
|
|
||||||
This query is executed as:
|
This query is executed as:
|
||||||
|
@ -170,29 +196,37 @@ This query:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"multi_match" : {
|
"query": {
|
||||||
"query": "quick brown fox",
|
"multi_match" : {
|
||||||
"type": "most_fields",
|
"query": "quick brown fox",
|
||||||
"fields": [ "title", "title.original", "title.shingles" ]
|
"type": "most_fields",
|
||||||
|
"fields": [ "title", "title.original", "title.shingles" ]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
would be executed as:
|
would be executed as:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"bool": {
|
"query": {
|
||||||
"should": [
|
"bool": {
|
||||||
{ "match": { "title": "quick brown fox" }},
|
"should": [
|
||||||
{ "match": { "title.original": "quick brown fox" }},
|
{ "match": { "title": "quick brown fox" }},
|
||||||
{ "match": { "title.shingles": "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
|
The score from each `match` clause is added together, then divided by the
|
||||||
number of `match` clauses.
|
number of `match` clauses.
|
||||||
|
@ -212,28 +246,36 @@ but they use a `match_phrase` or `match_phrase_prefix` query instead of a
|
||||||
This query:
|
This query:
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"multi_match" : {
|
"query": {
|
||||||
"query": "quick brown f",
|
"multi_match" : {
|
||||||
"type": "phrase_prefix",
|
"query": "quick brown f",
|
||||||
"fields": [ "subject", "message" ]
|
"type": "phrase_prefix",
|
||||||
|
"fields": [ "subject", "message" ]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
would be executed as:
|
would be executed as:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"dis_max": {
|
"query": {
|
||||||
"queries": [
|
"dis_max": {
|
||||||
{ "match_phrase_prefix": { "subject": "quick brown f" }},
|
"queries": [
|
||||||
{ "match_phrase_prefix": { "message": "quick brown f" }}
|
{ "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
|
Also, accepts `analyzer`, `boost`, `slop` and `zero_terms_query` as explained
|
||||||
in <<query-dsl-match-query>>. Type `phrase_prefix` additionally accepts
|
in <<query-dsl-match-query>>. Type `phrase_prefix` additionally accepts
|
||||||
|
@ -288,15 +330,19 @@ A query like:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"multi_match" : {
|
"query": {
|
||||||
"query": "Will Smith",
|
"multi_match" : {
|
||||||
"type": "cross_fields",
|
"query": "Will Smith",
|
||||||
"fields": [ "first_name", "last_name" ],
|
"type": "cross_fields",
|
||||||
"operator": "and"
|
"fields": [ "first_name", "last_name" ],
|
||||||
|
"operator": "and"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
is executed as:
|
is executed as:
|
||||||
|
|
||||||
|
@ -344,17 +390,21 @@ both use an `edge_ngram` analyzer, this query:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"multi_match" : {
|
"query": {
|
||||||
"query": "Jon",
|
"multi_match" : {
|
||||||
"type": "cross_fields",
|
"query": "Jon",
|
||||||
"fields": [
|
"type": "cross_fields",
|
||||||
|
"fields": [
|
||||||
"first", "first.edge",
|
"first", "first.edge",
|
||||||
"last", "last.edge"
|
"last", "last.edge"
|
||||||
]
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
would be executed as:
|
would be executed as:
|
||||||
|
|
||||||
|
@ -379,28 +429,33 @@ parameter to just one of them:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
|
"query": {
|
||||||
"bool": {
|
"bool": {
|
||||||
"should": [
|
"should": [
|
||||||
{
|
{
|
||||||
"multi_match" : {
|
"multi_match" : {
|
||||||
"query": "Will Smith",
|
"query": "Will Smith",
|
||||||
"type": "cross_fields",
|
"type": "cross_fields",
|
||||||
"fields": [ "first", "last" ],
|
"fields": [ "first", "last" ],
|
||||||
"minimum_should_match": "50%" <1>
|
"minimum_should_match": "50%" <1>
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"multi_match" : {
|
"multi_match" : {
|
||||||
"query": "Will Smith",
|
"query": "Will Smith",
|
||||||
"type": "cross_fields",
|
"type": "cross_fields",
|
||||||
"fields": [ "*.edge" ]
|
"fields": [ "*.edge" ]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
<1> Either `will` or `smith` must be present in either of the `first`
|
<1> Either `will` or `smith` must be present in either of the `first`
|
||||||
or `last` fields
|
or `last` fields
|
||||||
|
|
||||||
|
@ -409,15 +464,20 @@ parameter in the query.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"multi_match" : {
|
"query": {
|
||||||
"query": "Jon",
|
"multi_match" : {
|
||||||
"type": "cross_fields",
|
"query": "Jon",
|
||||||
"analyzer": "standard", <1>
|
"type": "cross_fields",
|
||||||
"fields": [ "first", "last", "*.edge" ]
|
"analyzer": "standard", <1>
|
||||||
|
"fields": [ "first", "last", "*.edge" ]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
<1> Use the `standard` analyzer for all fields.
|
<1> Use the `standard` analyzer for all fields.
|
||||||
|
|
||||||
which will be executed as:
|
which will be executed as:
|
||||||
|
|
|
@ -10,40 +10,45 @@ will work with:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
PUT /my_index
|
||||||
{
|
{
|
||||||
"type1" : {
|
"mappings": {
|
||||||
"properties" : {
|
"type1" : {
|
||||||
"obj1" : {
|
"properties" : {
|
||||||
"type" : "nested"
|
"obj1" : {
|
||||||
|
"type" : "nested"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TESTSETUP
|
||||||
|
|
||||||
And here is a sample nested query usage:
|
And here is a sample nested query usage:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"nested" : {
|
"query": {
|
||||||
"path" : "obj1",
|
"nested" : {
|
||||||
"score_mode" : "avg",
|
"path" : "obj1",
|
||||||
"query" : {
|
"score_mode" : "avg",
|
||||||
"bool" : {
|
"query" : {
|
||||||
"must" : [
|
"bool" : {
|
||||||
{
|
"must" : [
|
||||||
"match" : {"obj1.name" : "blue"}
|
{ "match" : {"obj1.name" : "blue"} },
|
||||||
},
|
{ "range" : {"obj1.count" : {"gt" : 5}} }
|
||||||
{
|
]
|
||||||
"range" : {"obj1.count" : {"gt" : 5}}
|
}
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The query `path` points to the nested object path, and the `query`
|
The query `path` points to the nested object path, and the `query`
|
||||||
includes the query that will run on the nested docs matching the
|
includes the query that will run on the nested docs matching the
|
||||||
|
|
|
@ -54,17 +54,21 @@ better as it does not need to do a join:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /my_index/_search
|
||||||
{
|
{
|
||||||
"has_parent": {
|
"query": {
|
||||||
"type": "blog",
|
"has_parent": {
|
||||||
"query": {
|
"type": "blog_post",
|
||||||
"term": {
|
"query": {
|
||||||
"_id": "1"
|
"term": {
|
||||||
|
"_id": "1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
==== Parameters
|
==== Parameters
|
||||||
|
|
||||||
|
|
|
@ -13,26 +13,27 @@ Create an index with two mappings:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XPUT "http://localhost:9200/my-index" -d'
|
PUT /my-index
|
||||||
{
|
{
|
||||||
"mappings": {
|
"mappings": {
|
||||||
"doctype": {
|
"doctype": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"queries": {
|
||||||
|
"properties": {
|
||||||
|
"query": {
|
||||||
|
"type": "percolator"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
"queries": {
|
|
||||||
"properties": {
|
|
||||||
"query": {
|
|
||||||
"type": "percolator"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}'
|
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The `doctype` mapping is the mapping used to preprocess
|
The `doctype` mapping is the mapping used to preprocess
|
||||||
the document defined in the `percolator` query before it
|
the document defined in the `percolator` query before it
|
||||||
|
@ -50,20 +51,24 @@ Register a query in the percolator:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XPUT 'localhost:9200/my-index/queries/1' -d '{
|
PUT /my-index/queries/1
|
||||||
|
{
|
||||||
"query" : {
|
"query" : {
|
||||||
"match" : {
|
"match" : {
|
||||||
"message" : "bonsai tree"
|
"message" : "bonsai tree"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}'
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[continued]
|
||||||
|
|
||||||
Match a document to the registered percolator queries:
|
Match a document to the registered percolator queries:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XGET 'localhost:9200/my-index/_search' -d '{
|
GET /my-index/_search
|
||||||
|
{
|
||||||
"query" : {
|
"query" : {
|
||||||
"percolate" : {
|
"percolate" : {
|
||||||
"field" : "query",
|
"field" : "query",
|
||||||
|
@ -73,8 +78,10 @@ curl -XGET 'localhost:9200/my-index/_search' -d '{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}'
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[continued]
|
||||||
|
|
||||||
The above request will yield the following response:
|
The above request will yield the following response:
|
||||||
|
|
||||||
|
@ -151,12 +158,13 @@ Index the document we want to percolate:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XPUT "http://localhost:9200/my-index/message/1" -d'
|
PUT /my-index/message/1
|
||||||
{
|
{
|
||||||
"message" : "A new bonsai tree in the office"
|
"message" : "A new bonsai tree in the office"
|
||||||
}'
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[continued]
|
||||||
Index response:
|
Index response:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
|
@ -179,7 +187,7 @@ Percolating an existing document, using the index response as basis to build to
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XGET "http://localhost:9200/my-index/_search" -d'
|
GET /my-index/_search
|
||||||
{
|
{
|
||||||
"query" : {
|
"query" : {
|
||||||
"percolate" : {
|
"percolate" : {
|
||||||
|
@ -191,8 +199,10 @@ curl -XGET "http://localhost:9200/my-index/_search" -d'
|
||||||
"version" : 1 <1>
|
"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
|
<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
|
the document we just have indexed. A change may be made after we have indexed, and if that is the
|
||||||
|
@ -216,35 +226,39 @@ Save a query:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XPUT "http://localhost:9200/my-index/queries/1" -d'
|
PUT /my-index/queries/1
|
||||||
{
|
{
|
||||||
"query" : {
|
"query" : {
|
||||||
"match" : {
|
"match" : {
|
||||||
"message" : "brown fox"
|
"message" : "brown fox"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}'
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[continued]
|
||||||
|
|
||||||
Save another query:
|
Save another query:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XPUT "http://localhost:9200/my-index/queries/2" -d'
|
PUT /my-index/queries/2
|
||||||
{
|
{
|
||||||
"query" : {
|
"query" : {
|
||||||
"match" : {
|
"match" : {
|
||||||
"message" : "lazy dog"
|
"message" : "lazy dog"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}'
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[continued]
|
||||||
|
|
||||||
Execute a search request with the `percolate` query and highlighting enabled:
|
Execute a search request with the `percolate` query and highlighting enabled:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
curl -XGET "http://localhost:9200/my-index/_search" -d'
|
GET /my-index/_search
|
||||||
{
|
{
|
||||||
"query" : {
|
"query" : {
|
||||||
"percolate" : {
|
"percolate" : {
|
||||||
|
@ -260,8 +274,10 @@ curl -XGET "http://localhost:9200/my-index/_search" -d'
|
||||||
"message": {}
|
"message": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}'
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[continued]
|
||||||
|
|
||||||
This will yield the following response.
|
This will yield the following response.
|
||||||
|
|
||||||
|
@ -344,16 +360,19 @@ can't do the selecting optimization (for example if an unsupported query is defi
|
||||||
or the unsupported query is the only query in the percolator document). These queries are marked by the percolator and
|
or the unsupported query is the only query in the percolator document). These queries are marked by the percolator and
|
||||||
can be found by running the following search:
|
can be found by running the following search:
|
||||||
|
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
---------------------------------------------------
|
||||||
curl -XGET "http://localhost:9200/_search" -d'
|
GET /_search
|
||||||
{
|
{
|
||||||
"query": {
|
"query": {
|
||||||
"term" : {
|
"term" : {
|
||||||
"query.unknown_query" : ""
|
"query.unknown_query" : ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}'
|
}
|
||||||
--------------------------------------------------
|
---------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
NOTE: The above example assumes that there is a `query` field of type `percolator` in the mappings.
|
NOTE: The above example assumes that there is a `query` field of type
|
||||||
|
`percolator` in the mappings.
|
||||||
|
|
|
@ -8,28 +8,37 @@ that starts with `ki`:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
{
|
GET /_search
|
||||||
|
{ "query": {
|
||||||
"prefix" : { "user" : "ki" }
|
"prefix" : { "user" : "ki" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
A boost can also be associated with the query:
|
A boost can also be associated with the query:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
{
|
GET /_search
|
||||||
|
{ "query": {
|
||||||
"prefix" : { "user" : { "value" : "ki", "boost" : 2.0 } }
|
"prefix" : { "user" : { "value" : "ki", "boost" : 2.0 } }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
Or :
|
Or :
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
{
|
GET /_search
|
||||||
|
{ "query": {
|
||||||
"prefix" : { "user" : { "prefix" : "ki", "boost" : 2.0 } }
|
"prefix" : { "user" : { "prefix" : "ki", "boost" : 2.0 } }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
This multi term query allows you to control how it gets rewritten using the
|
This multi term query allows you to control how it gets rewritten using the
|
||||||
<<query-dsl-multi-term-rewrite,rewrite>>
|
<<query-dsl-multi-term-rewrite,rewrite>>
|
||||||
|
|
|
@ -6,13 +6,17 @@ an example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"query_string" : {
|
"query": {
|
||||||
"default_field" : "content",
|
"query_string" : {
|
||||||
"query" : "this AND that OR thus"
|
"default_field" : "content",
|
||||||
|
"query" : "this AND that OR thus"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The `query_string` top level parameters include:
|
The `query_string` top level parameters include:
|
||||||
|
|
||||||
|
@ -113,25 +117,33 @@ For example, the following query
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"query_string" : {
|
"query": {
|
||||||
"fields" : ["content", "name"],
|
"query_string" : {
|
||||||
"query" : "this AND that"
|
"fields" : ["content", "name"],
|
||||||
|
"query" : "this AND that"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
matches the same words as
|
matches the same words as
|
||||||
|
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"query_string": {
|
"query": {
|
||||||
"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,
|
Since several queries are generated from the individual search terms,
|
||||||
combining them can be automatically done using either a `dis_max` query or a
|
combining them can be automatically done using either a `dis_max` query or a
|
||||||
|
@ -140,14 +152,18 @@ notation):
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"query_string" : {
|
"query": {
|
||||||
"fields" : ["content", "name^5"],
|
"query_string" : {
|
||||||
"query" : "this AND that OR thus",
|
"fields" : ["content", "name^5"],
|
||||||
"use_dis_max" : true
|
"query" : "this AND that OR thus",
|
||||||
|
"use_dis_max" : true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
Simple wildcard can also be used to search "within" specific inner
|
Simple wildcard can also be used to search "within" specific inner
|
||||||
elements of the document. For example, if we have a `city` object with
|
elements of the document. For example, if we have a `city` object with
|
||||||
|
@ -156,14 +172,18 @@ search on all "city" fields:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"query_string" : {
|
"query": {
|
||||||
"fields" : ["city.*"],
|
"query_string" : {
|
||||||
"query" : "this AND that OR thus",
|
"fields" : ["city.*"],
|
||||||
"use_dis_max" : true
|
"query" : "this AND that OR thus",
|
||||||
|
"use_dis_max" : true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
Another option is to provide the wildcard fields search in the query
|
Another option is to provide the wildcard fields search in the query
|
||||||
string itself (properly escaping the `*` sign), for example:
|
string itself (properly escaping the `*` sign), for example:
|
||||||
|
@ -188,13 +208,17 @@ introduced fields included). For example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"query_string" : {
|
"query": {
|
||||||
"fields" : ["content", "name.*^5"],
|
"query_string" : {
|
||||||
"query" : "this AND that OR thus",
|
"fields" : ["content", "name.*^5"],
|
||||||
"use_dis_max" : true
|
"query" : "this AND that OR thus",
|
||||||
|
"use_dis_max" : true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
include::query-string-syntax.asciidoc[]
|
include::query-string-syntax.asciidoc[]
|
||||||
|
|
|
@ -47,7 +47,7 @@ conditions are met:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
------------------------------------
|
------------------------------------
|
||||||
GET _search
|
GET /_search
|
||||||
{
|
{
|
||||||
"query": { <1>
|
"query": { <1>
|
||||||
"bool": { <2>
|
"bool": { <2>
|
||||||
|
@ -63,6 +63,7 @@ GET _search
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
------------------------------------
|
------------------------------------
|
||||||
|
// CONSOLE
|
||||||
<1> The `query` parameter indicates query context.
|
<1> The `query` parameter indicates query context.
|
||||||
<2> The `bool` and two `match` clauses are used in 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
|
which means that they are used to score how well each document
|
||||||
|
|
|
@ -9,16 +9,20 @@ a `NumericRangeQuery`. The following example returns all documents where
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET _search
|
||||||
{
|
{
|
||||||
"range" : {
|
"query": {
|
||||||
"age" : {
|
"range" : {
|
||||||
"gte" : 10,
|
"age" : {
|
||||||
"lte" : 20,
|
"gte" : 10,
|
||||||
"boost" : 2.0
|
"lte" : 20,
|
||||||
|
"boost" : 2.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The `range` query accepts the following parameters:
|
The `range` query accepts the following parameters:
|
||||||
|
|
||||||
|
@ -38,15 +42,19 @@ specified using <<date-math>>:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET _search
|
||||||
{
|
{
|
||||||
"range" : {
|
"query": {
|
||||||
"date" : {
|
"range" : {
|
||||||
"gte" : "now-1d/d",
|
"date" : {
|
||||||
"lt" : "now/d"
|
"gte" : "now-1d/d",
|
||||||
|
"lt" : "now/d"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
===== Date math and rounding
|
===== Date math and rounding
|
||||||
|
|
||||||
|
@ -86,16 +94,20 @@ passing the `format` parameter to the `range` query:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET _search
|
||||||
{
|
{
|
||||||
"range" : {
|
"query": {
|
||||||
"born" : {
|
"range" : {
|
||||||
"gte": "01/01/2012",
|
"born" : {
|
||||||
"lte": "2013",
|
"gte": "01/01/2012",
|
||||||
"format": "dd/MM/yyyy||yyyy"
|
"lte": "2013",
|
||||||
|
"format": "dd/MM/yyyy||yyyy"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
===== Time zone in range queries
|
===== Time zone in range queries
|
||||||
|
|
||||||
|
@ -105,15 +117,19 @@ accepts it), or it can be specified as the `time_zone` parameter:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET _search
|
||||||
{
|
{
|
||||||
"range" : {
|
"query": {
|
||||||
"timestamp" : {
|
"range" : {
|
||||||
"gte": "2015-01-01 00:00:00", <1>
|
"timestamp" : {
|
||||||
"lte": "now", <2>
|
"gte": "2015-01-01 00:00:00", <1>
|
||||||
"time_zone": "+01:00"
|
"lte": "now", <2>
|
||||||
|
"time_zone": "+01:00"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
<1> This date will be converted to `2014-12-31T23:00:00 UTC`.
|
<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).
|
<2> `now` is not affected by the `time_zone` parameter (dates must be stored as UTC).
|
||||||
|
|
|
@ -15,40 +15,52 @@ matchers like `.*?+` will mostly lower performance.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"regexp":{
|
"query": {
|
||||||
"name.first": "s.*y"
|
"regexp":{
|
||||||
|
"name.first": "s.*y"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
Boosting is also supported
|
Boosting is also supported
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"regexp":{
|
"query": {
|
||||||
"name.first":{
|
"regexp":{
|
||||||
"value":"s.*y",
|
"name.first":{
|
||||||
"boost":1.2
|
"value":"s.*y",
|
||||||
|
"boost":1.2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
You can also use special flags
|
You can also use special flags
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"regexp":{
|
"query": {
|
||||||
"name.first": {
|
"regexp":{
|
||||||
"value": "s.*y",
|
"name.first": {
|
||||||
"flags" : "INTERSECTION|COMPLEMENT|EMPTY"
|
"value": "s.*y",
|
||||||
|
"flags" : "INTERSECTION|COMPLEMENT|EMPTY"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
Possible flags are `ALL` (default), `ANYSTRING`, `COMPLEMENT`,
|
Possible flags are `ALL` (default), `ANYSTRING`, `COMPLEMENT`,
|
||||||
`EMPTY`, `INTERSECTION`, `INTERVAL`, or `NONE`. Please check the
|
`EMPTY`, `INTERSECTION`, `INTERVAL`, or `NONE`. Please check the
|
||||||
|
@ -64,16 +76,19 @@ this limit to allow more complex regular expressions to execute.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"regexp":{
|
"query": {
|
||||||
"name.first": {
|
"regexp":{
|
||||||
"value": "s.*y",
|
"name.first": {
|
||||||
"flags" : "INTERSECTION|COMPLEMENT|EMPTY",
|
"value": "s.*y",
|
||||||
"max_determinized_states": 20000
|
"flags" : "INTERSECTION|COMPLEMENT|EMPTY",
|
||||||
|
"max_determinized_states": 20000
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
include::regexp-syntax.asciidoc[]
|
include::regexp-syntax.asciidoc[]
|
||||||
|
|
|
@ -7,17 +7,20 @@ context, for example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
"bool" : {
|
GET /_search
|
||||||
"must" : {
|
{
|
||||||
...
|
"query": {
|
||||||
},
|
"bool" : {
|
||||||
"filter" : {
|
"must" : {
|
||||||
"script" : {
|
"script" : {
|
||||||
"script" : "doc['num1'].value > 1"
|
"script" : "doc['num1'].value > 1"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
==== Custom Parameters
|
==== Custom Parameters
|
||||||
|
@ -28,20 +31,23 @@ to use the ability to pass parameters to the script itself, for example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
"bool" : {
|
GET /_search
|
||||||
"must" : {
|
{
|
||||||
...
|
"query": {
|
||||||
},
|
"bool" : {
|
||||||
"filter" : {
|
"must" : {
|
||||||
"script" : {
|
"script" : {
|
||||||
"script" : {
|
"script" : {
|
||||||
"inline" : "doc['num1'].value > param1"
|
"inline" : "doc['num1'].value > param1",
|
||||||
"params" : {
|
"params" : {
|
||||||
"param1" : 5
|
"param1" : 5
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
|
|
|
@ -8,15 +8,19 @@ an example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
|
"query": {
|
||||||
"simple_query_string" : {
|
"simple_query_string" : {
|
||||||
"query": "\"fried eggs\" +(eggplant | potato) -frittata",
|
"query": "\"fried eggs\" +(eggplant | potato) -frittata",
|
||||||
"analyzer": "snowball",
|
"analyzer": "snowball",
|
||||||
"fields": ["body^5","_all"],
|
"fields": ["body^5","_all"],
|
||||||
"default_operator": "and"
|
"default_operator": "and"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The `simple_query_string` top level parameters include:
|
The `simple_query_string` top level parameters include:
|
||||||
|
|
||||||
|
@ -94,13 +98,17 @@ introduced fields included). For example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"simple_query_string" : {
|
"query": {
|
||||||
"fields" : ["content", "name.*^5"],
|
"simple_query_string" : {
|
||||||
"query" : "foo bar baz"
|
"fields" : ["content", "name.*^5"],
|
||||||
|
"query" : "foo bar baz"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
==== Flags
|
==== Flags
|
||||||
|
@ -110,13 +118,17 @@ should be enabled. It is specified as a `|`-delimited string with the
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"simple_query_string" : {
|
"query": {
|
||||||
"query" : "foo | bar + baz*",
|
"simple_query_string" : {
|
||||||
"flags" : "OR|AND|PREFIX"
|
"query" : "foo | bar + baz*",
|
||||||
|
"flags" : "OR|AND|PREFIX"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The available flags are: `ALL`, `NONE`, `AND`, `OR`, `NOT`, `PREFIX`, `PHRASE`,
|
The available flags are: `ALL`, `NONE`, `AND`, `OR`, `NOT`, `PREFIX`, `PHRASE`,
|
||||||
`PRECEDENCE`, `ESCAPE`, `WHITESPACE`, `FUZZY`, `NEAR`, and `SLOP`.
|
`PRECEDENCE`, `ESCAPE`, `WHITESPACE`, `FUZZY`, `NEAR`, and `SLOP`.
|
||||||
|
|
|
@ -6,24 +6,28 @@ query maps to Lucene `SpanContainingQuery`. Here is an example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"span_containing" : {
|
"query": {
|
||||||
"little" : {
|
"span_containing" : {
|
||||||
"span_term" : { "field1" : "foo" }
|
"little" : {
|
||||||
},
|
"span_term" : { "field1" : "foo" }
|
||||||
"big" : {
|
},
|
||||||
"span_near" : {
|
"big" : {
|
||||||
"clauses" : [
|
"span_near" : {
|
||||||
{ "span_term" : { "field1" : "bar" } },
|
"clauses" : [
|
||||||
{ "span_term" : { "field1" : "baz" } }
|
{ "span_term" : { "field1" : "bar" } },
|
||||||
],
|
{ "span_term" : { "field1" : "baz" } }
|
||||||
"slop" : 5,
|
],
|
||||||
"in_order" : true
|
"slop" : 5,
|
||||||
|
"in_order" : true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The `big` and `little` clauses can be any span type query. Matching
|
The `big` and `little` clauses can be any span type query. Matching
|
||||||
spans from `big` that contain matches from `little` are returned.
|
spans from `big` that contain matches from `little` are returned.
|
||||||
|
|
|
@ -6,15 +6,19 @@ to Lucene `SpanFirstQuery`. Here is an example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"span_first" : {
|
"query": {
|
||||||
"match" : {
|
"span_first" : {
|
||||||
"span_term" : { "user" : "kimchy" }
|
"match" : {
|
||||||
},
|
"span_term" : { "user" : "kimchy" }
|
||||||
"end" : 3
|
},
|
||||||
|
"end" : 3
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The `match` clause can be any other span type query. The `end` controls
|
The `match` clause can be any other span type query. The `end` controls
|
||||||
the maximum end position permitted in a match.
|
the maximum end position permitted in a match.
|
||||||
|
|
|
@ -7,24 +7,32 @@ it can be nested. Example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"span_multi":{
|
"query": {
|
||||||
"match":{
|
"span_multi":{
|
||||||
"prefix" : { "user" : { "value" : "ki" } }
|
"match":{
|
||||||
|
"prefix" : { "user" : { "value" : "ki" } }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
A boost can also be associated with the query:
|
A boost can also be associated with the query:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"span_multi":{
|
"query": {
|
||||||
"match":{
|
"span_multi":{
|
||||||
"prefix" : { "user" : { "value" : "ki", "boost" : 1.08 } }
|
"match":{
|
||||||
|
"prefix" : { "user" : { "value" : "ki", "boost" : 1.08 } }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
|
@ -8,18 +8,22 @@ matches are required to be in-order. The span near query maps to Lucene
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"span_near" : {
|
"query": {
|
||||||
"clauses" : [
|
"span_near" : {
|
||||||
{ "span_term" : { "field" : "value1" } },
|
"clauses" : [
|
||||||
{ "span_term" : { "field" : "value2" } },
|
{ "span_term" : { "field" : "value1" } },
|
||||||
{ "span_term" : { "field" : "value3" } }
|
{ "span_term" : { "field" : "value2" } },
|
||||||
],
|
{ "span_term" : { "field" : "value3" } }
|
||||||
"slop" : 12,
|
],
|
||||||
"in_order" : false
|
"slop" : 12,
|
||||||
|
"in_order" : false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The `clauses` element is a list of one or more other span type queries
|
The `clauses` element is a list of one or more other span type queries
|
||||||
and the `slop` controls the maximum number of intervening unmatched
|
and the `slop` controls the maximum number of intervening unmatched
|
||||||
|
|
|
@ -6,24 +6,28 @@ query maps to Lucene `SpanNotQuery`. Here is an example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"span_not" : {
|
"query": {
|
||||||
"include" : {
|
"span_not" : {
|
||||||
"span_term" : { "field1" : "hoya" }
|
"include" : {
|
||||||
},
|
"span_term" : { "field1" : "hoya" }
|
||||||
"exclude" : {
|
},
|
||||||
"span_near" : {
|
"exclude" : {
|
||||||
"clauses" : [
|
"span_near" : {
|
||||||
{ "span_term" : { "field1" : "la" } },
|
"clauses" : [
|
||||||
{ "span_term" : { "field1" : "hoya" } }
|
{ "span_term" : { "field1" : "la" } },
|
||||||
],
|
{ "span_term" : { "field1" : "hoya" } }
|
||||||
"slop" : 0,
|
],
|
||||||
"in_order" : true
|
"slop" : 0,
|
||||||
|
"in_order" : true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The `include` and `exclude` clauses can be any span type query. The
|
The `include` and `exclude` clauses can be any span type query. The
|
||||||
`include` clause is the span query whose matches are filtered, and the
|
`include` clause is the span query whose matches are filtered, and the
|
||||||
|
|
|
@ -6,15 +6,19 @@ Matches the union of its span clauses. The span or query maps to Lucene
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"span_or" : {
|
"query": {
|
||||||
"clauses" : [
|
"span_or" : {
|
||||||
{ "span_term" : { "field" : "value1" } },
|
"clauses" : [
|
||||||
{ "span_term" : { "field" : "value2" } },
|
{ "span_term" : { "field" : "value1" } },
|
||||||
{ "span_term" : { "field" : "value3" } }
|
{ "span_term" : { "field" : "value2" } },
|
||||||
]
|
{ "span_term" : { "field" : "value3" } }
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The `clauses` element is a list of one or more other span type queries.
|
The `clauses` element is a list of one or more other span type queries.
|
||||||
|
|
|
@ -6,25 +6,37 @@ Matches spans containing a term. The span term query maps to Lucene
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"span_term" : { "user" : "kimchy" }
|
"query": {
|
||||||
|
"span_term" : { "user" : "kimchy" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
A boost can also be associated with the query:
|
A boost can also be associated with the query:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"span_term" : { "user" : { "value" : "kimchy", "boost" : 2.0 } }
|
"query": {
|
||||||
|
"span_term" : { "user" : { "value" : "kimchy", "boost" : 2.0 } }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
Or :
|
Or :
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"span_term" : { "user" : { "term" : "kimchy", "boost" : 2.0 } }
|
"query": {
|
||||||
|
"span_term" : { "user" : { "term" : "kimchy", "boost" : 2.0 } }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
|
@ -6,24 +6,28 @@ query maps to Lucene `SpanWithinQuery`. Here is an example:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"span_within" : {
|
"query": {
|
||||||
"little" : {
|
"span_within" : {
|
||||||
"span_term" : { "field1" : "foo" }
|
"little" : {
|
||||||
},
|
"span_term" : { "field1" : "foo" }
|
||||||
"big" : {
|
},
|
||||||
"span_near" : {
|
"big" : {
|
||||||
"clauses" : [
|
"span_near" : {
|
||||||
{ "span_term" : { "field1" : "bar" } },
|
"clauses" : [
|
||||||
{ "span_term" : { "field1" : "baz" } }
|
{ "span_term" : { "field1" : "bar" } },
|
||||||
],
|
{ "span_term" : { "field1" : "baz" } }
|
||||||
"slop" : 5,
|
],
|
||||||
"in_order" : true
|
"slop" : 5,
|
||||||
|
"in_order" : true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The `big` and `little` clauses can be any span type query. Matching
|
The `big` and `little` clauses can be any span type query. Matching
|
||||||
spans from `little` that are enclosed within `big` are returned.
|
spans from `little` that are enclosed within `big` are returned.
|
||||||
|
|
|
@ -19,8 +19,8 @@ GET /_search
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The above request is translated into:
|
The above request is translated into:
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ GET /_search
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
Alternatively passing the template as an escaped string works as well:
|
Alternatively passing the template as an escaped string works as well:
|
||||||
|
|
||||||
|
@ -53,6 +53,8 @@ GET /_search
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
<1> New line characters (`\n`) should be escaped as `\\n` or removed,
|
<1> New line characters (`\n`) should be escaped as `\\n` or removed,
|
||||||
and quotes (`"`) should be escaped as `\\"`.
|
and quotes (`"`) should be escaped as `\\"`.
|
||||||
|
|
||||||
|
@ -77,6 +79,8 @@ GET /_search
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
<1> Name of the query template in `config/scripts/`, i.e., `my_template.mustache`.
|
<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:
|
Alternatively, you can register a query template in the cluster state with:
|
||||||
|
@ -85,9 +89,10 @@ Alternatively, you can register a query template in the cluster state with:
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
PUT /_search/template/my_template
|
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:
|
and refer to it in the `template` query with the `id` parameter:
|
||||||
|
|
||||||
|
@ -106,9 +111,13 @@ GET /_search
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
// TEST[continued]
|
||||||
|
|
||||||
<1> Name of the query template in `config/scripts/`, i.e., `my_template.mustache`.
|
<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.
|
There is also a dedicated `template` endpoint, allows you to template an entire search request.
|
||||||
Please see <<search-template>> for more details.
|
Please see <<search-template>> for more details.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,18 @@ Filters documents that have fields that match any of the provided terms
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"constant_score" : {
|
"query": {
|
||||||
"filter" : {
|
"constant_score" : {
|
||||||
"terms" : { "user" : ["kimchy", "elasticsearch"]}
|
"filter" : {
|
||||||
|
"terms" : { "user" : ["kimchy", "elasticsearch"]}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The `terms` query is also aliased with `in` as the filter name for
|
The `terms` query is also aliased with `in` as the filter name for
|
||||||
simpler usage deprecated[5.0.0,use `terms` instead].
|
simpler usage deprecated[5.0.0,use `terms` instead].
|
||||||
|
@ -63,33 +67,37 @@ possible, reducing the need for networking.
|
||||||
|
|
||||||
[float]
|
[float]
|
||||||
===== Terms lookup twitter example
|
===== 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]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
# index the information for user with id 2, specifically, its followers
|
PUT /users/user/2
|
||||||
curl -XPUT localhost:9200/users/user/2 -d '{
|
{
|
||||||
"followers" : ["1", "3"]
|
"followers" : ["1", "3"]
|
||||||
}'
|
}
|
||||||
|
|
||||||
# index a tweet, from user with id 1
|
PUT /tweets/tweet/1
|
||||||
curl -XPUT localhost:9200/tweets/tweet/1 -d '{
|
{
|
||||||
"user" : "1"
|
"user" : "1"
|
||||||
}'
|
}
|
||||||
|
|
||||||
# search on all the tweets that match the followers of user 2
|
GET /tweets/_search
|
||||||
curl -XGET localhost:9200/tweets/_search -d '{
|
{
|
||||||
"query" : {
|
"query" : {
|
||||||
"terms" : {
|
"terms" : {
|
||||||
"user" : {
|
"user" : {
|
||||||
"index" : "users",
|
"index" : "users",
|
||||||
"type" : "user",
|
"type" : "user",
|
||||||
"id" : "2",
|
"id" : "2",
|
||||||
"path" : "followers"
|
"path" : "followers"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}'
|
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
The structure of the external terms document can also include array of
|
The structure of the external terms document can also include array of
|
||||||
inner objects, for example:
|
inner objects, for example:
|
||||||
|
|
|
@ -5,9 +5,13 @@ Filters documents matching the provided document / mapping type.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"type" : {
|
"query": {
|
||||||
"value" : "my_type"
|
"type" : {
|
||||||
|
"value" : "my_type"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
|
@ -11,28 +11,40 @@ query maps to Lucene `WildcardQuery`.
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"wildcard" : { "user" : "ki*y" }
|
"query": {
|
||||||
|
"wildcard" : { "user" : "ki*y" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
A boost can also be associated with the query:
|
A boost can also be associated with the query:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"wildcard" : { "user" : { "value" : "ki*y", "boost" : 2.0 } }
|
"query": {
|
||||||
|
"wildcard" : { "user" : { "value" : "ki*y", "boost" : 2.0 } }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
Or :
|
Or :
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
GET /_search
|
||||||
{
|
{
|
||||||
"wildcard" : { "user" : { "wildcard" : "ki*y", "boost" : 2.0 } }
|
"query": {
|
||||||
|
"wildcard" : { "user" : { "wildcard" : "ki*y", "boost" : 2.0 } }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
// CONSOLE
|
||||||
|
|
||||||
This multi term query allows to control how it gets rewritten using the
|
This multi term query allows to control how it gets rewritten using the
|
||||||
<<query-dsl-multi-term-rewrite,rewrite>>
|
<<query-dsl-multi-term-rewrite,rewrite>>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue