# E-shop sorting by lowest price

**URL:** https://discuss.elastic.co/t/e-shop-sorting-by-lowest-price/26393
**Category:** Elasticsearch
**Created:** [July 28, 2015, 7:48am UTC](https://discuss.elastic.co/t/e-shop-sorting-by-lowest-price/26393 "2015-07-28T07:48:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mirakovar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mirakovar/32/3881_2.png) [@mirakovar](https://discuss.elastic.co/u/mirakovar)
#### Post date: [July 28, 2015, 7:48am UTC](https://discuss.elastic.co/t/e-shop-sorting-by-lowest-price/26393/1 "2015-07-28T07:48:02Z")

</div>

Hi!  
I would like to ask you about best solution for searching/sorting within elasticsearch. Let’s imagine catalog about 50 00+ cards.  
Each card has got price within dimension of pricelist about 20 pricelist. So I created documents like this:

```
{
	“catalog_number”: “XYZ”,
	“url”: “http://xyz”,
	“…”: “…”,
	“price”: [
		{“pricelist”: {“id”: “X”, “name”: “pricelist_a”}, “value”: 5000, “currency”: {“key”: “EUR”, “id”: “X”}},
		{“pricelist”: {“id”: “Y”, “name”: “pricelist_b”}, “value”: 4900, “currency”: {“key”: “EUR”, “id”: “X”}},
		{“pricelist”: {“id”: “Z”, “name”: “pricelist_c”}, “value”: 4800, “currency”: {“key”: “EUR”, “id”: “X”}}
		, … 20 times …
	]
}

```

Then we wouldlike to create user specific prices and here come my case. Imagine 5 000+ users with specific prices with each pricelist dimension.

```
{
	“catalog_number”: “XYZ”,
	“url”: “http://xyz”,
	“…”: “…”,
	“price”: [
		{“pricelist”: {“id”: “X”, “name”: “pricelist_a”}, “value”: 5000, “currency”: {“key”: “EUR”, “id”: “X”}},
		{“pricelist”: {“id”: “Y”, “name”: “pricelist_b”}, “value”: 4900, “currency”: {“key”: “EUR”, “id”: “X”}},
		{“pricelist”: {“id”: “Z”, “name”: “pricelist_c”}, “value”: 4800, “currency”: {“key”: “EUR”, “id”: “X”}}
		, … 20*5000 times … ?!
	]
}

```

First I come with idea of parent-child document, which would be fine parent document (card) would not be overwritten each time price changed and parent document size wolud be keep small. But I cannot sort parents document by value of child document.

Now let’s imagine e-shop and signed-in user. User see cards and click on sort by price. Which solution do you suggest to me?

a) store price within same document (large documents + version change each time price) but sorting works  
b) parent-child document size and amount of prices is good but sorting not working  
c) ?

Thanks for any ideas or suggestions.

---

<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: [July 28, 2015, 11:39pm UTC](https://discuss.elastic.co/t/e-shop-sorting-by-lowest-price/26393/2 "2015-07-28T23:39:56Z")

</div>

You may just want to do both and then query whichever is more relevant for the response you want.

This sort of "multiview"is the best option rather than having a single structure that is not optimal for either use case.

---

<div class="post-metadata">

### Author: ![mirakovar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mirakovar/32/3881_2.png) [@mirakovar](https://discuss.elastic.co/u/mirakovar)
#### Post date: [July 31, 2015, 7:09am UTC](https://discuss.elastic.co/t/e-shop-sorting-by-lowest-price/26393/3 "2015-07-31T07:09:27Z")

</div>

Thanks,  
that is not answer what I'm waiting for. There must be som solustion over parent/child document sorting, maybe by script sort? I exclude option holding price on card document because of amount of prices and frequency of changing.

---

<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, 11:58pm UTC](https://discuss.elastic.co/t/e-shop-sorting-by-lowest-price/26393/4 "2017-07-05T23:58:02Z")

</div>


