小智 7
如果我很好地理解你的问题,我尝试在 ES 7.8 版本上进行本地测试,并在索引中提取了以下数据:
"content": "这是一个测试", "trusted": true
"content": "这是一个新测试", "trusted": true
"content": "这不是测试", "trusted": false
这是索引的映射:
"mappings" : {
"properties" : {
"content" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"trusted" : {
"type" : "boolean"
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是以下情况下的查询"order" : "desc":
{
"sort": [
{
"trusted": {
"order": "desc"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
响应:
"hits" : [
{
"_index" : "boolean-sorting",
"_type" : "_doc",
"_id" : "B-YleHQBsTCl1BZvrFdA",
"_score" : null,
"_source" : {
"content" : "This is a test",
"trusted" : true
},
"sort" : [
1
]
},
{
"_index" : "boolean-sorting",
"_type" : "_doc",
"_id" : "CeYleHQBsTCl1BZvtFdJ",
"_score" : null,
"_source" : {
"content" : "This is a new test",
"trusted" : true
},
"sort" : [
1
]
},
{
"_index" : "boolean-sorting",
"_type" : "_doc",
"_id" : "DOYleHQBsTCl1BZvvVfl",
"_score" : null,
"_source" : {
"content" : "This is not a test",
"trusted" : false
},
"sort" : [
0
]
}
]
Run Code Online (Sandbox Code Playgroud)
当 时"order":"asc",响应为:
"hits" : [
{
"_index" : "boolean-sorting",
"_type" : "_doc",
"_id" : "DOYleHQBsTCl1BZvvVfl",
"_score" : null,
"_source" : {
"content" : "This is not a test",
"trusted" : false
},
"sort" : [
0
]
},
{
"_index" : "boolean-sorting",
"_type" : "_doc",
"_id" : "B-YleHQBsTCl1BZvrFdA",
"_score" : null,
"_source" : {
"content" : "This is a test",
"trusted" : true
},
"sort" : [
1
]
},
{
"_index" : "boolean-sorting",
"_type" : "_doc",
"_id" : "CeYleHQBsTCl1BZvtFdJ",
"_score" : null,
"_source" : {
"content" : "This is a new test",
"trusted" : true
},
"sort" : [
1
]
}
]
Run Code Online (Sandbox Code Playgroud)
链接: https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html
如果我回答错误,请告诉我,我很乐意提供帮助。
| 归档时间: |
|
| 查看次数: |
4083 次 |
| 最近记录: |