如何在弹性搜索中对字符串字段进行排序。我需要坚持下去,但不能那样做。
我尝试通过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}
]
答案 0 :(得分:0)
尝试“丢失”:按“ _last”排序
GET testindex/_search
{
"sort": [
{
"url": {
"order": "asc",
"missing": "_last"
}
}
]
}
映射
PUT testindex3/_mapping
{
"properties": {
"url": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}