1
- [[request-body- search-sort ]]
2
- ==== Sort
1
+ [[sort- search-results ]]
2
+ === Sort search results
3
3
4
4
Allows you to add one or more sorts on specific fields. Each sort can be
5
5
reversed as well. The sort is defined on a per field level, with special
@@ -48,12 +48,12 @@ NOTE: `_doc` has no real use-case besides being the most efficient sort order.
48
48
So if you don't care about the order in which documents are returned, then you
49
49
should sort by `_doc`. This especially helps when <<request-body-search-scroll,scrolling>>.
50
50
51
- ===== Sort Values
51
+ ==== Sort Values
52
52
53
53
The sort values for each document returned are also returned as part of
54
54
the response.
55
55
56
- ===== Sort Order
56
+ ==== Sort Order
57
57
58
58
The `order` option can have the following values:
59
59
@@ -64,7 +64,7 @@ The `order` option can have the following values:
64
64
The order defaults to `desc` when sorting on the `_score`, and defaults
65
65
to `asc` when sorting on anything else.
66
66
67
- ===== Sort mode option
67
+ ==== Sort mode option
68
68
69
69
Elasticsearch supports sorting by array or multi-valued fields. The `mode` option
70
70
controls what array value is picked for sorting the document it belongs
@@ -84,7 +84,7 @@ The default sort mode in the ascending sort order is `min` -- the lowest value
84
84
is picked. The default sort mode in the descending order is `max` --
85
85
the highest value is picked.
86
86
87
- ====== Sort mode example usage
87
+ ===== Sort mode example usage
88
88
89
89
In the example below the field price has multiple prices per document.
90
90
In this case the result hits will be sorted by price ascending based on
@@ -109,7 +109,7 @@ POST /_search
109
109
}
110
110
--------------------------------------------------
111
111
112
- ===== Sorting numeric fields
112
+ ==== Sorting numeric fields
113
113
114
114
For numeric fields it is also possible to cast the values from one type
115
115
to another using the `numeric_type` option.
@@ -227,7 +227,7 @@ To avoid overflow, the conversion to `date_nanos` cannot be applied on dates bef
227
227
1970 and after 2262 as nanoseconds are represented as longs.
228
228
229
229
[[nested-sorting]]
230
- ===== Sorting within nested objects.
230
+ ==== Sorting within nested objects.
231
231
232
232
Elasticsearch also supports sorting by
233
233
fields that are inside one or more nested objects. The sorting by nested
@@ -253,7 +253,7 @@ field support has a `nested` sort option with the following properties:
253
253
NOTE: Elasticsearch will throw an error if a nested field is defined in a sort without
254
254
a `nested` context.
255
255
256
- ====== Nested sorting examples
256
+ ===== Nested sorting examples
257
257
258
258
In the below example `offer` is a field of type `nested`.
259
259
The nested `path` needs to be specified; otherwise, Elasticsearch doesn't know on what nested level sort values need to be captured.
@@ -331,7 +331,7 @@ POST /_search
331
331
Nested sorting is also supported when sorting by
332
332
scripts and sorting by geo distance.
333
333
334
- ===== Missing Values
334
+ ==== Missing Values
335
335
336
336
The `missing` parameter specifies how docs which are missing
337
337
the sort field should be treated: The `missing` value can be
@@ -357,7 +357,7 @@ GET /_search
357
357
NOTE: If a nested inner object doesn't match with
358
358
the `nested.filter` then a missing value is used.
359
359
360
- ===== Ignoring Unmapped Fields
360
+ ==== Ignoring Unmapped Fields
361
361
362
362
By default, the search request will fail if there is no mapping
363
363
associated with a field. The `unmapped_type` option allows you to ignore
@@ -383,7 +383,7 @@ then Elasticsearch will handle it as if there was a mapping of type
383
383
`long`, with all documents in this index having no value for this field.
384
384
385
385
[[geo-sorting]]
386
- ===== Geo Distance Sorting
386
+ ==== Geo Distance Sorting
387
387
388
388
Allow to sort by `_geo_distance`. Here is an example, assuming `pin.location` is a field of type `geo_point`:
389
389
@@ -438,7 +438,7 @@ have values for the field that is used for distance computation.
438
438
439
439
The following formats are supported in providing the coordinates:
440
440
441
- ====== Lat Lon as Properties
441
+ ===== Lat Lon as Properties
442
442
443
443
[source,console]
444
444
--------------------------------------------------
@@ -462,7 +462,7 @@ GET /_search
462
462
}
463
463
--------------------------------------------------
464
464
465
- ====== Lat Lon as String
465
+ ===== Lat Lon as String
466
466
467
467
Format in `lat,lon`.
468
468
@@ -485,7 +485,7 @@ GET /_search
485
485
}
486
486
--------------------------------------------------
487
487
488
- ====== Geohash
488
+ ===== Geohash
489
489
490
490
[source,console]
491
491
--------------------------------------------------
@@ -506,7 +506,7 @@ GET /_search
506
506
}
507
507
--------------------------------------------------
508
508
509
- ====== Lat Lon as Array
509
+ ===== Lat Lon as Array
510
510
511
511
Format in `[lon, lat]`, note, the order of lon/lat here in order to
512
512
conform with http://geojson.org/[GeoJSON].
@@ -531,7 +531,7 @@ GET /_search
531
531
--------------------------------------------------
532
532
533
533
534
- ===== Multiple reference points
534
+ ==== Multiple reference points
535
535
536
536
Multiple geo points can be passed as an array containing any `geo_point` format, for example
537
537
@@ -560,7 +560,7 @@ The final distance for a document will then be `min`/`max`/`avg` (defined via `m
560
560
561
561
562
562
563
- ===== Script Based Sorting
563
+ ==== Script Based Sorting
564
564
565
565
Allow to sort based on custom scripts, here is an example:
566
566
@@ -588,7 +588,7 @@ GET /_search
588
588
--------------------------------------------------
589
589
590
590
591
- ===== Track Scores
591
+ ==== Track Scores
592
592
593
593
When sorting on a field, scores are not computed. By setting
594
594
`track_scores` to true, scores will still be computed and tracked.
@@ -609,7 +609,7 @@ GET /_search
609
609
}
610
610
--------------------------------------------------
611
611
612
- ===== Memory Considerations
612
+ ==== Memory Considerations
613
613
614
614
When sorting, the relevant sorted field values are loaded into memory.
615
615
This means that per shard, there should be enough memory to contain
0 commit comments