美文网首页
简单粗暴的按照一个或者多个字段排序

简单粗暴的按照一个或者多个字段排序

作者: zz云飞扬 | 来源:发表于2019-12-12 15:48 被阅读0次

es 官网doc地址:https://www.elastic.co/guide/en/elasticsearch/reference/6.5/search-request-sort.html

1、两个值的数字字段按照平均值排序

PUT /my_index/_doc/1?refresh

{

  "product": "chocolate",

  "price": [20, 4]

}

POST my_index//_search

{

  "query" : {

      "term" : { "product" : "chocolate" }

  },

  "sort" : [

      {"price" : {"order" : "asc", "mode" : "avg"}}

  ]

}

mode 可选择项有min,max,sum,avg,median

价格平均值排序

2、按照日期排序,日期相同按照"user"字段排序,多个排序字段举例

多个排序字段

相关文章

网友评论

      本文标题:简单粗暴的按照一个或者多个字段排序

      本文链接:https://www.haomeiwen.com/subject/qwdtnctx.html