Watcher -> How to return a value in a transform

Hello, I am trying to return a mathematical result with the number of hits of two input chains which would return a percentage, but I am unable to get the value and use it in the actions email. It always returns a "0".

Any help would be appreciated.

{
  "trigger": {
    "schedule": {
      "interval": "1m"
    }
  },
  "input": {
    "chain": {
      "inputs": [
        {
          "completedCalls": {
            "search": {
              "request": {
                "search_type": "query_then_fetch",
                "indices": [
                  "index1"
                ],
                "rest_total_hits_as_int": true,
                "body": {
                 "size": 0,
                  "query": {
                    "bool": {
                      "should": [
                        {
                          "match": {
                            "cdr.terminationCause": "1"
                          }
                        },
                        {
                          "match": {
                            "cdr.terminationCause": "16"
                          }
                        },
                        {
                          "match": {
                            "cdr.terminationCause": "17"
                          }
                        },
                        {
                          "match": {
                            "cdr.terminationCause": "19"
                          }
                        },
                        {
                          "match": {
                            "cdr.terminationCause": "20"
                          }
                        }
                      ],
                      "minimum_should_match": 1,
                      "filter": {
                        "range": {
                          "@timestamp": {
                            "gte": "now-1m"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        {
          "failedCalls": {
            "search": {
              "request": {
                "search_type": "query_then_fetch",
                "indices": [
                  "uc-voice-broadsoft-cdr"
                ],
                "rest_total_hits_as_int": true,
                "body": {
                 "size": 0,
                  "query": {
                    "bool": {
                      "must_not": [
                        {
                          "match": {
                            "cdr.terminationCause": "1"
                          }
                        },
                        {
                          "match": {
                            "cdr.terminationCause": "16"
                          }
                        },
                        {
                          "match": {
                            "cdr.terminationCause": "17"
                          }
                        },
                        {
                          "match": {
                            "cdr.terminationCause": "19"
                          }
                        },
                        {
                          "match": {
                            "cdr.terminationCause": "20"
                          }
                        }
                      ],
                      "filter": {
                        "range": {
                          "@timestamp": {
                            "gte": "now-1m"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      ]
    }
  },
  "transform": {
    "script": {
      "source": """
        ctx.payload.result = ((ctx.payload.failedCalls.hits.total / ctx.payload.completedCalls.hits.total) * 100);
        return ctx.payload;
      """,
      "lang": "painless"
    }
  },
  "actions": {
    "condition1_email": {
      "email": {
        "profile": "standard",
        "to": [
          "email@email.ca"
        ],
        "subject": "Watcher",
        "body": {
          "text": """Detected {{ctx.payload.result}}% failures in the last minute and requires investigation.
"""
        }
      }
    }
  }
}

Transform results:

    "transform": {
      "type": "script",
      "status": "success",
      "payload": {
        "result": 0,
        "failedCalls": {
          "_shards": {
            "total": 46,
            "failed": 0,
            "successful": 46,
            "skipped": 0
          },
          "hits": {
            "hits": [],
            "total": 550,
            "max_score": null
          },
          "took": 680,
          "timed_out": false
        },
        "completedCalls": {
          "_shards": {
            "total": 46,
            "failed": 0,
            "successful": 46,
            "skipped": 0
          },
          "hits": {
            "hits": [],
            "total": 10000,
            "max_score": null
          },
          "took": 883,
          "timed_out": false
        }
      }
    },

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.