在 Elastic Search 中加入两个索引,如 table 加入

Joining two indexes in Elastic Search like a table join

我对这个弹性搜索比较陌生。所以,我有一个名为 post 的索引,其中包含如下文档:

{
"id": 1,
"link": "https:www.instagram.com/p/XXXXX/",
"profile_id": 11,
"like_count": 100,
"comment_count": 12
}

我有另一个名为 profile 的索引,其中包含如下文档:

{
"id": 11,
"username": "superman",
"name": "Superman",
"followers": 12312
}

因此,正如你们所见,我在名为 profile 的索引下拥有所有配置文件数据,并且所有 post索引下的数据名为post。 post 文档中的 "profile_id""id" 存在于配置文件中。

有什么办法吗,当我查询 post 索引并过滤掉 post 文档时,配置文件数据也会与 post 文档一起出现,基于 "profile_id" 出现在 post 文件中?或者以某种方式获取这两个数据进行多索引搜索?

提前谢谢你们,任何帮助将不胜感激。

为了性能,Elasticsearch 鼓励您对数据进行非规范化,并根据您希望从查询中获得的响应对文档进行建模。但是,对于您的情况,我建议使用 Join 数据类型(link 到 Elastic documentation) and using the parent-join queries to run your searches (link to Elastic documentation)来定义关系 post-profile。