case_insensitive_normalizer is just to make strings sorted in case insensitive way. Name field has vales like item 0, item 1, item 10, item 2. If I try to sort object index by name as like name.keyword : "asc" it returns response as item 0, item 1, item 10, item 2. But correct response should be item 0, item 1, item 2, item 10. I see by default does sorting in lexicographical order, how to make numbers treated as strings an get correct sorting order?
To sort alphanumeric strings in Elasticsearch in numerical order (e.g., item 0, item 1, item 2, item 10), you can't directly achieve this with the default sorting because Elasticsearch sorts strings lexicographically. Instead, consider these two main approaches:
Use a Script-based Sorting: Implement a custom script in your Elasticsearch query that extracts and converts the numerical part of your strings to integers for sorting. This method is flexible but might affect performance negatively for large datasets.
Index a Separate Numeric Field: During data ingestion, extract the numeric part of your strings and store it in a separate numeric field. Then, sort using this numeric field to achieve the desired order. This method is more efficient but requires preprocessing your data.
The second method is generally preferred for better performance and scalability.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.