Hi,
need a bit of help here with the watcher aggregation. So far I've dealt with somewhat simplified aggs of the form: time->host->latency.
Now I need to work on a bit of a different struct: time->host->direction(in/out)->count.
Here's the Execute API on just ONE host:
{
  "took": 120,
  "timed_out": false,
  "_shards": {
    "total": 90,
    "successful": 90,
    "failed": 0
  },
  "hits": {
    "total": 12388488,
    "max_score": 3.4217281,
    "hits": [
      {
        "_index": "metrics-logstash-events-2018.05.15",
        "_type": "logs",
        "_id": "AWNhsEzjxT0d2iHVWExL",
        "_score": 3.4217281,
        "_source": {
          "hostname": "idb-syslog-to-elk01",
          "@timestamp": "2018-05-15T02:45:34.048Z",
          "role": "idb-syslog-to-elk",
          "@version": "1",
          "message": "390d1450067e",
          "env": "dev",
          "events": {
            "rate_1m": 2369.6364088497176,
            "rate_15m": 1313.484153030162,
            "count": 12334829429,
            "rate_5m": 1325.9731311137257
          },
          "direction": "in"
        }
      },
      {
        "_index": "metrics-logstash-events-2018.05.15",
        "_type": "logs",
        "_id": "AWNhsEzjxT0d2iHVWExM",
        "_score": 3.4217281,
        "_source": {
          "hostname": "idb-syslog-to-elk01",
          "@timestamp": "2018-05-15T02:45:34.049Z",
          "role": "idb-syslog-to-elk",
          "latency": {
            "min": 0,
            "rate_1m": 2364.295865870752,
            "rate_15m": 1296.0409708266031,
            "max": 1373715744447,
            "p5": 45809,
            "mean": 1773511221.7431247,
            "count": 12015839728,
            "rate_5m": 1316.2510911377335,
            "stddev": 221730.6164462496,
            "p95": 45809
          },
          "@version": "1",
          "message": "390d1450067e",
          "env": "dev",
          "events": {
            "rate_1m": 2369.6299397889406,
            "rate_15m": 1313.4818294550885,
            "count": 12334829429,
            "rate_5m": 1325.9668145518926
          },
          "direction": "out"
        }
      },
      {
        "_index": "metrics-logstash-events-2018.05.15",
        "_type": "logs",
        "_id": "AWNhsDmdxT0d2iHVV-3X",
        "_score": 3.4217281,
        "_source": {
          "hostname": "idb-syslog-to-elk01",
          "@timestamp": "2018-05-15T02:45:29.115Z",
          "role": "idb-syslog-to-elk",
          "@version": "1",
          "message": "390d1450067e",
          "env": "dev",
          "events": {
            "rate_1m": 2157.43726480526,
            "rate_15m": 1293.996092725291,
            "count": 12334805105,
            "rate_5m": 1267.3925343519945
          },
          "direction": "in"
        }
      },
      {
        "_index": "metrics-logstash-events-2018.05.15",
        "_type": "logs",
        "_id": "AWNhsDmdxT0d2iHVV-3Y",
        "_score": 3.4217281,
        "_source": {
          "hostname": "idb-syslog-to-elk01",
          "@timestamp": "2018-05-15T02:45:29.115Z",
          "role": "idb-syslog-to-elk",
          "latency": {
            "min": 0,
            "rate_1m": 2153.249022335875,
            "rate_15m": 1276.5615835790086,
            "max": 1373715744447,
            "p5": 45809,
            "mean": 1773514788.8849082,
            "count": 12015815557,
            "rate_5m": 1257.8264228374765,
            "stddev": 221730.7278094322,
            "p95": 45809
          },
          "@version": "1",
          "message": "390d1450067e",
          "env": "dev",
          "events": {
            "rate_1m": 2157.4128527470007,
            "rate_15m": 1293.9948704087974,
            "count": 12334805105,
            "rate_5m": 1267.3894728980138
          },
          "direction": "out"
        }
      }
    ]
  }
}
for each host I need to do the following mnemonically as a condition:
(metricHostOUT/metricHostIN)*100 > 20
where Host is hostname
where my "metric" is events.count
whereIN/OUT is the value of the direction
I came up with the following aggregation layout, but I'm note sure if it's correct and/or how to do the condition part of watcher:
          "aggregations":{
             "minutes":{
               "date_histogram":{
                  "field": "@timestamp",
                  "interval": "minute",
                  "offset": 0,
                  "order":{
                     "_key": "asc"
                  },
                  "keyed": false,
                  "min_doc_count": 0
               },
               "aggregations":{
                   "nodes":{
                      "terms":{
                        "field": "hostname.keyword",
                        "size": 10,
                        "min_doc_count": 1,
                        "shard_min_doc_count": 0,
                        "show_term_doc_count_error": false,
                        "order": [
                           {
                             "eventCnt": "desc"
                           },
                           {
                             "_term": "asc"
                           }
                        ]
                      },
                      "terms":{
                        "field": "direction.keyword",
                        "size": 10,
                        "min_doc_count": 1,
                        "shard_min_doc_count": 0,
                        "show_term_doc_count_error": false,
                        "order": [
                           {
                             "eventCnt": "desc"
                           },
                           {
                             "_term": "asc"
                           }
                        ]
                      },
                      "aggregations":{
                         "eventCnt":{
                            "sum":{
                               "field": "events.count"
                            }
                         }
                      }
                   }
               }
             }
          },
I thought of sum-img all event.count metrics per host/direction combo and then doing the math...
Any help will be greatly appreciated!