elasticsearch带优先级的复杂查询

uqjltbpv  于 2021-06-10  发布在  ElasticSearch
关注(0)|答案(0)|浏览(262)

我有许多基于可获得的折扣和指定优先权的价目表的价格的产品。“价格”零件Map如下所示:

"price": {
    "properties": {
        "USD": {
            "type": "nested",
            "properties": {
                "amount": {
                    "type": "float"
                },
                "discount_id": {
                    "type": "keyword"
                },
                "price_list_id": {
                    "type": "keyword"
                },
                "priority": {
                    "type": "short"
                }
            }
        }
    }
}

根属性是货币(可能有更多的货币,取决于商店)。价格示例:

"price": {
    "USD": [
        {
            "amount": 10.0,
            "price_list_id": 1,
            "discount_id": [
                1
            ],
            "priority": 1
        },
        {
            "amount": 143.8,
            "price_list_id": 1,
            "discount_id": [
                20,
                22
            ],
            "priority": 2
        },
        {
            "amount": 193.8,
            "price_list_id": 1,
            "discount_id": null,
            "priority": 3
        }
    ]
}

输入为:货币、折扣ID数组、价目表ID数组和价格。
我需要根据给定的输入匹配所有的价格,按优先级排序,然后比较最高优先级的价格(最低的数字)与给定的金额。如果没有产品价格与给定的折扣ID匹配(不必与所有ID匹配,一个就足够了),则价格为null discount_id 使用值。
我举个例子。顾客正在按价格筛选产品。最低金额为100美元,最高金额为150美元。假设价目表是id 1。
此客户可享受id为20的折扣。所以这个查询匹配priority为2的price。
没有折扣。所以这个查询匹配优先级为3的价格,但是价格高于给定的范围,所以客户看不到产品。
另外,当客户可以得到折扣,但有些产品没有这样的折扣价格为给定的折扣id,那么价格在哪里 discount_id ==应用空值。
我想避免编写脚本,但我自己无法解决这个问题。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题