I think you can do this easier with a scripted_metric
. An advent post from 2 years ago discusses a similar case, unfortunately in german, but just use your favorite online translator:
In short you need something like:
"values": {
"scripted_metric": {
"init_script": "state.docs = []",
"map_script": "state.docs.add(new HashMap(params['_source']['values']))",
"combine_script": "return state.docs",
"reduce_script": "def docs = []; for (s in states) {for (d in s) { docs.add(d);}}return docs"
}
}
You probably need to tweak the map part a bit to e.g. not fail if value
is missing in a doc.