一、排序

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

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

POST /book/_search
{
"query": {
"match": {"description":"solr"}
}
}

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

POST /book/_search
{
"query": {
"match": {"description":"solr"}
},
"sort": [
{"_score": {"order": "asc"}}
]
}

|NO.Z.00025|————|BigDataEnd|——|Hadoop&ElasticSearch.V25|——|ELK.v25|集群|QueryDSL|排序|_浮点数_02

### --- 字段值排序

POST /book/_search
{
"query": {
"match_all": {}
},
"sort": [
{"price": {"order": "desc"}}
]
}

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

### --- 多级排序 假定我们想要结合使用 price和 timestamp(时间) 进行查询,

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

|NO.Z.00025|————|BigDataEnd|——|Hadoop&ElasticSearch.V25|——|ELK.v25|集群|QueryDSL|排序|_浮点数_04












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