Filter Script with array

Hi everyone, I have a question about filter script for array in ES

I have documents or schema like this:

"name": "linh",
                    "array": [
                            "ts": 1,
                            "val": 200
                            "ts": 2,
                            "val": 300
                            "ts": 3,
                            "val": 100

I want to query documents which have elements in array with ts field > [ts_threshold] and sum of val of these elements > [val_threshold]


a little bit more context would be great appreciated? Does it mean that a query like ts: 3 and val > 550 would match in this case or not?

A few sample queries of what would match and what not helps to create a common context and would greatly appreciated!


i want query like that:
pick all documents which have array.ts from 2 to 3 and arr.val of corresponding objects have sum (300 + 100) > 350.


My only idea for this would be script query calculating this manually, as the query is rather dynamic.