From b77a3394afb1554aa3ba834b11fdb3639592313b Mon Sep 17 00:00:00 2001 From: "Marcus V. Ximenes" Date: Fri, 10 Oct 2025 10:59:12 -0300 Subject: [PATCH] [DOCS] Update sort examples to avoid using _id field Updates sorting documentation to avoid using the _id field in examples and adds a note linking to the ID field type documentation where the limitations are explained in detail. Improves consistency with other documentation pages and best practices. Signed-off-by: Marcus V. Ximenes --- _search-plugins/searching-data/paginate.md | 14 +++++++------- _search-plugins/searching-data/sort.md | 4 +++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/_search-plugins/searching-data/paginate.md b/_search-plugins/searching-data/paginate.md index 66873b2572b..397dde39c76 100644 --- a/_search-plugins/searching-data/paginate.md +++ b/_search-plugins/searching-data/paginate.md @@ -159,7 +159,7 @@ Because open search contexts consume a lot of memory, we suggest you don't use t The `search_after` parameter provides a live cursor that uses the previous page's results to obtain the next page's results. It is similar to the `scroll` operation in that it is meant to scroll many queries in parallel. You can use `search_after` only when sorting is applied. -For example, the following query sorts all lines from the play "Hamlet" by the speech number and then the ID and retrieves the first three results: +For example, the following query sorts all lines from the play "Hamlet" by the speech number and then the line ID and retrieves the first three results: ```json GET shakespeare/_search @@ -172,7 +172,7 @@ GET shakespeare/_search }, "sort": [ { "speech_number": "asc" }, - { "_id": "asc" } + { "line_id": "asc" } ] } ``` @@ -211,7 +211,7 @@ The response contains the `sort` array of values for each document: }, "sort" : [ 1, - "32435" + 32436 ] }, { @@ -229,7 +229,7 @@ The response contains the `sort` array of values for each document: }, "sort" : [ 1, - "32634" + 32635 ] }, { @@ -247,7 +247,7 @@ The response contains the `sort` array of values for each document: }, "sort" : [ 1, - "32635" + 32636 ] } ] @@ -266,10 +266,10 @@ GET shakespeare/_search "play_name": "Hamlet" } }, - "search_after": [ 1, "32635"], + "search_after": [ 1, 32636], "sort": [ { "speech_number": "asc" }, - { "_id": "asc" } + { "line_id": "asc" } ] } ``` diff --git a/_search-plugins/searching-data/sort.md b/_search-plugins/searching-data/sort.md index 804b1297211..8947ce1120e 100644 --- a/_search-plugins/searching-data/sort.md +++ b/_search-plugins/searching-data/sort.md @@ -879,4 +879,6 @@ For each document, the sorting distance is calculated as the minimum, maximum, o ## Performance considerations -Sorted field values are loaded into memory for sorting. Therefore, for minimum overhead we recommend mapping [numeric types]({{site.url}}{{site.baseurl}}/opensearch/supported-field-types/numeric) to the smallest acceptable types, like `short`, `integer`, and `float`. [String types]({{site.url}}{{site.baseurl}}/opensearch/supported-field-types/string) should not have the sorted field analyzed or tokenized. \ No newline at end of file +Sorted field values are loaded into memory for sorting. Therefore, for minimum overhead we recommend mapping [numeric types]({{site.url}}{{site.baseurl}}/opensearch/supported-field-types/numeric) to the smallest acceptable types, like `short`, `integer`, and `float`. [String types]({{site.url}}{{site.baseurl}}/opensearch/supported-field-types/string) should not have the sorted field analyzed or tokenized. + +The `_id` field is restricted from use in sorting operations. If you need to sort by document ID, consider duplicating the ID value into another field with `doc_values` enabled. For more information about `_id` field limitations, see [ID field type]({{site.url}}{{site.baseurl}}/field-types/metadata-fields/id/). \ No newline at end of file