默认情况下,是按照_score降序排序的
然而,某些情况下,可能没有用到_score,比如说filter
GET /_search { "query" : { "bool" : { "filter" : { "term" : { "author_id" : 1 } } } } }
当然,也可以是constant_score
GET /_search { "query" : { "constant_score" : { "filter" : { "term" : { "author_id" : 1 } } } } }2、定制排序规则
按照员工入职时间升序
GET /company/employee/_search { "query":{ "range":{ "age":{ "gte": 30 } } }, "sort": [{ "join_date":{ "order": "asc" } }] }
响应结果
{ "took": 15, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 2, "max_score": null, "hits": [ { "_index": "company", "_type": "employee", "_id": "3", "_score": null, "_source": { "address": { "country": "china", "province": "shanxi", "city": "xian" }, "name": "marry", "age": 35, "join_date": "2015-01-01" }, "sort": [ 1420070400000 ] }, { "_index": "company", "_type": "employee", "_id": "2", "_score": null, "_source": { "address": { "country": "china", "province": "jiangsu", "city": "nanjing" }, "name": "tom", "age": 30, "join_date": "2016-01-01" }, "sort": [ 1451606400000 ] } ] } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)