# Filtering nested lists using scripts

**URL:** https://discuss.elastic.co/t/filtering-nested-lists-using-scripts/354248
**Category:** Elasticsearch
**Tags:** painless
**Created:** [February 27, 2024, 3:02pm UTC](https://discuss.elastic.co/t/filtering-nested-lists-using-scripts/354248 "2024-02-27T15:02:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![oliver3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oliver3/32/132126_2.png) [@oliver3](https://discuss.elastic.co/u/oliver3)
#### Post date: [February 27, 2024, 3:02pm UTC](https://discuss.elastic.co/t/filtering-nested-lists-using-scripts/354248/1 "2024-02-27T15:02:29Z")

</div>

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:

```auto
{
"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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 26, 2024, 3:02pm UTC](https://discuss.elastic.co/t/filtering-nested-lists-using-scripts/354248/2 "2024-03-26T15:02:53Z")

</div>

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