Skip to content

Commit 6baf029

Browse files
authored
Add doumentation for sorting over range fields (#130538)
1 parent 417bf4f commit 6baf029

File tree

1 file changed

+64
-0
lines changed
  • docs/reference/elasticsearch/mapping-reference

1 file changed

+64
-0
lines changed

docs/reference/elasticsearch/mapping-reference/range.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,70 @@ The following parameters are accepted by range types:
215215
[`store`](/reference/elasticsearch/mapping-reference/mapping-store.md)
216216
: Whether the field value should be stored and retrievable separately from the [`_source`](/reference/elasticsearch/mapping-reference/mapping-source-field.md) field. Accepts `true` or `false` (default).
217217

218+
## Sorting
219+
220+
Sorting is not supported for any of the `range` field types. Attempting to sort by a field of type range_field will result in a `400 Bad Request` response.
221+
For example, executing a sort query on a field of type `integer_range`,
222+
```console
223+
PUT idx
224+
{
225+
"mappings": {
226+
"properties": {
227+
"my_range": {
228+
"type": "integer_range"
229+
}
230+
}
231+
}
232+
}
233+
234+
POST idx/_search
235+
{
236+
"sort": [
237+
{
238+
"my_range": {
239+
"order": "asc"
240+
}
241+
}
242+
]
243+
}
244+
```
245+
results in the following response:
246+
```console-result
247+
{
248+
"error": {
249+
"root_cause": [
250+
{
251+
"type": "illegal_argument_exception",
252+
"reason": "Sorting by range field [my_range] is not supported"
253+
}
254+
],
255+
"type": "search_phase_execution_exception",
256+
"reason": "all shards failed",
257+
"phase": "query",
258+
"grouped": true,
259+
"failed_shards": [
260+
{
261+
"shard": 0,
262+
"index": "idx",
263+
"node": "7pzVSCf5TuSNZYj-N7u3tw",
264+
"reason": {
265+
"type": "illegal_argument_exception",
266+
"reason": "Sorting by range field [my_range] is not supported"
267+
}
268+
}
269+
],
270+
"caused_by": {
271+
"type": "illegal_argument_exception",
272+
"reason": "Sorting by range field [my_range] is not supported",
273+
"caused_by": {
274+
"type": "illegal_argument_exception",
275+
"reason": "Sorting by range field [my_range] is not supported"
276+
}
277+
}
278+
},
279+
"status": 400
280+
}
281+
```
218282

219283
## Synthetic `_source` [range-synthetic-source]
220284

0 commit comments

Comments
 (0)