Best practice for handling many-to-many relationships in Elasticsearch?

后端 未结 1 745
[愿得一人]
[愿得一人] 2021-02-05 12:24

I\'m pretty sure I know the answer to this question but am looking for confirmation from someone with more Elasticsearch experience than me.

Let\'s say I\'ve got a datab

相关标签:
1条回答
  • 2021-02-05 13:04

    From your question I can safely assume that ES will not be your primary data-store. So the main question as to how to denormalise your many-to-many relationship is to figure out "how & what" will you use ES. That is what queries are you expected to build.

    Thinking of "query command" design and denormalize accordingly. Here are a few pointers:

    • denormalising Authors IDs into the book: would you expect a user to execute a search such as "all book for userId=XYZ". If not, you would rather need the name of the author as a multi-field in your Book document
    • duplicate, duplicate and duplicate. Figure out which data will be heavily updated (authors, as book general do not gain author after their publication). Denormalize author into books (names most likely). Duplicate (into another document type) something like "author_books" which will would be a child of authors and support update fairly often (again, denormalise the title and other relevant stuff to search from the author perspective).

    Hope this makes some sense ;)

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