Home > Software design >  Foreach with conditional
Foreach with conditional

Time:09-13

I am trying to avoid scripts (I am under the impression that may have a performance impact?) so would ideally like to do something like the following:

"foreach": "ctx.payload.aggregations.name.buckets",
  "condition": {
    "compare": {
      "ctx.payload.doc_count" : {
        "gte": 10
       }
     }
   },
...

but I can't seem to get it working. Is it possible to do this? If there is a script-based solution that would also be appreciated, but as I said I am trying to avoid this if at all possible.

Thanks!

CodePudding user response:

Tldr;

I am not sure there is a solution without a painless script.

Script solution

Add a transform step to your watcher, to filter out the what you do not want.

The following filter out number below 5.

{
  "transform" : {
    "script" : """
    def list = [1, 2, 3, 4, 5, 6, 7];

    return list.stream().filter(c-> c>5).collect(Collectors.toList());
    """
  }
}
  • Related