我有一些相关字段的数据;这是一个与我的索引相关的例子
用户索引
[
{
"id": "user_1",
"name": "xxx",
},
{
"id": "user_2",
"name": "xxx",
},
{
"id": "user_3",
"name": "xxx",
},
{
"id": "user_4",
"name": "xxx",
}
]
职位索引
[
{
"id": "post_1",
"title": "xxx",
"user_id": "user_1",
"created": "10-2-2022"
},
{
"id": "post_2",
"title": "xxx",
"user_id": "user_3",
"created": "11-2-2022"
},
{
"id": "post_3",
"title": "xxx",
"user_id": "user_1",
"created": "9-2-2022"
}
]
我想根据帖子created
的日期对users
进行排序。
我要的desc
结果
[
{
"id": "user_3" # Given that they have to most recent post `post_2`
},
{
"id": "user_1"
},
{
"id": "user_2"
},
{
"id": "user_4"
}
]
注:user_2
& user_4
有0个帖子,但被添加在结果的末尾。
如何最佳地实现这一点?
1条答案
按热度按时间c7rzv4ha1#
这在ElasticSearch中是不可能的。
ElasticSearch没有连接的概念。您需要将数据反规范化。将所有数据放在一起。您可以浏览parent/child或nested fields。