From 531c58cf81cb48f7c883d1b41e34903ae1074508 Mon Sep 17 00:00:00 2001 From: David Kemp Date: Fri, 19 Jan 2018 09:19:01 +1100 Subject: [PATCH] Documents applicability of term query to range type (#28166) Closes #27030 --- docs/reference/mapping/types/range.asciidoc | 71 ++++++++++++++++++-- docs/reference/query-dsl/term-query.asciidoc | 2 + 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/docs/reference/mapping/types/range.asciidoc b/docs/reference/mapping/types/range.asciidoc index 76aba682771..0ef4a463c9b 100644 --- a/docs/reference/mapping/types/range.asciidoc +++ b/docs/reference/mapping/types/range.asciidoc @@ -47,18 +47,16 @@ PUT range_index/_doc/1 -------------------------------------------------- //CONSOLE -The following is an example of a `date_range` query over the `date_range` field named "time_frame". +The following is an example of a <> on the `integer_range` field named "expected_attendees". [source,js] -------------------------------------------------- -POST range_index/_search +GET range_index/_search { "query" : { - "range" : { - "time_frame" : { <5> - "gte" : "2015-10-31", - "lte" : "2015-11-01", - "relation" : "within" <6> + "term" : { + "expected_attendees" : { + "value": 12 } } } @@ -104,6 +102,27 @@ The result produced by the above query. -------------------------------------------------- // TESTRESPONSE[s/"took": 13/"took" : $body.took/] + +The following is an example of a `date_range` query over the `date_range` field named "time_frame". + +[source,js] +-------------------------------------------------- +GET range_index/_search +{ + "query" : { + "range" : { + "time_frame" : { <5> + "gte" : "2015-10-31", + "lte" : "2015-11-01", + "relation" : "within" <6> + } + } + } +} +-------------------------------------------------- +// CONSOLE +// TEST[setup:range_index] + <1> `date_range` types accept the same field parameters defined by the <> type. <2> Example indexing a meeting with 10 to 20 attendees. <3> Date ranges accept the same format as described in <>. @@ -112,6 +131,44 @@ The result produced by the above query. <6> Range queries over range <> support a `relation` parameter which can be one of `WITHIN`, `CONTAINS`, `INTERSECTS` (default). +This query produces a similar result: + +[source,js] +-------------------------------------------------- +{ + "took": 13, + "timed_out": false, + "_shards" : { + "total": 2, + "successful": 2, + "skipped" : 0, + "failed": 0 + }, + "hits" : { + "total" : 1, + "max_score" : 1.0, + "hits" : [ + { + "_index" : "range_index", + "_type" : "_doc", + "_id" : "1", + "_score" : 1.0, + "_source" : { + "expected_attendees" : { + "gte" : 10, "lte" : 20 + }, + "time_frame" : { + "gte" : "2015-10-31 12:00:00", "lte" : "2015-11-01" + } + } + } + ] + } +} +-------------------------------------------------- +// TESTRESPONSE[s/"took": 13/"took" : $body.took/] + + [[range-params]] ==== Parameters for range fields diff --git a/docs/reference/query-dsl/term-query.asciidoc b/docs/reference/query-dsl/term-query.asciidoc index 4b668203a33..f1224f33ca7 100644 --- a/docs/reference/query-dsl/term-query.asciidoc +++ b/docs/reference/query-dsl/term-query.asciidoc @@ -51,6 +51,8 @@ GET _search as the query clause for `normal`. <2> The `normal` clause has the default neutral boost of `1.0`. +A `term` query can also match against <>. + .Why doesn't the `term` query match my document? **************************************************