I am using Elasticsearch 8.3.3 and trying to make specific index Transform operation in Kibana. More specifically:
- Make groupby of documents by documentId;
- Apply aggregation using custom "scripted_metric" and Painless language;
- Return multiple rows per each group that would be visible in target index as separate entries.
So far, my best result generates only a single entry per group and fields there contain complex datatypes. My code is below:
"aggregations": {
"info": {
"scripted_metric": {
"init_script": "state.docs=[];",
"map_script": "state.docs.add(params['_source']);",
"combine_script": "return state.docs",
"reduce_script": """
ArrayList output = new ArrayList();
for (thr in [1,2,3]){
def kpis = ['a': 0F, 'b': 0F, 'c': 0F];
kpis['threshold'] = thr;
info.putAll(kpis);
output.add(info);
}
return output;
"""
}
}}
Is it possible to reach the aim without usage of re-indexing operations?
state.docs
in the reduce script?