Elasticsearch 查询结果排序
Elasticsearch 查询结果排序,部分内容来自 B 站中华石杉 Elasticsearch 顶尖高手系列课程核心知识篇,英文内容来自官方文档。
默认排序规则
默认情况下,是按照_score 降序排序的
然而,某些情况下,可能没有有用的_score,比如说 filter
当然,也可以是 constant_score
定制排序规则
Sort search results
Allows you to add one or more sorts on specific fields. Each sort can be reversed as well. The sort is defined on a per field level, with special field name for _score to sort by score, and _doc to sort by index order.
Sort Values
The sort values for each document returned are also returned as part of the response.
Sort mode example usage
Memory Considerations
When sorting, the relevant sorted field values are loaded into memory. This means that per shard, there should be enough memory to contain them. For string based types, the field sorted on should not be analyzed / tokenized. For numeric types, if possible, it is recommended to explicitly set the type to narrower types(like short, integer and float).
版权声明: 本文为 InfoQ 作者【escray】的原创文章。
原文链接:【http://xie.infoq.cn/article/ad0ae604f0572a1e209bc12fc】。
本文遵守【CC-BY 4.0】协议,转载请保留原文出处及本版权声明。
评论