E-shop sorting by lowest price


(Miroslav Kovář) #1

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.


(Mark Walkom) #2

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.


(Miroslav Kovář) #3

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.


(system) #4