Expressions with dynamicly generated schemas

Hi,

I have following problem:

We have a dynamic template for tags (I dont know tag names upfront unfortunately) for our documents and across our indexes we run a query like:
....
"sum": {
"lang": "expression",
"script": " doc['tags.price.numeric_values'].value * doc['tags.quantity.numeric_values'].value"
}
....

Now the problem is I get the results of this query but some indices throw exceptions like:

... nested: ExpressionScriptCompilationException[Field [tags.price.numeric_values] used in expression does not exist in mappings]; "

Which makes sense because some of the indices did not index documents with those tags, now my question is:
Is there any established solution to this problem to avoid those exceptions, adding "exists" filter doesn't help at all.
I was thinking about maybe checking mapping of all the indexes involved and excluding the ones that didn't have the required tags via mapping API, but while this solution would fix the problem, I belive it creates another one.

Lets say we have a sum A between tag X,Y and another aggregate sum B between tag C,D - then if the inices have some of those, then I should still be able to get results from them - the solution with checking mapping would essentially exclude results from indices that could satisfy only sum A or sum B, so I'm looking for some other possible solutions?

Maybe jython script that would check document for tag existence would be an option here?