# How to correctly store the parent/child structure in the ES

**URL:** https://discuss.elastic.co/t/how-to-correctly-store-the-parent-child-structure-in-the-es/16621
**Category:** Elasticsearch
**Created:** [March 26, 2014, 5:55pm UTC](https://discuss.elastic.co/t/how-to-correctly-store-the-parent-child-structure-in-the-es/16621 "2014-03-26T17:55:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![11144](https://avatars.discourse-cdn.com/v4/letter/1/c2a13f/32.png) [@11144](https://discuss.elastic.co/u/11144)
#### Post date: [March 26, 2014, 5:55pm UTC](https://discuss.elastic.co/t/how-to-correctly-store-the-parent-child-structure-in-the-es/16621/1 "2014-03-26T17:55:29Z")

</div>

Hi,

I have the next structure in my mysql database.

[https://lh4.googleusercontent.com/-UZJmzHN7BLM/UzMSK5WNrSI/AAAAAAAAAlY/I1lfQfw-IR8/s1600/Screen+Shot+2014-03-26+at+7.44.46+PM.png](https://lh4.googleusercontent.com/-UZJmzHN7BLM/UzMSK5WNrSI/AAAAAAAAAlY/I1lfQfw-IR8/s1600/Screen+Shot+2014-03-26+at+7.44.46+PM.png)

What I want to do is to copy the content of the database to the  
elasticsearch server. Main goal is to search through the transactions and  
use the facets option.

Kind of this (currently it's implemented using the mysql):

[https://lh6.googleusercontent.com/-v-vR0z7g98k/UzMSsZABwaI/AAAAAAAAAlg/Kt\_AuN2Lhe4/s1600/Screen+Shot+2014-03-26+at+7.46.55+PM.png](https://lh6.googleusercontent.com/-v-vR0z7g98k/UzMSsZABwaI/AAAAAAAAAlg/Kt_AuN2Lhe4/s1600/Screen+Shot+2014-03-26+at+7.46.55+PM.png)

The issue is - how should I store the documents in the elasticsearch, so  
they are reindexed quickly.  
In the future, I would need to update the ES index as soon as transaction  
or bank\_account data is updated.

I've checked all the available options of the  
ES [http://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/](http://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/)  
and decided to use the parent/child one.  
I've created one index and two types - transaction and bank\_account. Where  
the transaction is the child of the bank\_account.

_But there are open questions:_

_1._ How could I query the ES, using the "has\_parent" option so it would  
return not only the childs but the information about the parent also.  
In the results I need to receive the object where the fields country,  
currency and name would be available.  
Currently I've managed to receive only the \_source fields from the  
transaction and the \_parent field which is the id of the bank account

_2._ How should I query the ES to receive the facets on the fields country,  
currency and name?

_3._ Which other structure could I use so the reindexing is happening  
quickly? The case is that I have 160000 transactions and 20 banks. If I  
would store the information about the bank directly in the transaction  
object, that means that if I would change the country of the bank, then I  
would need to reindex nearly 40000 documents (for example). Which is not  
acceptable.

I'm also not able to use the "nested object" concept - to store the  
transactions inside the bank account, because that way I would not be able  
to insert the transactions to that bank dynamically, each new insert would  
also cause the reindexing of the whole document.

Any thoughts?

Regards,

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6a0fba83-6e0b-4e0d-aefd-b66bca5fded3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6a0fba83-6e0b-4e0d-aefd-b66bca5fded3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![11144](https://avatars.discourse-cdn.com/v4/letter/1/c2a13f/32.png) [@11144](https://discuss.elastic.co/u/11144)
#### Post date: [March 27, 2014, 10:00am UTC](https://discuss.elastic.co/t/how-to-correctly-store-the-parent-child-structure-in-the-es/16621/2 "2014-03-27T10:00:54Z")

</div>

Still interesting to get your opinion about the question.

среда, 26 марта 2014 г., 19:55:29 UTC+2 пользователь Павел Поляков написал:

> Hi,
> 
> I have the next structure in my mysql database.
> 
> [https://lh4.googleusercontent.com/-UZJmzHN7BLM/UzMSK5WNrSI/AAAAAAAAAlY/I1lfQfw-IR8/s1600/Screen+Shot+2014-03-26+at+7.44.46+PM.png](https://lh4.googleusercontent.com/-UZJmzHN7BLM/UzMSK5WNrSI/AAAAAAAAAlY/I1lfQfw-IR8/s1600/Screen+Shot+2014-03-26+at+7.44.46+PM.png)
> 
> What I want to do is to copy the content of the database to the  
> elasticsearch server. Main goal is to search through the transactions and  
> use the facets option.
> 
> Kind of this (currently it's implemented using the mysql):
> 
> [https://lh6.googleusercontent.com/-v-vR0z7g98k/UzMSsZABwaI/AAAAAAAAAlg/Kt\_AuN2Lhe4/s1600/Screen+Shot+2014-03-26+at+7.46.55+PM.png](https://lh6.googleusercontent.com/-v-vR0z7g98k/UzMSsZABwaI/AAAAAAAAAlg/Kt_AuN2Lhe4/s1600/Screen+Shot+2014-03-26+at+7.46.55+PM.png)
> 
> The issue is - how should I store the documents in the elasticsearch, so  
> they are reindexed quickly.  
> In the future, I would need to update the ES index as soon as transaction  
> or bank\_account data is updated.
> 
> I've checked all the available options of the ES  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/and) decided to use the parent/child one.  
> I've created one index and two types - transaction and bank\_account. Where  
> the transaction is the child of the bank\_account.
> 
> _But there are open questions:_
> 
> _1._ How could I query the ES, using the "has\_parent" option so it would  
> return not only the childs but the information about the parent also.  
> In the results I need to receive the object where the fields country,  
> currency and name would be available.  
> Currently I've managed to receive only the \_source fields from the  
> transaction and the \_parent field which is the id of the bank account
> 
> _2._ How should I query the ES to receive the facets on the fields  
> country, currency and name?
> 
> _3._ Which other structure could I use so the reindexing is happening  
> quickly? The case is that I have 160000 transactions and 20 banks. If I  
> would store the information about the bank directly in the transaction  
> object, that means that if I would change the country of the bank, then I  
> would need to reindex nearly 40000 documents (for example). Which is not  
> acceptable.
> 
> I'm also not able to use the "nested object" concept - to store the  
> transactions inside the bank account, because that way I would not be able  
> to insert the transactions to that bank dynamically, each new insert would  
> also cause the reindexing of the whole document.
> 
> Any thoughts?
> 
> Regards,

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/21d4dfbb-eafd-4556-9087-7c01d2772b3a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/21d4dfbb-eafd-4556-9087-7c01d2772b3a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:40am UTC](https://discuss.elastic.co/t/how-to-correctly-store-the-parent-child-structure-in-the-es/16621/3 "2017-07-06T01:40:17Z")

</div>


