|NO.Z.00025|——————————|BigDataEnd|——|Hadoop&ElasticSearch.V25|——|ELK.v25|集群|QueryDSL|排序|

一、排序
### --- 相关性评分排序

~~~     默认情况下,返回的结果是按照 相关性 进行排序的——最相关的文档排在最前。 
~~~     首先看看 sort 参数以及如何使用它。
~~~     为了按照相关性来排序,需要将相关性表示为一个数值。
~~~     在 Elasticsearch 中, 相关性得分 由一个浮点数进行表示,
~~~     并在搜索结果中通过 _score 参数返回, 默认排序是 _score 降序,按照相关性评分升序排序如下
### --- 排序示例

POST /book/_search
{
"query": {
"match": {"description":"solr"}
}
}
POST /book/_search
{
"query": {
"match": {"description":"solr"}
},
"sort": [
{"_score": {"order": "asc"}}
]
}
### --- 字段值排序

POST /book/_search
{
"query": {
"match_all": {}
},
"sort": [
{"price": {"order": "desc"}}
]
}
### --- 多级排序 假定我们想要结合使用 price和 timestamp(时间) 进行查询,

~~~     并且匹配的结果首先按照价格排序,
~~~     然后按照相关性得分排序:
POST /book/_search
{
"query":{
"match_all":{}
},
"sort": [
{ "price": { "order": "desc" }},
{ "timestamp": { "order": "desc" }}
]
}

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(17)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示