是否可以在 Elasticsearch (Opensearch) 中按值的子字符串排序?
假设我有这些文档:
[
{
"_index" : "index_name",
"_type" : "_doc",
"_id" : "some_obj.{RANDOM UUID}:{REAL ID}",
"_source" : {
"id" : "some_obj.{RANDOM UUID}:{REAL ID}",
"parent_id": "{SOME ID}"
"name" : "{some name}"
}
},
{ ... }
]
我尝试使用查询获取这些对象:
GET index_name/_search
{
"sort" : [
{ "id": {"order": "asc"}}
],
"query": {
"terms": {
"parent_id": [ "1" ]
}
}
}
由于 id
字段中间有 {RANDOM UUID}
我无法按 < code>{REAL ID}
是否可以删除 some_obj.{RANDOM UUID}:
部分进行排序或按 :
拆分它并使用第二部分进行排序或其他一些能够排序的方式{真实身份}
?
Let's say I have these documents:
[
{
"_index" : "index_name",
"_type" : "_doc",
"_id" : "some_obj.{RANDOM UUID}:{REAL ID}",
"_source" : {
"id" : "some_obj.{RANDOM UUID}:{REAL ID}",
"parent_id": "{SOME ID}"
"name" : "{some name}"
}
},
{ ... }
]
I trying to get these objects by using query:
GET index_name/_search
{
"sort" : [
{ "id": {"order": "asc"}}
],
"query": {
"terms": {
"parent_id": [ "1" ]
}
}
}
Because of {RANDOM UUID}
in the middle of id
field I can't order by {REAL ID}
Is it possible to remove some_obj.{RANDOM UUID}:
part for sorting or split it by :
and use second part for sorting or some another way to be able sort by {REAL ID}
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下查询应该这样做。我假设
id
您的映射中的字段是keyword
和{真实ID}
是数字。如果是字符串,则应将查询中的类型
更改为string
,然后从返回语句中删除long.parse
。Following query should do it. I assumed
id
field in your mapping iskeyword
and{REAL ID}
is numeric. If it is a string, you should changetype
in the query tostring
and removeLong.parse
from the return statement.