# M:N - Search and pagination combination

**URL:** <https://discuss.elastic.co/t/m-n-search-and-pagination-combination/88884>\
**Category:** Elasticsearch\
**Created:** [June 9, 2017, 6:59pm UTC](https://discuss.elastic.co/t/m-n-search-and-pagination-combination/88884 "2017-06-09T18:59:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akshata\_S](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@Akshata\_S](https://discuss.elastic.co/u/Akshata_S)\
**Post date:** [June 9, 2017, 6:59pm UTC](https://discuss.elastic.co/t/m-n-search-and-pagination-combination/88884/1 "2017-06-09T18:59:03Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 10, 2017, 8:22am UTC](https://discuss.elastic.co/t/m-n-search-and-pagination-combination/88884/2 "2017-06-10T08:22:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Akshata\_S](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@Akshata\_S](https://discuss.elastic.co/u/Akshata_S)\
**Post date:** [June 10, 2017, 11:09am UTC](https://discuss.elastic.co/t/m-n-search-and-pagination-combination/88884/3 "2017-06-10T11:09:10Z")

</div>

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]}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 8, 2017, 11:09am UTC](https://discuss.elastic.co/t/m-n-search-and-pagination-combination/88884/4 "2017-07-08T11:09:23Z")

</div>

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