Convert rest of query-dsl docs to be run in tests
This commit is contained in:
parent
ab4367c07e
commit
85f1ab44d9
|
@ -8,7 +8,9 @@ overall score.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"boosting" : {
|
||||
"positive" : {
|
||||
"term" : {
|
||||
|
@ -23,4 +25,6 @@ overall score.
|
|||
"negative_boost" : 0.2
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
|
|
@ -70,7 +70,9 @@ In this example, words that have a document frequency greater than 0.1%
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"common": {
|
||||
"body": {
|
||||
"query": "this is bonsai cool",
|
||||
|
@ -78,7 +80,9 @@ In this example, words that have a document frequency greater than 0.1%
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
The number of terms which should match can be controlled with the
|
||||
<<query-dsl-minimum-should-match,`minimum_should_match`>>
|
||||
|
@ -90,7 +94,9 @@ all terms required:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"common": {
|
||||
"body": {
|
||||
"query": "nelly the elephant as a cartoon",
|
||||
|
@ -99,13 +105,17 @@ all terms required:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
which is roughly equivalent to:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": [
|
||||
{ "term": { "body": "nelly"}},
|
||||
|
@ -113,13 +123,15 @@ which is roughly equivalent to:
|
|||
{ "term": { "body": "cartoon"}}
|
||||
],
|
||||
"should": [
|
||||
{ "term": { "body": "the"}}
|
||||
{ "term": { "body": "as"}}
|
||||
{ "term": { "body": "the"}},
|
||||
{ "term": { "body": "as"}},
|
||||
{ "term": { "body": "a"}}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Alternatively use
|
||||
<<query-dsl-minimum-should-match,`minimum_should_match`>>
|
||||
|
@ -128,7 +140,9 @@ must be present, for instance:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"common": {
|
||||
"body": {
|
||||
"query": "nelly the elephant as a cartoon",
|
||||
|
@ -137,13 +151,17 @@ must be present, for instance:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
which is roughly equivalent to:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": {
|
||||
"bool": {
|
||||
|
@ -156,13 +174,15 @@ which is roughly equivalent to:
|
|||
}
|
||||
},
|
||||
"should": [
|
||||
{ "term": { "body": "the"}}
|
||||
{ "term": { "body": "as"}}
|
||||
{ "term": { "body": "the"}},
|
||||
{ "term": { "body": "as"}},
|
||||
{ "term": { "body": "a"}}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
minimum_should_match
|
||||
|
||||
|
@ -174,7 +194,9 @@ additional parameters (note the change in structure):
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"common": {
|
||||
"body": {
|
||||
"query": "nelly the elephant not as a cartoon",
|
||||
|
@ -186,13 +208,17 @@ additional parameters (note the change in structure):
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
which is roughly equivalent to:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": {
|
||||
"bool": {
|
||||
|
@ -217,7 +243,9 @@ which is roughly equivalent to:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
In this case it means the high frequency terms have only an impact on
|
||||
relevance when there are at least three of them. But the most
|
||||
|
@ -227,7 +255,9 @@ for high frequency terms is when there are only high frequency terms:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"common": {
|
||||
"body": {
|
||||
"query": "how not to be",
|
||||
|
@ -239,13 +269,17 @@ for high frequency terms is when there are only high frequency terms:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
which is roughly equivalent to:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"should": [
|
||||
{ "term": { "body": "how"}},
|
||||
|
@ -256,7 +290,9 @@ which is roughly equivalent to:
|
|||
"minimum_should_match": "3<50%"
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
The high frequency generated query is then slightly less restrictive
|
||||
than with an `AND`.
|
||||
|
|
|
@ -27,7 +27,9 @@ This query maps to Lucene `DisjunctionMaxQuery`.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"dis_max" : {
|
||||
"tie_breaker" : 0.7,
|
||||
"boost" : 1.2,
|
||||
|
@ -41,4 +43,6 @@ This query maps to Lucene `DisjunctionMaxQuery`.
|
|||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
|
|
@ -5,10 +5,14 @@ Returns documents that have at least one non-`null` value in the original field:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"exists" : { "field" : "user" }
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
For instance, these documents would all match the above query:
|
||||
|
||||
|
@ -77,6 +81,9 @@ clause as follows:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must_not": {
|
||||
"exists": {
|
||||
|
@ -84,7 +91,10 @@ clause as follows:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
This query returns documents that have no value in the user field.
|
||||
|
||||
|
|
|
@ -17,16 +17,22 @@ Here is a simple example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"fuzzy" : { "user" : "ki" }
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Or with more advanced settings:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"fuzzy" : {
|
||||
"user" : {
|
||||
"value" : "ki",
|
||||
|
@ -37,7 +43,9 @@ Or with more advanced settings:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
===== Parameters
|
||||
|
@ -75,7 +83,9 @@ For example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"fuzzy" : {
|
||||
"price" : {
|
||||
"value" : 12,
|
||||
|
@ -83,14 +93,18 @@ For example:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Will result in a range query between 10 and 14. Date fields support
|
||||
<<time-units,time values>>, eg:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"fuzzy" : {
|
||||
"created" : {
|
||||
"value" : "2010-02-05T12:05:07",
|
||||
|
@ -98,6 +112,7 @@ Will result in a range query between 10 and 14. Date fields support
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
|
||||
// CONSOLE
|
||||
See <<fuzziness>> for more details about accepted values.
|
||||
|
|
|
@ -6,6 +6,24 @@ bounding box. Assuming the following indexed document:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
PUT /my_locations
|
||||
{
|
||||
"mappings": {
|
||||
"location": {
|
||||
"properties": {
|
||||
"pin": {
|
||||
"properties": {
|
||||
"location": {
|
||||
"type": "geo_point"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PUT /my_locations/location/1
|
||||
{
|
||||
"pin" : {
|
||||
"location" : {
|
||||
|
@ -15,13 +33,17 @@ bounding box. Assuming the following indexed document:
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
// TESTSETUP
|
||||
|
||||
Then the following simple query can be executed with a
|
||||
`geo_bounding_box` filter:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"must" : {
|
||||
"match_all" : {}
|
||||
|
@ -42,7 +64,9 @@ Then the following simple query can be executed with a
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
==== Query Options
|
||||
|
@ -75,7 +99,9 @@ representation of the geo point, the filter can accept it as well:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"must" : {
|
||||
"match_all" : {}
|
||||
|
@ -96,7 +122,9 @@ representation of the geo point, the filter can accept it as well:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
===== Lat Lon As Array
|
||||
|
@ -106,7 +134,9 @@ conform with http://geojson.org/[GeoJSON].
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"must" : {
|
||||
"match_all" : {}
|
||||
|
@ -121,7 +151,9 @@ conform with http://geojson.org/[GeoJSON].
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
===== Lat Lon As String
|
||||
|
@ -130,7 +162,9 @@ Format in `lat,lon`.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"must" : {
|
||||
"match_all" : {}
|
||||
|
@ -145,14 +179,18 @@ Format in `lat,lon`.
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
===== Geohash
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"must" : {
|
||||
"match_all" : {}
|
||||
|
@ -167,7 +205,9 @@ Format in `lat,lon`.
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
==== Vertices
|
||||
|
@ -181,7 +221,9 @@ values separately.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"must" : {
|
||||
"match_all" : {}
|
||||
|
@ -198,7 +240,9 @@ values separately.
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
|
||||
[float]
|
||||
|
@ -227,7 +271,9 @@ are not supported. Here is an example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"must" : {
|
||||
"match_all" : {}
|
||||
|
@ -249,7 +295,9 @@ are not supported. Here is an example:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
==== Ignore Unmapped
|
||||
|
|
|
@ -5,7 +5,9 @@ Filters documents that exists within a range from a specific point:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"must" : {
|
||||
"match_all" : {}
|
||||
|
@ -22,7 +24,9 @@ Filters documents that exists within a range from a specific point:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Supports the same point location parameter and query options as the
|
||||
<<query-dsl-geo-distance-query,geo_distance>>
|
||||
|
|
|
@ -6,12 +6,11 @@ points. Here is an example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"query" : {
|
||||
"match_all" : {}
|
||||
},
|
||||
"filter" : {
|
||||
"geo_polygon" : {
|
||||
"person.location" : {
|
||||
"points" : [
|
||||
|
@ -24,7 +23,9 @@ points. Here is an example:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
==== Query Options
|
||||
|
@ -53,7 +54,9 @@ conform with http://geojson.org/[GeoJSON].
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"must" : {
|
||||
"match_all" : {}
|
||||
|
@ -71,7 +74,9 @@ conform with http://geojson.org/[GeoJSON].
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
===== Lat Lon as String
|
||||
|
@ -80,7 +85,9 @@ Format in `lat,lon`.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"must" : {
|
||||
"match_all" : {}
|
||||
|
@ -98,14 +105,18 @@ Format in `lat,lon`.
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
===== Geohash
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"must" : {
|
||||
"match_all" : {}
|
||||
|
@ -123,7 +134,9 @@ Format in `lat,lon`.
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
==== geo_point Type
|
||||
|
|
|
@ -38,6 +38,7 @@ The following query will find the point using the Elasticsearch's
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query":{
|
||||
"bool": {
|
||||
|
@ -59,6 +60,7 @@ The following query will find the point using the Elasticsearch's
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
==== Pre-Indexed Shape
|
||||
|
||||
|
@ -81,7 +83,9 @@ shape:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": {
|
||||
"match_all": {}
|
||||
|
@ -100,7 +104,9 @@ shape:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
==== Spatial Relations
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ setting the `geohash_prefix` option:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
PUT /my_index
|
||||
{
|
||||
"mappings" : {
|
||||
"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
|
||||
defined by a latitude and longitude pair the size of the cell needs to be
|
||||
|
@ -42,7 +45,9 @@ next to the given cell.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"must" : {
|
||||
"match_all" : {}
|
||||
|
@ -59,7 +64,9 @@ next to the given cell.
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
==== Ignore Unmapped
|
||||
|
|
|
@ -7,7 +7,9 @@ an example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"has_child" : {
|
||||
"type" : "blog_tag",
|
||||
"query" : {
|
||||
|
@ -17,7 +19,9 @@ an example:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
==== Scoring capabilities
|
||||
|
@ -32,7 +36,9 @@ inside the `has_child` query:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"has_child" : {
|
||||
"type" : "blog_tag",
|
||||
"score_mode" : "min",
|
||||
|
@ -43,7 +49,9 @@ inside the `has_child` query:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
==== Min/Max Children
|
||||
|
@ -54,7 +62,9 @@ a match:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"has_child" : {
|
||||
"type" : "blog_tag",
|
||||
"score_mode" : "min",
|
||||
|
@ -67,7 +77,9 @@ a match:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
<1> Both `min_children` and `max_children` are optional.
|
||||
|
||||
The `min_children` and `max_children` parameters can be combined with
|
||||
|
|
|
@ -9,7 +9,9 @@ in the same manner as the `has_child` query.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"has_parent" : {
|
||||
"parent_type" : "blog",
|
||||
"query" : {
|
||||
|
@ -19,7 +21,9 @@ in the same manner as the `has_child` query.
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
==== Scoring capabilities
|
||||
|
@ -34,7 +38,9 @@ matching parent document. The score mode can be specified with the
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"has_parent" : {
|
||||
"parent_type" : "blog",
|
||||
"score" : true,
|
||||
|
@ -45,7 +51,9 @@ matching parent document. The score mode can be specified with the
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
==== Ignore Unmapped
|
||||
|
|
|
@ -6,13 +6,17 @@ uses the <<mapping-uid-field,_uid>> field.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"ids" : {
|
||||
"type" : "my_type",
|
||||
"values" : ["1", "4", "100"]
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
The `type` is optional and can be omitted, and can also accept an array
|
||||
of values. If no type is specified, all types defined in the index mapping are tried.
|
||||
|
|
|
@ -9,7 +9,9 @@ on the list, the alternative `no_match_query` is executed.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"indices" : {
|
||||
"indices" : ["index1", "index2"],
|
||||
"query" : {
|
||||
|
@ -20,7 +22,9 @@ on the list, the alternative `no_match_query` is executed.
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
You can use the `index` field to provide a single index.
|
||||
|
||||
|
|
|
@ -6,12 +6,16 @@ allows for prefix matches on the last term in the text. For example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"match_phrase_prefix" : {
|
||||
"message" : "quick brown f"
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
It accepts the same parameters as the phrase type. In addition, it also
|
||||
accepts a `max_expansions` parameter (default `50`) that can control to how
|
||||
|
@ -21,7 +25,9 @@ example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"match_phrase_prefix" : {
|
||||
"message" : {
|
||||
"query" : "quick brown f",
|
||||
|
@ -29,7 +35,9 @@ example:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[IMPORTANT]
|
||||
===================================================
|
||||
|
|
|
@ -6,12 +6,16 @@ out of the analyzed text. For example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"match_phrase" : {
|
||||
"message" : "this is a test"
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
A phrase query matches terms up to a configurable `slop`
|
||||
(which defaults to 0) in any order. Transposed terms have a slop of 2.
|
||||
|
@ -22,7 +26,9 @@ definition, or the default search analyzer, for example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"match_phrase" : {
|
||||
"message" : {
|
||||
"query" : "this is a test",
|
||||
|
@ -30,4 +36,6 @@ definition, or the default search analyzer, for example:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
|
|
@ -7,12 +7,16 @@ them, and constructs a query. For example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"match" : {
|
||||
"message" : "this is a test"
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Note, `message` is the name of a field, you can substitute the name of
|
||||
any field (including `_all`) instead.
|
||||
|
@ -54,7 +58,9 @@ change in structure, `message` is the field name):
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"match" : {
|
||||
"message" : {
|
||||
"query" : "this is a test",
|
||||
|
@ -62,7 +68,9 @@ change in structure, `message` is the field name):
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[[query-dsl-match-query-zero]]
|
||||
===== Zero terms query
|
||||
|
@ -73,7 +81,9 @@ change that the `zero_terms_query` option can be used, which accepts
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"match" : {
|
||||
"message" : {
|
||||
"query" : "to be or not to be",
|
||||
|
@ -82,7 +92,9 @@ change that the `zero_terms_query` option can be used, which accepts
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[[query-dsl-match-query-cutoff]]
|
||||
===== Cutoff frequency
|
||||
|
@ -110,7 +122,9 @@ Here is an example showing a query composed of stopwords exclusively:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"match" : {
|
||||
"message" : {
|
||||
"query" : "to be or not to be",
|
||||
|
@ -118,8 +132,9 @@ Here is an example showing a query composed of stopwords exclusively:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
|
||||
// CONSOLE
|
||||
|
||||
IMPORTANT: The `cutoff_frequency` option operates on a per-shard-level. This means
|
||||
that when trying it out on test indexes with low document numbers you
|
||||
|
|
|
@ -10,6 +10,7 @@ will work with:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
PUT /my_index
|
||||
{
|
||||
"type1" : {
|
||||
"properties" : {
|
||||
|
@ -20,12 +21,16 @@ will work with:
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
// TESTSETUP
|
||||
|
||||
And here is a sample nested query usage:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"nested" : {
|
||||
"path" : "obj1",
|
||||
"score_mode" : "avg",
|
||||
|
@ -43,7 +48,9 @@ And here is a sample nested query usage:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
The query `path` points to the nested object path, and the `query`
|
||||
includes the query that will run on the nested docs matching the
|
||||
|
|
|
@ -7,6 +7,7 @@ The `parent_id` query can be used to find child documents which belong to a part
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
PUT /my_index
|
||||
{
|
||||
"parent_id" : {
|
||||
"type" : "blog_tag",
|
||||
|
@ -14,6 +15,8 @@ The `parent_id` query can be used to find child documents which belong to a part
|
|||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
// TESTSETUP
|
||||
|
||||
The above is functionally equivalent to using the following
|
||||
<<query-dsl-has-parent-query, `has_parent`>> query, but performs
|
||||
|
@ -21,7 +24,9 @@ better as it does not need to do a join:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"has_parent": {
|
||||
"type": "blog",
|
||||
"query": {
|
||||
|
@ -31,7 +36,9 @@ better as it does not need to do a join:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
==== Parameters
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ Create an index with two mappings:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
curl -XPUT "http://localhost:9200/my-index" -d'
|
||||
PUT /my-index
|
||||
{
|
||||
"mappings": {
|
||||
"doctype": {
|
||||
|
@ -31,8 +31,9 @@ curl -XPUT "http://localhost:9200/my-index" -d'
|
|||
}
|
||||
}
|
||||
}
|
||||
}'
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
The `doctype` mapping is the mapping used to preprocess
|
||||
the document defined in the `percolator` query before it
|
||||
|
@ -50,20 +51,24 @@ Register a query in the percolator:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
curl -XPUT 'localhost:9200/my-index/queries/1' -d '{
|
||||
PUT /my-index/queries/1
|
||||
{
|
||||
"query" : {
|
||||
"match" : {
|
||||
"message" : "bonsai tree"
|
||||
}
|
||||
}
|
||||
}'
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
// TEST[continued]
|
||||
|
||||
Match a document to the registered percolator queries:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
curl -XGET 'localhost:9200/my-index/_search' -d '{
|
||||
GET /my-index/_search
|
||||
{
|
||||
"query" : {
|
||||
"percolate" : {
|
||||
"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:
|
||||
|
||||
|
@ -151,12 +158,13 @@ Index the document we want to percolate:
|
|||
|
||||
[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"
|
||||
}'
|
||||
}
|
||||
--------------------------------------------------
|
||||
|
||||
// CONSOLE
|
||||
// TEST[continued]
|
||||
Index response:
|
||||
|
||||
[source,js]
|
||||
|
@ -179,7 +187,7 @@ Percolating an existing document, using the index response as basis to build to
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
curl -XGET "http://localhost:9200/my-index/_search" -d'
|
||||
GET /my-index/_search
|
||||
{
|
||||
"query" : {
|
||||
"percolate" : {
|
||||
|
@ -191,8 +199,10 @@ curl -XGET "http://localhost:9200/my-index/_search" -d'
|
|||
"version" : 1 <1>
|
||||
}
|
||||
}
|
||||
}'
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
// TEST[continued]
|
||||
|
||||
<1> The version is optional, but useful in certain cases. We can then ensure that we are try to percolate
|
||||
the document we just have indexed. A change may be made after we have indexed, and if that is the
|
||||
|
@ -216,35 +226,39 @@ Save a query:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
curl -XPUT "http://localhost:9200/my-index/queries/1" -d'
|
||||
PUT /my-index/queries/1
|
||||
{
|
||||
"query" : {
|
||||
"match" : {
|
||||
"message" : "brown fox"
|
||||
}
|
||||
}
|
||||
}'
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
// TEST[continued]
|
||||
|
||||
Save another query:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
curl -XPUT "http://localhost:9200/my-index/queries/2" -d'
|
||||
PUT /my-index/queries/2
|
||||
{
|
||||
"query" : {
|
||||
"match" : {
|
||||
"message" : "lazy dog"
|
||||
}
|
||||
}
|
||||
}'
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
// TEST[continued]
|
||||
|
||||
Execute a search request with the `percolate` query and highlighting enabled:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
curl -XGET "http://localhost:9200/my-index/_search" -d'
|
||||
GET /my-index/_search
|
||||
{
|
||||
"query" : {
|
||||
"percolate" : {
|
||||
|
@ -260,8 +274,10 @@ curl -XGET "http://localhost:9200/my-index/_search" -d'
|
|||
"message": {}
|
||||
}
|
||||
}
|
||||
}'
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
// TEST[continued]
|
||||
|
||||
This will yield the following response.
|
||||
|
||||
|
|
|
@ -6,13 +6,17 @@ an example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"query_string" : {
|
||||
"default_field" : "content",
|
||||
"query" : "this AND that OR thus"
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
The `query_string` top level parameters include:
|
||||
|
||||
|
@ -113,25 +117,33 @@ For example, the following query
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"query_string" : {
|
||||
"fields" : ["content", "name"],
|
||||
"query" : "this AND that"
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
matches the same words as
|
||||
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"query_string": {
|
||||
"query": "(content:this OR name:this) AND (content:that OR name:that)"
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Since several queries are generated from the individual search terms,
|
||||
combining them can be automatically done using either a `dis_max` query or a
|
||||
|
@ -140,14 +152,18 @@ notation):
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"query_string" : {
|
||||
"fields" : ["content", "name^5"],
|
||||
"query" : "this AND that OR thus",
|
||||
"use_dis_max" : true
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Simple wildcard can also be used to search "within" specific inner
|
||||
elements of the document. For example, if we have a `city` object with
|
||||
|
@ -156,14 +172,18 @@ search on all "city" fields:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"query_string" : {
|
||||
"fields" : ["city.*"],
|
||||
"query" : "this AND that OR thus",
|
||||
"use_dis_max" : true
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Another option is to provide the wildcard fields search in the query
|
||||
string itself (properly escaping the `*` sign), for example:
|
||||
|
@ -188,13 +208,17 @@ introduced fields included). For example:
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"query_string" : {
|
||||
"fields" : ["content", "name.*^5"],
|
||||
"query" : "this AND that OR thus",
|
||||
"use_dis_max" : true
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
include::query-string-syntax.asciidoc[]
|
||||
|
|
|
@ -15,18 +15,24 @@ matchers like `.*?+` will mostly lower performance.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"regexp":{
|
||||
"name.first": "s.*y"
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Boosting is also supported
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"regexp":{
|
||||
"name.first":{
|
||||
"value":"s.*y",
|
||||
|
@ -34,13 +40,17 @@ Boosting is also supported
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
You can also use special flags
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"regexp":{
|
||||
"name.first": {
|
||||
"value": "s.*y",
|
||||
|
@ -48,7 +58,9 @@ You can also use special flags
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Possible flags are `ALL` (default), `ANYSTRING`, `COMPLEMENT`,
|
||||
`EMPTY`, `INTERSECTION`, `INTERVAL`, or `NONE`. Please check the
|
||||
|
@ -64,7 +76,9 @@ this limit to allow more complex regular expressions to execute.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"regexp":{
|
||||
"name.first": {
|
||||
"value": "s.*y",
|
||||
|
@ -73,7 +87,8 @@ this limit to allow more complex regular expressions to execute.
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
|
||||
// CONSOLE
|
||||
|
||||
include::regexp-syntax.asciidoc[]
|
||||
|
|
|
@ -7,17 +7,20 @@ context, for example:
|
|||
|
||||
[source,js]
|
||||
----------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"must" : {
|
||||
...
|
||||
},
|
||||
"filter" : {
|
||||
"script" : {
|
||||
"script" : "doc['num1'].value > 1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
----------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
[float]
|
||||
==== Custom Parameters
|
||||
|
@ -28,14 +31,14 @@ to use the ability to pass parameters to the script itself, for example:
|
|||
|
||||
[source,js]
|
||||
----------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"bool" : {
|
||||
"must" : {
|
||||
...
|
||||
},
|
||||
"filter" : {
|
||||
"script" : {
|
||||
"script" : {
|
||||
"inline" : "doc['num1'].value > param1"
|
||||
"inline" : "doc['num1'].value > param1",
|
||||
"params" : {
|
||||
"param1" : 5
|
||||
}
|
||||
|
@ -43,5 +46,8 @@ to use the ability to pass parameters to the script itself, for example:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
----------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
|
|
|
@ -67,21 +67,24 @@ possible, reducing the need for networking.
|
|||
|
||||
[float]
|
||||
===== Terms lookup twitter example
|
||||
At first we index the information for user with id 2, specifically, its
|
||||
followers, than index a tweet from user with id 1. Finally we search on
|
||||
all the tweets that match the followers of user 2.
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
# index the information for user with id 2, specifically, its followers
|
||||
curl -XPUT localhost:9200/users/user/2 -d '{
|
||||
PUT /users/user/2
|
||||
{
|
||||
"followers" : ["1", "3"]
|
||||
}'
|
||||
}
|
||||
|
||||
# index a tweet, from user with id 1
|
||||
curl -XPUT localhost:9200/tweets/tweet/1 -d '{
|
||||
PUT /tweets/tweet/1
|
||||
{
|
||||
"user" : "1"
|
||||
}'
|
||||
}
|
||||
|
||||
# search on all the tweets that match the followers of user 2
|
||||
curl -XGET localhost:9200/tweets/_search -d '{
|
||||
GET /tweets/_search
|
||||
{
|
||||
"query" : {
|
||||
"terms" : {
|
||||
"user" : {
|
||||
|
@ -92,8 +95,9 @@ curl -XGET localhost:9200/tweets/_search -d '{
|
|||
}
|
||||
}
|
||||
}
|
||||
}'
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
The structure of the external terms document can also include array of
|
||||
inner objects, for example:
|
||||
|
|
|
@ -11,28 +11,40 @@ query maps to Lucene `WildcardQuery`.
|
|||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"wildcard" : { "user" : "ki*y" }
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
A boost can also be associated with the query:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"wildcard" : { "user" : { "value" : "ki*y", "boost" : 2.0 } }
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
Or :
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
GET /_search
|
||||
{
|
||||
"query": {
|
||||
"wildcard" : { "user" : { "wildcard" : "ki*y", "boost" : 2.0 } }
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
This multi term query allows to control how it gets rewritten using the
|
||||
<<query-dsl-multi-term-rewrite,rewrite>>
|
||||
|
|
Loading…
Reference in New Issue