在Elasticsearch中存储树的最佳结构? [英] Best structure for storing tree in Elasticsearch?

查看:553
本文介绍了在Elasticsearch中存储树的最佳结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Elasticsearch中存储一棵树。理论上,我的树可以无限长(尽管不太可能发生),并且可以相对频繁地分支。

I am trying to store a tree in Elasticsearch. My tree can theoretically be infinitely long (although that is unlikely to happen) and can branch relatively often.

存储此树的最佳方法是什么?

What is the best approach for storing this?

我调查了这个问题,但是分支时它的答案性能有限。有什么方法可以实现文档的正确嵌套,同时仍然具有分支的灵活性以及读取树及其节点时的整体性能?

I looked into this question but its answer has limited performance when branching. Is there any way I can achieve proper nesting of documents, while still having the flexibility of branching, and the overall performance when reading a tree and its nodes?

推荐答案

我非常建议以与Mongodb建议使用实体化路径类似的方式在ES中存储树

I very much recommend storing trees in ES in a similar fashion as Mongodb suggests using Materialized paths

只需将树中的每个节点存储为文档在索引内部,如果您有不同类型的节点,则可以创建一个类型字段并以此进行过滤。

Just store every node in the tree as a document inside an index, if you have different kinds of nodes you can just create a type field and filter by that.

将文档的路径以逗号形式存储在树中这样的分隔字符串:

Store the path of the document in the tree as a comma delimited string like this:

路径:',root,books,fiction'

path: ',root,books,fiction'

您以后可以使用文本搜索以搜索子树

you can later use text search to search in subtrees

有关更多详细信息,请参见此处的文档:
https://docs.mongodb.com/manual/tutorial/model-tree-structures-with-materialized-paths/

See the docs here for more details: https://docs.mongodb.com/manual/tutorial/model-tree-structures-with-materialized-paths/

这篇关于在Elasticsearch中存储树的最佳结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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