# Most efficient way to model data in Elasticsearch

**URL:** https://discuss.elastic.co/t/most-efficient-way-to-model-data-in-elasticsearch/51061
**Category:** Elasticsearch
**Created:** [May 26, 2016, 1:00pm UTC](https://discuss.elastic.co/t/most-efficient-way-to-model-data-in-elasticsearch/51061 "2016-05-26T13:00:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![psilos](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@psilos](https://discuss.elastic.co/u/psilos)
#### Post date: [May 26, 2016, 1:00pm UTC](https://discuss.elastic.co/t/most-efficient-way-to-model-data-in-elasticsearch/51061/1 "2016-05-26T13:00:01Z")

</div>

I have an example of modelling an commence site. Say that the site has few hundreds shops and few millions products. The products per shop range: 1000-100.000 products/shop. I need to be able to aggregate the products and the shop fields. All the products and all the shops have the same schema.

Product

```
        {
          "productName"
          "price"
          "category"
        } 

```

Shop

```
{
  "shopName"
  "rating"
} 

```

1. Is it more efficient to have a) 1 index/shop, b) same index and 1 type/shop or c) same index, same type and have a field to determine the shop of the product?

I read some related articles and most of them are in favour of same index and 1 type/shop. But then they say that if there is one single index which has a large number of docs it might be even slower than having multiple indices.

1. I also need to perform JOINS and aggregations between the shops and the products. For example I need to be able to retrieve all the products from the shops with rating higher than 8/10 and also get the number of products per category. Is it preferable to use a) application-side JOIN, b) parent-child relationships, c) [Siren plug-in](https://siren.solutions/relational-joins-for-elasticsearch-the-siren-join-plugin/), d) something else?

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [May 27, 2016, 6:20am UTC](https://discuss.elastic.co/t/most-efficient-way-to-model-data-in-elasticsearch/51061/2 "2016-05-27T06:20:00Z")

</div>

1. Different indices.
2. Why do you think you need joins?

---

<div class="post-metadata">

### Author: ![psilos](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@psilos](https://discuss.elastic.co/u/psilos)
#### Post date: [May 28, 2016, 9:30pm UTC](https://discuss.elastic.co/t/most-efficient-way-to-model-data-in-elasticsearch/51061/3 "2016-05-28T21:30:27Z")

</div>

1. Thnx for that. Can you please elaborate a bit more on why you think 1 index is better/faster?
2. Because first I need to get all the shops with rating above 8/10 and then join that with the products from these shops.

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [June 14, 2016, 5:08pm UTC](https://discuss.elastic.co/t/most-efficient-way-to-model-data-in-elasticsearch/51061/4 "2016-06-14T17:08:40Z")

</div>

ES doesn't support joins. You have to model your data differently, typically by de-normalizing it.

---

<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 5, 2017, 10:43pm UTC](https://discuss.elastic.co/t/most-efficient-way-to-model-data-in-elasticsearch/51061/5 "2017-07-05T22:43:52Z")

</div>


