How to implement custom sort in elasticsearch?

150 views Asked by At

The ids in my documents are alphanumeric (like A-1,A-2,A-10,A-21). When I sort the documents based on these ids then the results are like :

A-1 A-10 A-2 A-20 

but I want them like

A-1 A-2 A-10 A-20

To achieve this, how can I write custom scripts for sorting in Elasticsearch?

1

There are 1 answers

0
Sara On

Check this library:

https://github.com/jprante/elasticsearch-analysis-naturalsort

In the example, there is this order: [Bob: 2 points, Bob: 3 points, Bob: 10 points]