Skip to content

Commit b21ab9e

Browse files
davidbkempmayya-sharipova
authored andcommitted
Documents applicability of term query to range type (#28166)
Closes #27030
1 parent f303ca6 commit b21ab9e

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

docs/reference/mapping/types/range.asciidoc

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,16 @@ PUT range_index/_doc/1
4747
--------------------------------------------------
4848
//CONSOLE
4949

50-
The following is an example of a `date_range` query over the `date_range` field named "time_frame".
50+
The following is an example of a <<query-dsl-term-query, term query>> on the `integer_range` field named "expected_attendees".
5151

5252
[source,js]
5353
--------------------------------------------------
54-
POST range_index/_search
54+
GET range_index/_search
5555
{
5656
"query" : {
57-
"range" : {
58-
"time_frame" : { <5>
59-
"gte" : "2015-10-31",
60-
"lte" : "2015-11-01",
61-
"relation" : "within" <6>
57+
"term" : {
58+
"expected_attendees" : {
59+
"value": 12
6260
}
6361
}
6462
}
@@ -104,6 +102,27 @@ The result produced by the above query.
104102
--------------------------------------------------
105103
// TESTRESPONSE[s/"took": 13/"took" : $body.took/]
106104

105+
106+
The following is an example of a `date_range` query over the `date_range` field named "time_frame".
107+
108+
[source,js]
109+
--------------------------------------------------
110+
GET range_index/_search
111+
{
112+
"query" : {
113+
"range" : {
114+
"time_frame" : { <5>
115+
"gte" : "2015-10-31",
116+
"lte" : "2015-11-01",
117+
"relation" : "within" <6>
118+
}
119+
}
120+
}
121+
}
122+
--------------------------------------------------
123+
// CONSOLE
124+
// TEST[setup:range_index]
125+
107126
<1> `date_range` types accept the same field parameters defined by the <<date, `date`>> type.
108127
<2> Example indexing a meeting with 10 to 20 attendees.
109128
<3> Date ranges accept the same format as described in <<ranges-on-dates, date range queries>>.
@@ -112,6 +131,44 @@ The result produced by the above query.
112131
<6> Range queries over range <<mapping-types, fields>> support a `relation` parameter which can be one of `WITHIN`, `CONTAINS`,
113132
`INTERSECTS` (default).
114133

134+
This query produces a similar result:
135+
136+
[source,js]
137+
--------------------------------------------------
138+
{
139+
"took": 13,
140+
"timed_out": false,
141+
"_shards" : {
142+
"total": 2,
143+
"successful": 2,
144+
"skipped" : 0,
145+
"failed": 0
146+
},
147+
"hits" : {
148+
"total" : 1,
149+
"max_score" : 1.0,
150+
"hits" : [
151+
{
152+
"_index" : "range_index",
153+
"_type" : "_doc",
154+
"_id" : "1",
155+
"_score" : 1.0,
156+
"_source" : {
157+
"expected_attendees" : {
158+
"gte" : 10, "lte" : 20
159+
},
160+
"time_frame" : {
161+
"gte" : "2015-10-31 12:00:00", "lte" : "2015-11-01"
162+
}
163+
}
164+
}
165+
]
166+
}
167+
}
168+
--------------------------------------------------
169+
// TESTRESPONSE[s/"took": 13/"took" : $body.took/]
170+
171+
115172
[[range-params]]
116173
==== Parameters for range fields
117174

docs/reference/query-dsl/term-query.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ GET _search
5151
as the query clause for `normal`.
5252
<2> The `normal` clause has the default neutral boost of `1.0`.
5353

54+
A `term` query can also match against <<range, range data types>>.
55+
5456
.Why doesn't the `term` query match my document?
5557
**************************************************
5658

0 commit comments

Comments
 (0)