es中keyword字符串类型排序问题

kibana中请求如下
size为返回条数,source为返回字段,aggs为聚合查询,sum为求和

GET /tms-pro-insurance-record-beta-1/_search
{
  "track_scores": false,
  "_source": [
    "order_num",
    "company_id",
    "Order|b_tr_car_batch",
    "create_time",
    "ol_create_time",
    "show_order_flags",
    "insure_com_id",
    "id",
    "uuid",
    "od_id",
    "od_link_id",
    "b_basic_id"
  ],
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "company_id": 44392
          }
        }
      ],
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "status": 1
              }
            }
          ]
        }
      }
    }
  },
  "size": 20, 
  "aggs": {
    "g_num": {
      "sum": {
        "field": "g_num"
      }
    }
    
  },
  "sort": [
    {
      "id": "desc"
    },
    {
      "create_time": "desc"
    }
  ]
}

返回数据如下

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 18,
    "max_score" : null,
    "hits" : [
      {
        "_index" : "tms-pro-insurance-record-beta-1",
        "_type" : "_doc",
        "_id" : "88888_99",
        "_score" : null,
        "_source" : {
          "Order|b_tr_car_batch" : "A666001GX201200073",
          "create_time" : "2020-12-24 08:42:16",
          "company_id" : "44392",
          "od_link_id" : 152417298,
          "id" : "99",
          "order_num" : "A66600120120126",
          "b_basic_id" : "20249562",
          "uuid" : "88888_99",
          "od_id" : "105791251",
          "show_order_flags" : [
            "can_order_pickup"
          ]
        },
        "sort" : [
          "99"
        ]
      },
      {
        "_index" : "tms-pro-insurance-record-beta-1",
        "_type" : "_doc",
        "_id" : "88888_90",
        "_score" : null,
        "_source" : {
          "Order|b_tr_car_batch" : "A666001GX201200066",
          "create_time" : "2020-12-22 16:59:04",
          "company_id" : "44392",
          "od_link_id" : 152417272,
          "id" : "90",
          "order_num" : "A66600120120117",
          "b_basic_id" : "20249547",
          "uuid" : "88888_90",
          "od_id" : "105791226",
          "show_order_flags" : [
            "can_order_pickup"
          ]
        },
        "sort" : [
          "90"
        ]
      },
      {
        "_index" : "tms-pro-insurance-record-beta-1",
        "_type" : "_doc",
        "_id" : "88888_89",
        "_score" : null,
        "_source" : {
          "Order|b_tr_car_batch" : "A666001GX201200065",
          "create_time" : "2020-12-22 16:57:11",
          "company_id" : "44392",
          "od_link_id" : 152417271,
          "id" : "89",
          "order_num" : "A66600120120116",
          "b_basic_id" : "20249546",
          "uuid" : "88888_89",
          "od_id" : "105791225",
          "show_order_flags" : [ ]
        },
        "sort" : [
          "89"
        ]
      },
      {
        "_index" : "tms-pro-insurance-record-beta-1",
        "_type" : "_doc",
        "_id" : "88888_82",
        "_score" : null,
        "_source" : {
          "Order|b_tr_car_batch" : "A666001GX201200058",
          "create_time" : "2020-12-21 11:24:56",
          "company_id" : "44392",
          "od_link_id" : 152417231,
          "id" : "82",
          "order_num" : "A66600120120099",
          "b_basic_id" : "20249524",
          "uuid" : "88888_82",
          "od_id" : "105791197",
          "show_order_flags" : [
            "passed_om",
            "can_order_pickup"
          ]
        },
        "sort" : [
          "82"
        ]
      },
      {
        "_index" : "tms-pro-insurance-record-beta-1",
        "_type" : "_doc",
        "_id" : "88888_103",
        "_score" : null,
        "_source" : {
          "Order|b_tr_car_batch" : "A666001GX201200076",
          "create_time" : "2020-12-24 13:50:58",
          "company_id" : "44392",
          "od_link_id" : 152417304,
          "id" : "103",
          "order_num" : "A66600120120132",
          "b_basic_id" : "20249565",
          "uuid" : "88888_103",
          "od_id" : "105791257",
          "show_order_flags" : [
            "can_order_pickup"
          ]
        },
        "sort" : [
          "103"
        ]
      },
      {
        "_index" : "tms-pro-insurance-record-beta-1",
        "_type" : "_doc",
        "_id" : "88888_101",
        "_score" : null,
        "_source" : {
          "Order|b_tr_car_batch" : "A666001GX201200075",
          "create_time" : "2020-12-24 10:08:51",
          "company_id" : "44392",
          "od_link_id" : 152417302,
          "id" : "101",
          "order_num" : "A66600120120130",
          "b_basic_id" : "20249564",
          "uuid" : "88888_101",
          "od_id" : "105791255",
          "show_order_flags" : [
            "can_order_pickup"
          ]
        },
        "sort" : [
          "101"
        ]
      },
      {
        "_index" : "tms-pro-insurance-record-beta-1",
        "_type" : "_doc",
        "_id" : "88888_100",
        "_score" : null,
        "_source" : {
          "Order|b_tr_car_batch" : "A666001GX201200074",
          "create_time" : "2020-12-24 08:48:11",
          "company_id" : "44392",
          "od_link_id" : 152417300,
          "id" : "100",
          "order_num" : "A66600120120128",
          "b_basic_id" : "20249563",
          "uuid" : "88888_100",
          "od_id" : "105791253",
          "show_order_flags" : [
            "can_order_pickup"
          ]
        },
        "sort" : [
          "100"
        ]
      }
    ]
  },
  "aggregations" : {
    "g_num" : {
      "value" : 18.0
    }
  }
}

在id为keyword类型的情况下,根据id排序会按字符串排序,顺序和要求的不同,所以如果不按时间排序的话,可以以int类型字段排序

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值