java - 如何使用 Elastic 对 Null 进行最后排序?
问题描述
如何在弹性搜索中对字符串字段进行排序。我需要把它放在最后,但不能那样做。
我尝试按 ASC 进行排序,但它不起作用
例子:
[
{"url":"https://amazon"},
{"url":"https://amazon"},
{"url":null},
{"url":"https://amazon"}
]
我的代码:
sourceBuilder = sourceBuilder.sort("url", SortOrder.ASC)
并使用我的代码我得到相同的
I expect to see:
[
{"url":"https://amazon"},
{"url":"https://amazon"},
{"url":"https://amazon"},
{"url":null}
]
解决方案
尝试 "missing": "_last" 排序
GET testindex/_search
{
"sort": [
{
"url": {
"order": "asc",
"missing": "_last"
}
}
]
}
映射
PUT testindex3/_mapping
{
"properties": {
"url": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
推荐阅读
- c - 在结构内部定义结构指针
- python - 如何用这种形状的 python 和 pandas 堆叠数据?
- ruby - Capistorano 部署 SSHKit::Runner::ExecuteError:rake 退出状态:1
- python - 如何将日期时间转换为日期?
- swift - 根据数组中的项目数迭代创建 UITextView
- javascript - 在浏览器中本地通过 DirectShow 播放 Videograbber 输入
- ajax - 使用邮递员 404 端点发现 api 身份验证
- javascript - 尝试从我的 S3 存储桶访问文件时在我的 Node.js 应用程序中获取“禁止:null”
- c# - 如果要删除某些元素,如何迭代 JObject?
- r - 我有 2 个数据框,每个数据框都有纬度和经度。我想为 df1 中的每个点找到离 df2 最近的 5 个点