具有多个父/子关系的弹性搜索 [英] Elasticsearch with multiple parent/child relationship

查看:109
本文介绍了具有多个父/子关系的弹性搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Book,User and Review(书籍,用户和评论)说,我正在构建一个复杂模型的应用程序。



评论包含Book和User id。
为了能够搜索至少包含一个评论的图书,我已将Book设置为Review,并具有路由。但是,我还需要找到撰写包含某些短语的评论的用户。



是否可以将Book和User作为Review?有没有更好的方法来处理这种情况?



请注意,我无法更改数据建模/不愿意这样做的方式,因为数据被转移来自持久性数据库的弹性搜索。

解决方案

据我所知,您无法拥有两个父母的文档。 p>

我的建议是基于应用程序连接弹性搜索章节




  • 创建父/子关系预订 / 评论

  • 确保你有 user_id 属性在评论映射中,其中包含撰写该评论的用户标识。



我认为这两个用例描述如下:




  • 至少包含的书籍一个评论可以用h解决作为儿童过滤器 / 查询

  • 撰写包含某些短语的评论的用户可以通过使用要搜索的短语查询评论并执行<在场上的href =http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html =noreferrer>基数聚合 USER_ID 。如果您需要用户信息,您必须查询您的数据库(或其他弹性搜索索引),并检索ids。



编辑:给我本月由John写的用户评论的书籍



我建议您收集所有那些高级用例和非标准化您需要实现的数据。在这种特殊情况下,将用户名转换为 Review 就足够了。无论如何,弹性人物已经在管理关系他们的博客或< a href =http://www.elastic.co/guide/en/elasticsearch/guide/master/relations.html =noreferrer>弹性搜索最终指南


I'm building an application with complicated model, says Book, User and Review.

A Review contains both Book and User id. To be able to search for Books that contain at least one review, I've set the Book as Review's parent and have routing as such. However I also need to find Users who wrote reviews that contain certain phrases.

Is it possible to have both the Book and User as Review's parent? Is there a better way to handle such situation?

Note that I'm not able to change the way data is modeled/not willing to do so because the data is transfered to Elasticsearch from a persistence database.

解决方案

As far as I know you can't have a document with two parents.

My suggestion based on Application-side join chapter of Elasticsearch the definitive guide:

  • Create a parent/child relationship Book/Review
  • Be sure you have user_id property in Review mapping which contain the user id who wrote that review.

I think that covers both uses cases you described as follows:

  • Books that contain at least one review It can be solved with has child filter/query
  • Users who wrote reviews that contain certain phrases It can be solved by querying to reviews with the phrase you want to search and perform a cardinality aggregation on field user_id. If you need users information you have to query your database (or another elasticsearch index) with the ids retrieved.

Edit: "give me the books that have reviews this month written by user whose name started with John"

I recommend you to collect all those advanced uses cases and denormalize the data you need to achieve them. In this particular case it's enough with denormalizing the user name into Review. In any case elasticsearch people has written about managing relations in their blog or elasticsearch the definitive guide

这篇关于具有多个父/子关系的弹性搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆