Filtering nested lists using scripts

Hi all, I have spent days trying to come up with a very specific query.
Here is the challenge:
I have an index that stores ecommerce products. One product has lots of variants, which store the variant's price.
The price is also a nested object, as it stores the price along with a date_since variable to indicate when that price started or will start applying to the variant.

Here is a basic example:

{
"product_id": "123",
    "product_variants":[
        {
            "variant_id": "456",
            "variant_prices":[
                {
                    "price": 100,
                    "date_since": 1708439263876282
                },
                {
                    "price": 90,
                    "date_since": 1708517400328610
                }
            ]
        },
        {
            "variant_id": "789",
            "variant_prices": [
                {
                    "price": 90,
                    "date_since": 1708439263876282
                },
                {
                    "price": 83,
                    "date_since": 1708517400328610
                }
            ]
        }
    ]
}

The challenge is to filter products by price, where the price is defined as the variant_prices.price with it's respective date_since most recent, but in the past.
I need to also get inner_hits ideally, indicating which product variants caused the document hit.

So I can't index the current_price, as it depends on when you are asking. (Maybe there are future prices and in a couple of minutes the filter will not return the same products)

Is this even possible? Because it seems to me that it's not at this point.

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