Best structure for storing tree in Elasticsearch?

前端 未结 1 666
无人及你
无人及你 2021-02-08 19:20

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

相关标签:
1条回答
  • 2021-02-08 19:46

    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:

    path: ',root,books,fiction'

    you can later use text search to search in subtrees

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

    0 讨论(0)
提交回复
热议问题