M:N - Search and pagination combination

I have been learning to work with elasticsearch recently and had a design question about a typical scenario ?

M:N relation between Author and Books

Author1 -> Book1 and Book2
Author2 -> Book1 and Book3

Book1 - is titled “Mathematics”
Book2 - is titled “Biology”
Book3 - is titled “Chemistry”

Search all books that contain name “Biology” written by “Author1” but return them in batches of 50 (using from and size in the query)

What would be the ideal way to implement indexing for this of search/pagination in Elasticsearch ?

As the author of a book and potential details of an author probably changes infrequently (if ever) I think your best option might be to denormalise the data model and store information about the authors with each book in a flat data model. This should make it easy to query and paginate.

Thank you for the reply.

Just to clarify, would it be better to store them as nested objects like so ?

Author1 - Nested object {[Book1, Book2]}
Author2 - Nested object {[Book1, Book3]}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.