If you want number based sorting, take a look at multi fields and index this field as a string as well as an integer. This way you can specify the string based for all your search operations and the integer based field for sorting.
please format your snippets properly. This is super hard to read.
In order to fully understand the issue, you need to provide a minimal, but complete reproducible example, that includes index creation, mapping, sample documents and your query, otherwise everyone is working on assumptions, how your may have configured Elasticsearch and come to wrong conclusions.
That said, a keyword field is still a string field and not an integer field, so you are still not properly sorting by a number.
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.