# How to model data?

**URL:** <https://discuss.elastic.co/t/how-to-model-data/133687>\
**Category:** Elasticsearch\
**Created:** [May 29, 2018, 1:22pm UTC](https://discuss.elastic.co/t/how-to-model-data/133687 "2018-05-29T13:22:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hym](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hym/32/22399_2.png) [@hym](https://discuss.elastic.co/u/hym)\
**Post date:** [May 29, 2018, 1:22pm UTC](https://discuss.elastic.co/t/how-to-model-data/133687/1 "2018-05-29T13:22:16Z")

</div>

Hi, I have an index in which I am trying to have some fields translated in different languages:  
which approach you think is better:

first approach:  
{  
"field1": {  
"en": "book",  
"de": "buch",  
"fr": "livre"  
},  
"field2": {  
"en": "water",  
"de": "wasser",  
"fr": "eau"  
},  
"field3": {  
"en": "head",  
"de": "kopf",  
"fr": "tête"  
}  
}

Or  
Second approach:  
{  
"en": {  
"field1": "book"  
"field2": "water"  
"field3": "head"  
},  
"de": {  
"field1": "buch"  
"field2": "wasser"  
"field3": "kopf"  
},  
"fr": {  
"field1": "livre"  
"field2": "eau"  
"field3": "tête"  
}  
}

Which one is better and why?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![JKhondhu](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@JKhondhu](https://discuss.elastic.co/u/JKhondhu)\
**Post date:** [May 29, 2018, 5:30pm UTC](https://discuss.elastic.co/t/how-to-model-data/133687/2 "2018-05-29T17:30:17Z")

</div>

@hym  
How do you intend to serve the results to your users?

Are you wanting to create a synonyms search whereby one user searches for `auto` IT and that is able to find results for `car` EN, `coche` ES?

---

<div class="post-metadata">

**Author:** ![hym](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hym/32/22399_2.png) [@hym](https://discuss.elastic.co/u/hym)\
**Post date:** [May 30, 2018, 9:04am UTC](https://discuss.elastic.co/t/how-to-model-data/133687/3 "2018-05-30T09:04:55Z")

</div>

@JKhondhu, Thanks for replay;  
No in this case I am not thinking of using synonyms because I already provided synonyms per each analyzer of different languages.  
My question is more from data model point of view, it is just like project structures nowadays is a question,  
**by-feature** or **by-type** where in our case the **first approach** is more like **by-feature** and the **second approach** is like **by-type**

> <https://softwareengineering.stackexchange.com/questions/338597/folder-by-type-or-folder-by-feature>

Please also tell me more what goes in your mind, maybe I did not get your hint and question  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![JKhondhu](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@JKhondhu](https://discuss.elastic.co/u/JKhondhu)\
**Post date:** [May 30, 2018, 3:47pm UTC](https://discuss.elastic.co/t/how-to-model-data/133687/4 "2018-05-30T15:47:12Z")

</div>

How do you intend to serve the results to your users?  
How do you presume your data to be queried? By feature or type? Then we can work backwards.

---

<div class="post-metadata">

**Author:** ![hym](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hym/32/22399_2.png) [@hym](https://discuss.elastic.co/u/hym)\
**Post date:** [May 30, 2018, 4:39pm UTC](https://discuss.elastic.co/t/how-to-model-data/133687/5 "2018-05-30T16:39:58Z")

</div>

@JKhondhu, In my queries, I will always have locale (en, de, ...) here we define it **type** , for example, let's assume a request comes in and it has the locale set to en, then the query clauses will target fields for en.  
please tell me some also what you have in mind for queries by feature?  
and one more question, if we define data model by type we will have all fields (field1, field2, field3) several times defined with the same **name** in the mapping (same index) but with different analyzers, it could be a problem?

Thanks

---

<div class="post-metadata">

**Author:** ![JKhondhu](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@JKhondhu](https://discuss.elastic.co/u/JKhondhu)\
**Post date:** [May 31, 2018, 10:20am UTC](https://discuss.elastic.co/t/how-to-model-data/133687/6 "2018-05-31T10:20:04Z")

</div>

🙂@hym,

```auto
"en": {
"field1": "book"
"field2": "water"
"field3": "head"
.
.

```

This schema is much easier for search. In a multimatch you can use the wildcard en.\*. So the recommendation would be to do this by language, absolutely.

---

<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 28, 2018, 10:20am UTC](https://discuss.elastic.co/t/how-to-model-data/133687/7 "2018-06-28T10:20:11Z")

</div>

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