Elasticsearch sorting on string not returning expected results Elasticsearch sorting on string not returning expected results elasticsearch elasticsearch

Elasticsearch sorting on string not returning expected results


As mconlin mentioned if you want to sort on the unanalyzed doc field you need to specify "index": "not_analyzed" to sort as you described. But if you're looking to be able to keep this field tokenized to search on, this post by sloan shows a great example. Using multi-field to keep two different mappings for a field is very common in Elasticsearch.

Hope this helps, let me know if I can offer more explanation.


If you want the sorting to be case-insensitive "index": "not_analyzed" doesn't work, so I've created a custom sort analyzer.

index-settings.yml

index :       analysis :        analyzer :            sort :                type : custom                tokenizer : keyword                filter : [lowercase]

Mapping:

..."articleName": {    "type": "string",    "analyzer": "standard",    "fields": {        "sort": {            "type": "string",            "analyzer": "sort"        }    }}...