gpt4 book ai didi

java - 如何使用 Elastic 对最后的 Null 进行排序?

转载 作者:太空宇宙 更新时间:2023-11-04 09:34:41 24 4
gpt4 key购买 nike

如何在 Elasticsearch 中对字符串字段进行排序。我需要把它放在最后,但不能这样做。

我尝试按 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
}
}
}
}
}

关于java - 如何使用 Elastic 对最后的 Null 进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56651347/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com