ElasticSearch 7 搜索(9)排序查询
第一种排序查询 GET/POST请求
- 请求
localhost:9200/nba/_search
- 请求体
{
// 语义: 火箭队中按打球时间从大到小排序的球员
"query": {
"match": {
"teamName": "Rockets"
}
},
"sort": [
{
"playYear": {
"order": "desc"
}
}
],
"from": 0,
"size": 3
}
- 响应
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 21,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "nba",
"_type" : "_doc",
"_id" : "395",
"_score" : null,
"_source" : {
"countryEn" : "Brazil",
"teamName" : "火箭",
"birthDay" : 400737600000,
"country" : "巴西",
"teamCityEn" : "Houston",
"code" : "nene_hilario",
"displayAffiliation" : "Brazil",
"displayName" : "内内",
"schoolType" : "",
"teamConference" : "西部",
"teamConferenceEn" : "Western",
"weight" : "113.4 公斤",
"teamCity" : "休斯顿",
"playYear" : 17,
"jerseyNo" : "42",
"teamNameEn" : "Rockets",
"draft" : 2002,
"displayNameEn" : "Nene",
"heightValue" : 2.11,
"birthDayStr" : "1982-09-13",
"position" : "中锋-前锋",
"age" : 37,
"playerId" : "2403"
},
"sort" : [
17
]
},
{
"_index" : "nba",
"_type" : "_doc",
"_id" : "425",
"_score" : null,
"_source" : {
"countryEn" : "United States",
"teamName" : "火箭",
"birthDay" : 484200000000,
"country" : "美国",
"teamCityEn" : "Houston",
"code" : "chris_paul",
"displayAffiliation" : "Wake Forest/United States",
"displayName" : "克里斯 保罗",
"schoolType" : "College",
"teamConference" : "西部",
"teamConferenceEn" : "Western",
"weight" : "79.4 公斤",
"teamCity" : "休斯顿",
"playYear" : 14,
"jerseyNo" : "3",
"teamNameEn" : "Rockets",
"draft" : 2005,
"displayNameEn" : "Chris Paul",
"heightValue" : 1.83,
"birthDayStr" : "1985-05-06",
"position" : "后卫",
"age" : 34,
"playerId" : "101108"
},
"sort" : [
14
]
},
{
"_index" : "nba",
"_type" : "_doc",
"_id" : "206",
"_score" : null,
"_source" : {
"countryEn" : "United States",
"teamName" : "火箭",
"birthDay" : 507099600000,
"country" : "美国",
"teamCityEn" : "Houston",
"code" : "gerald_green",
"displayAffiliation" : "No College/United States",
"displayName" : "杰拉德 格林",
"schoolType" : "High School",
"teamConference" : "西部",
"teamConferenceEn" : "Western",
"weight" : "93.0 公斤",
"teamCity" : "休斯顿",
"playYear" : 12,
"jerseyNo" : "14",
"teamNameEn" : "Rockets",
"draft" : 2005,
"displayNameEn" : "Gerald Green",
"heightValue" : 2.01,
"birthDayStr" : "1986-01-26",
"position" : "后卫-前锋",
"age" : 33,
"playerId" : "101123"
},
"sort" : [
12
]
}
]
}
}
第一种排序查询 GET/POST请求
- 请求
localhost:9200/nba/_search
- 请求体
{
// 语义: 火箭队中按打球时间从大到小,如果年龄相同则按照身高从低到高排序的球员
"query": {
"match": {
"teamNameEn": "Rockets"
}
},
"sort": [
{
"playYear": {
"order": "desc"
}
},
{
"heightValue": {
"order": "asc"
}
}
],
"from": 0,
"size": 3
}
- 响应
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 21,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "nba",
"_type" : "_doc",
"_id" : "395",
"_score" : null,
"_source" : {
"countryEn" : "Brazil",
"teamName" : "火箭",
"birthDay" : 400737600000,
"country" : "巴西",
"teamCityEn" : "Houston",
"code" : "nene_hilario",
"displayAffiliation" : "Brazil",
"displayName" : "内内",
"schoolType" : "",
"teamConference" : "西部",
"teamConferenceEn" : "Western",
"weight" : "113.4 公斤",
"teamCity" : "休斯顿",
"playYear" : 17,
"jerseyNo" : "42",
"teamNameEn" : "Rockets",
"draft" : 2002,
"displayNameEn" : "Nene",
"heightValue" : 2.11,
"birthDayStr" : "1982-09-13",
"position" : "中锋-前锋",
"age" : 37,
"playerId" : "2403"
},
"sort" : [
17,
2.11
]
},
{
"_index" : "nba",
"_type" : "_doc",
"_id" : "425",
"_score" : null,
"_source" : {
"countryEn" : "United States",
"teamName" : "火箭",
"birthDay" : 484200000000,
"country" : "美国",
"teamCityEn" : "Houston",
"code" : "chris_paul",
"displayAffiliation" : "Wake Forest/United States",
"displayName" : "克里斯 保罗",
"schoolType" : "College",
"teamConference" : "西部",
"teamConferenceEn" : "Western",
"weight" : "79.4 公斤",
"teamCity" : "休斯顿",
"playYear" : 14,
"jerseyNo" : "3",
"teamNameEn" : "Rockets",
"draft" : 2005,
"displayNameEn" : "Chris Paul",
"heightValue" : 1.83,
"birthDayStr" : "1985-05-06",
"position" : "后卫",
"age" : 34,
"playerId" : "101108"
},
"sort" : [
14,
1.83
]
},
{
"_index" : "nba",
"_type" : "_doc",
"_id" : "206",
"_score" : null,
"_source" : {
"countryEn" : "United States",
"teamName" : "火箭",
"birthDay" : 507099600000,
"country" : "美国",
"teamCityEn" : "Houston",
"code" : "gerald_green",
"displayAffiliation" : "No College/United States",
"displayName" : "杰拉德 格林",
"schoolType" : "High School",
"teamConference" : "西部",
"teamConferenceEn" : "Western",
"weight" : "93.0 公斤",
"teamCity" : "休斯顿",
"playYear" : 12,
"jerseyNo" : "14",
"teamNameEn" : "Rockets",
"draft" : 2005,
"displayNameEn" : "Gerald Green",
"heightValue" : 2.01,
"birthDayStr" : "1986-01-26",
"position" : "后卫-前锋",
"age" : 33,
"playerId" : "101123"
},
"sort" : [
12,
2.01
]
}
]
}
}
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/12/elasticsearch-7-search-sort-query/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
THE END
0
二维码
打赏
海报
ElasticSearch 7 搜索(9)排序查询
第一种排序查询 GET/POST请求
请求
localhost:9200/nba/_search
请求体
{
// 语义: 火箭队中按打球时间从大到小排序的球员
"query": {
……
文章目录
关闭
共有 0 条评论