# Modeling indices to mimic many to one relationships

**URL:** https://discuss.elastic.co/t/modeling-indices-to-mimic-many-to-one-relationships/133237
**Category:** Elasticsearch
**Created:** [May 25, 2018, 2:38am UTC](https://discuss.elastic.co/t/modeling-indices-to-mimic-many-to-one-relationships/133237 "2018-05-25T02:38:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![andyhoang](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@andyhoang](https://discuss.elastic.co/u/andyhoang)
#### Post date: [May 25, 2018, 2:38am UTC](https://discuss.elastic.co/t/modeling-indices-to-mimic-many-to-one-relationships/133237/1 "2018-05-25T02:38:11Z")

</div>

Hi, I doing sync data to es 6.2 from postgres database and got some trouble modeling it. I have this situation:  
3 models A, B, C  
We want to search field from that 3 model and has result as model B look alike. Those are have relationship as A(1) - B(n), C(1) - B(n).  
So if I have a text 'andy' from all 3 model the result would be:

- all result of B that has text 'andy',
- all result of B "belong to" A which has text 'andy'
- all result of B "belong to" C which has text 'andy'

How I should modeling my indices so that I can search and paginate the result?

Right now I model it as one index: A as parent, B as Child, C is stored nested in B. It work quite ok with inner hit query. It has some cons relate to concurrent sync data.

But I'm wonder if is there any better way to do this (and how to update docs data)

---

<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: [May 25, 2018, 5:24am UTC](https://discuss.elastic.co/t/modeling-indices-to-mimic-many-to-one-relationships/133237/2 "2018-05-25T05:24:40Z")

</div>

What is the size of these entities and the expected cardinality between them? How frequently are they updated?

---

<div class="post-metadata">

### Author: ![andyhoang](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@andyhoang](https://discuss.elastic.co/u/andyhoang)
#### Post date: [May 25, 2018, 6:28am UTC](https://discuss.elastic.co/t/modeling-indices-to-mimic-many-to-one-relationships/133237/3 "2018-05-25T06:28:44Z")

</div>

- The size is around 50kb (I dump them as json string and calculate using getsize)
- The cardinal is around \<20 at this moment: 1 A has max 20 B, 1 C has max 5 B
- They got update frequently, especially C. B will be updated when C is updated but it is not follow the order C first then B

Thanks.

---

<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: [June 22, 2018, 6:28am UTC](https://discuss.elastic.co/t/modeling-indices-to-mimic-many-to-one-relationships/133237/4 "2018-06-22T06:28:54Z")

</div>

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