I have documents in Elasticsearch1.5.2 that look like
POST /test/prod
{
"title": "product 1, type1",
"category": "category1",
"price in €": 1.67,
"price in €/kg": 3.35,
"weight in kg": 0.500
}
POST /test/prod
{
"title": "product 1, type2",
"category": "category1",
"price in €": 1.85,
"price in €/kg": 1.85,
"weight in kg": 1
}
POST /test/prod
{
"title": "product 1, type3",
"category": "category1",
"price in €": 0.79,
"price in €/kg": 4.7,
"weight in kg": 0.168
}
POST /test/prod
{
"title": "product 1, type4",
"category": "category1",
"price in €": 2.15,
"price in €/kg": 4.3,
"weight in kg": 0.5
}
I want to buy 1.2 kg of product1 by the cheapest price in € available, even by using combination between two or three types of product1.And at the same time, The sum of price in €/kg must be equal or greater than 1.200 kg. In my case I must have as a result product 1, type1 and product 1, type2.
My query looks like
POST test/_search?search_type=count
{
"aggs" : {
"product 1" : {
"filter" : {
"query":{ "query_string": {
"query": "title:product 1"
}
}},
"aggs" : {
"minprice": {
"top_hits": {
"sort": [
{
"price in €/kg": {
"order": "asc"
}
}
], "size":4
}
}
}
}} }
I get my documents sorted by field price in €/kg. Now, I must range and sort the result of this query by the weight in kg from 1.2 kg. For example,
3 product 1, Type1 (0.5kg*3)> 1.2 kg.
2 product 1, Type2 (1kg*2)>1.2kg.
8 product 1,Type3 (0.168*8)>1.2kg.
3 product 1, Type 4 (0.5*3)>1.2 kg.
product 1, Type1 + product 1, Type2 (1+0.5)>1.2
product 1, Type2 + 3 product 1, Type3 (1+(0.168*3))> 1.2
....
....
At the end, I want to keep as a final result the lowest price in € of all these combinations.