Complex query with priorities

Hello,

I am struggling to figure this out. I've got products with many prices based on available discounts and price lists with assigned priorities. The 'price' part mapping looks like this:

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

The root property is currency (there might be more currencies, depends on a shop). Real example of price:

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

The input is: currency, array of discount ids, array of price list ids and price.

I need to match all prices based on given input, sort them via priority and then compare the highest priority price (lowest number) with given amount. When no product price matches given discount ids (doesn't have to match all ids, one is enough), then price with null discount_id value is used.

I'd like to avoid scripting, but can't figure out this by myself.

Thanks for any idea.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.