在弹性搜索中,多个顶级文档可以共享单个嵌套文档吗? [英] In Elasticsearch, can multiple top-level documents share a single nested document?

查看:191
本文介绍了在弹性搜索中,多个顶级文档可以共享单个嵌套文档吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

弹性搜索有嵌套文档(很棒)。我想使用它来存储消息(顶级文档)及其作者(嵌套文档)。



由于一个作者可以有很多消息 - 可以作者的一个版本被引用为多个消息的子节点



这样一来,如果您在一个地方更新作者数据,那么它将被引用到任何地方。



注意:这与:如何加入Elasticsearch或Lucene级别 - 这里的答案可能也会解决。

解决方案

您可能需要使用 _parent 映射来查看: http://www.elasticsearch.org/guide/en/elasticsearch/ reference / current / mapping-parent-field.html



这允许你为作者创建一个类型,另一个为Message类型(具有_parent类型的作者),然后分别索引文档,并随着时间添加到消息中。您只需要更新作者的单一版本,以影响与该作者的所有邮件的查询。



要实现与特定作者的邮件查询,您将需要使用has_parent查询或过滤器。或者反过来,使用has_child来查找具有某些消息的作者。




  • has_child导致父文件中有与查询匹配的子文档

  • has_parent结果在孩子中具有与查询匹配的父文档的文档



我一直使用这种更动态的表单而不是嵌套的文档,并且运行良好对于我来说(对于查询和方面),但是在加载该类型的任何文档之前,您必须注意定义映射,因为事实之后添加 _parent 映射似乎为我工作并且重建是迄今为止我没有管理的东西。


Elasticsearch has nested documents (great). I'd like to use this to store Messages (top-level document) and their Authors (nested document).

Since one author can have many many messages -- can one version of the Author be referenced as the child of multiple Messages?

That way, if you update the Author data in one place, it would update everywhere they're referenced.

NB: This is related to: How to do a join in Elasticsearch -- or at the Lucene level -- an answer here might solve that too.

解决方案

You may want to take a look using a _parent mapping: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-parent-field.html

This allows you to create a type for an Author and a separate type for a Message (with _parent type of Author), then index documents separately and add to the messages over time. You only need to update the single version of an Author for it to affect queries for all messages with that Author.

To achieve queries of messages with a specific author you'll need to use the has_parent query or filter. Or the reverse, use has_child to find authors with certain messages.

  • has_child results in parent documents that have child documents that match the query
  • has_parent results in child documents that have the parent documents that match the query

I have been using this more dynamic form rather than nested documents and it has worked well for me (for both queries and facets), but you must take care defining your mappings before loading any documents of that type, since adding the _parent mapping after the fact doesn't seem to work for me. And reindexing has been something I have failed to manage so far.

这篇关于在弹性搜索中,多个顶级文档可以共享单个嵌套文档吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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