Elasticsearch: sorting integer desc

前端 未结 1 1043
暗喜
暗喜 2021-01-22 21:41

When sorting by integer field in elasticsearch (version \"1.1.2\") using query:

{
  \"query\": {
    \"match_all\": {}
  },
  \"sort\": [
    {
      \"cubicCapa         


        
相关标签:
1条回答
  • 2021-01-22 22:16

    you should add leading zeros to your numbers, so you will have [0001, 0010, 0002, 0005] instead of [1, 10, 2, 5]. The number of leading zeros you have add to will depend of the max value you think you will have. e.g. if you think it will be under 10 billions so you should store 0000000005 (9 zeros) instead of 5 and 0000000010 (8 zeros) instead of 10

    0 讨论(0)
提交回复
热议问题