I've been looking at aggregations, and at scripting using painless
, and I am not able to figure out how to iterate/sum over all values in an object.
Example:
My mapping looks like
"field1": {
"properties": {
"subfield1": {
"type": "float"
},
"subfield2": {
"type": "float"
},
"subfield3": {
"type": "float"
}
}
}
Let's assume my data looks like this:
{
"field1" : {
"subfield1": 50.0,
"subfield2": 20.5,
"subfield3": 30.5
}
}
I want to perform a range query on 50.0 + 20.5 + 30.5
, or, basically, access all the values within the field1
object in some way.
Aggregations do not allow me to use wild-cards in fields.
I was looking at the code for LeafDocLookup
(used internally for painless), and I see that the relevant methods are disabled.
I've managed to write the script like this:
"query": {
"script": {
"script": {
"inline": "return (doc['field1.subfield1'].value + doc['field1.subfield2'].value + doc['field1.subfield3'].value > 50);",
"lang": "painless"
}
}
}
but this is obviously sub-optimal, and doesn't solve the main issue of dynamic keys.