Elasticsearch聚合

时间:2017-03-27 02:31:11

标签: elasticsearch aggregation

我在Elasticsearch1.5.2中有类似

的文档
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
}

我想以最便宜的价格购买1.2公斤的产品1,即使是使用两种或三种产品的组合1.同时,以欧元/公斤为单位的价格总和必须等于或大于超过1.200公斤。在我的情况下,我必须得到产品1,type1和产品1,type2。

我的查询看起来像

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
                    }
                }
            }
     }}   } 

我的文件按字段价格排列,单位为€/ kg。现在,我必须根据1.2千克的重量以千克为单位对查询结果进行排序和排序。例如,

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
....
....

最后,我想保留所有这些组合中最低价格的最终结果。

0 个答案:

没有答案