# Best practice to design index/type for Elasticsearch

**URL:** <https://discuss.elastic.co/t/best-practice-to-design-index-type-for-elasticsearch/18635>\
**Category:** Elasticsearch\
**Created:** [July 14, 2014, 12:03am UTC](https://discuss.elastic.co/t/best-practice-to-design-index-type-for-elasticsearch/18635 "2014-07-14T00:03:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ranjith\_Sundaraj\_Cha](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@Ranjith\_Sundaraj\_Cha](https://discuss.elastic.co/u/Ranjith_Sundaraj_Cha)\
**Post date:** [July 14, 2014, 12:03am UTC](https://discuss.elastic.co/t/best-practice-to-design-index-type-for-elasticsearch/18635/1 "2014-07-14T00:03:54Z")

</div>

Hi,  
I am a newbie to elasticsearch. I am planning to use elasticsearch for just  
search and leave oracle DB to hold the canonical data.

_Requirement :_ To provide search functionality on the 'application forms'  
submitted to our system. Our 'application forms' can have many 'items'  
associated with it (one to many).  
We have to provide 2 searches, one that fetches 'application form' level  
data and the other fetches 'item' level data. Both will have similar search  
criteria.

_Options 1:_  
I can create 2 indices with different json document structure. First index  
will have the 'application form' as the parent and all 'items' as its child  
(similar to its canonical structure), Second index will reverse the  
hierarchy and have 'item' as the parent and all the 'application form'  
attributes associated to it.  
\*Cons: \*  
Data is duplicated in 2 indices.

_Option 2:_  
Create one index similar to canonical structure and support both the search  
requirement.  
\*Cons : \*  
I have to write code to process and massage the data for returning the  
results at 'item' level.

_Question:_

1. Which option is preferable and why.
2. Is there a better solution to handle this scenario.
3. If I opt for option 1 - do I need to create 2 JDBC river component to  
update data in both the elasticsearch indices.  
or  
should I write one JDBC river component and update both the indices.

Appreciate your inputs.

--  
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/92702ef1-4fd1-45a6-a4b2-eb0cbd8c3aad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/92702ef1-4fd1-45a6-a4b2-eb0cbd8c3aad%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [July 14, 2014, 7:05am UTC](https://discuss.elastic.co/t/best-practice-to-design-index-type-for-elasticsearch/18635/2 "2014-07-14T07:05:23Z")

</div>

Regarding the JDBC river, it depends how many data sources you have. If you  
have one for form fields and one for form values, you should use two  
instances. If you can use a single SQL select for both form fields and  
values, one river instance should be sufficient.

Beside, you do not need parent/child or two indices if one index with two  
mappings should work where you can follow reference IDs to get additional  
attributes.

Jörg

On Mon, Jul 14, 2014 at 2:03 AM, Ranjith Sundaraj Chandra \<  
[scranjith.work@gmail.com](mailto:scranjith.work@gmail.com)\> wrote:

> Hi,  
> I am a newbie to elasticsearch. I am planning to use elasticsearch for  
> just search and leave oracle DB to hold the canonical data.
> 
> _Requirement :_ To provide search functionality on the 'application  
> forms' submitted to our system. Our 'application forms' can have many  
> 'items' associated with it (one to many).  
> We have to provide 2 searches, one that fetches 'application form' level  
> data and the other fetches 'item' level data. Both will have similar search  
> criteria.
> 
> _Options 1:_  
> I can create 2 indices with different json document structure. First index  
> will have the 'application form' as the parent and all 'items' as its child  
> (similar to its canonical structure), Second index will reverse the  
> hierarchy and have 'item' as the parent and all the 'application form'  
> attributes associated to it.  
> \*Cons: \*  
> Data is duplicated in 2 indices.
> 
> _Option 2:_  
> Create one index similar to canonical structure and support both the  
> search requirement.  
> \*Cons : \*  
> I have to write code to process and massage the data for returning the  
> results at 'item' level.
> 
> _Question:_
> 
> 1. Which option is preferable and why.
> 2. Is there a better solution to handle this scenario.
> 3. If I opt for option 1 - do I need to create 2 JDBC river component to  
> update data in both the elasticsearch indices.  
> or  
> should I write one JDBC river component and update both the indices.
> 
> Appreciate your inputs.
> 
> --  
> 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/92702ef1-4fd1-45a6-a4b2-eb0cbd8c3aad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/92702ef1-4fd1-45a6-a4b2-eb0cbd8c3aad%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/92702ef1-4fd1-45a6-a4b2-eb0cbd8c3aad%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/92702ef1-4fd1-45a6-a4b2-eb0cbd8c3aad%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAKdsXoE%3DkFigz43zn0UGBG1JWRu8zy4kPCrAFTus8BBZ4yTF0w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoE%3DkFigz43zn0UGBG1JWRu8zy4kPCrAFTus8BBZ4yTF0w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ranjith\_Sundaraj\_Cha](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@Ranjith\_Sundaraj\_Cha](https://discuss.elastic.co/u/Ranjith_Sundaraj_Cha)\
**Post date:** [July 14, 2014, 9:39pm UTC](https://discuss.elastic.co/t/best-practice-to-design-index-type-for-elasticsearch/18635/3 "2014-07-14T21:39:20Z")

</div>

Thanks Jorg,  
I will try this out and get back.  
meanwhile if you have a sample to create the mapping at the 'item' level,  
please share it.

Thanks,  
Ranjith

On Monday, July 14, 2014 3:05:32 AM UTC-4, Jörg Prante wrote:

> Regarding the JDBC river, it depends how many data sources you have. If  
> you have one for form fields and one for form values, you should use two  
> instances. If you can use a single SQL select for both form fields and  
> values, one river instance should be sufficient.
> 
> Beside, you do not need parent/child or two indices if one index with two  
> mappings should work where you can follow reference IDs to get additional  
> attributes.
> 
> Jörg
> 
> On Mon, Jul 14, 2014 at 2:03 AM, Ranjith Sundaraj Chandra \<  
> [scranji...@gmail.com](mailto:scranji...@gmail.com) \<javascript:\>\> wrote:
> 
> > Hi,  
> > I am a newbie to elasticsearch. I am planning to use elasticsearch for  
> > just search and leave oracle DB to hold the canonical data.
> > 
> > _Requirement :_ To provide search functionality on the 'application  
> > forms' submitted to our system. Our 'application forms' can have many  
> > 'items' associated with it (one to many).  
> > We have to provide 2 searches, one that fetches 'application form' level  
> > data and the other fetches 'item' level data. Both will have similar search  
> > criteria.
> > 
> > _Options 1:_  
> > I can create 2 indices with different json document structure. First  
> > index will have the 'application form' as the parent and all 'items' as its  
> > child (similar to its canonical structure), Second index will reverse the  
> > hierarchy and have 'item' as the parent and all the 'application form'  
> > attributes associated to it.  
> > \*Cons: \*  
> > Data is duplicated in 2 indices.
> > 
> > _Option 2:_  
> > Create one index similar to canonical structure and support both the  
> > search requirement.  
> > \*Cons : \*  
> > I have to write code to process and massage the data for returning the  
> > results at 'item' level.
> > 
> > _Question:_
> > 
> > 1. Which option is preferable and why.
> > 2. Is there a better solution to handle this scenario.
> > 3. If I opt for option 1 - do I need to create 2 JDBC river component to  
> > update data in both the elasticsearch indices.  
> > or  
> > should I write one JDBC river component and update both the indices.
> > 
> > Appreciate your inputs.
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/92702ef1-4fd1-45a6-a4b2-eb0cbd8c3aad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/92702ef1-4fd1-45a6-a4b2-eb0cbd8c3aad%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/92702ef1-4fd1-45a6-a4b2-eb0cbd8c3aad%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/92702ef1-4fd1-45a6-a4b2-eb0cbd8c3aad%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/8891e581-6089-47b9-aeea-fb4e1d09f4a8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8891e581-6089-47b9-aeea-fb4e1d09f4a8%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:15am UTC](https://discuss.elastic.co/t/best-practice-to-design-index-type-for-elasticsearch/18635/4 "2017-07-06T01:15:50Z")

</div>


