What you are trying to do is IMO best covered by the ICU analysis plugin and specifically its keyword field.
I gave it a quick shot and tried the following:
DELETE test
PUT test
{
"mappings": {
"_doc": {
"properties": {
"login_id": {
"type": "text",
"fields": {
"sort": {
"type": "icu_collation_keyword",
"index": false,
"numeric": true,
"case_level": false
}
}
}
}
}
}
}
POST test/_doc
{ "login_id": "1" }
POST test/_doc
{ "login_id": "1A" }
POST test/_doc
{ "login_id": "1B" }
POST test/_doc
{ "login_id": "12" }
POST test/_doc
{ "login_id": "123" }
POST test/_doc
{ "login_id": "20" }
POST test/_doc
{ "login_id": "22" }
POST test/_doc
{ "login_id": "user" }
POST test/_doc
{ "login_id": "user1" }
POST test/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"login_id.sort": {
"order": "asc"
}
}
]
}
This gives you back 1, 1A, 1B, 12, 20, 22, 123, user, user1. I'm not sure if it's (easily) possible to get 1A after 123; that feels rather counterintuitive.
This is not a helpful comment: What specifically is not working? Sorting is wrong, you have issues installing the ICU plugin (which I didn't explicitly mention, sorry),...
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.