1

I am using Elasticsearch 8.3.3 and trying to make specific index Transform operation in Kibana. More specifically:

  1. Make groupby of documents by documentId;
  2. Apply aggregation using custom "scripted_metric" and Painless language;
  3. 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?

2
  • 1
    Why are you not using state.docs in the reduce script?
    – Val
    Commented Sep 14, 2023 at 9:49
  • @Val Beacuse it is only the minimalistic example to reproduce the problem. In real application I heavily use state.docs in logic. Commented Sep 14, 2023 at 12:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.