Elasticsearch7.8.0版本高级查询—— 单字段排序文档
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |
目录
一、初始化文档数据
-
在 Postman 中向 ES 服务器发 POST 请求 http://localhost:9200/user/_doc/1请求体内容为
{ "name":"zhangsan", "age":20, "sex":"男" }
-
在 Postman 中向 ES 服务器发 POST 请求 http://localhost:9200/user/_doc/2请求体内容为
{ "name":"zhangsan1", "age":21, "sex":"男" }
-
在 Postman 中向 ES 服务器发 POST 请求 http://localhost:9200/user/_doc/3请求体内容为
{ "name":"zhangsan2", "age":22, "sex":"男" }
-
在 Postman 中向 ES 服务器发 POST 请求 http://localhost:9200/user/_doc/4请求体内容为
{ "name":"lisi", "age":25, "sex":"女" }
二、单字段排序文档
2.1、概述
sort
可以让我们按照不同的字段进行排序并且通过order
指定排序的方式。desc 降序asc升序。
2.2、示例
-
在 Postman 中向 ES 服务器发 GET请求 http://localhost:9200/user/_search请求体内容为
{ "query": { "fuzzy": { "name": { "value": "zhangsan" } } }, "sort": [{ "age": { "order":"asc" } }] }
-
服务器响应结果