# Machine Learning datafeed for egress traffic

**URL:** <https://discuss.elastic.co/t/machine-learning-datafeed-for-egress-traffic/222451>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-machine-learning\
**Created:** [March 6, 2020, 11:59am UTC](https://discuss.elastic.co/t/machine-learning-datafeed-for-egress-traffic/222451 "2020-03-06T11:59:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ezions](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ezions/32/46906_2.png) [@ezions](https://discuss.elastic.co/u/ezions)\
**Post date:** [March 6, 2020, 11:59am UTC](https://discuss.elastic.co/t/machine-learning-datafeed-for-egress-traffic/222451/1 "2020-03-06T11:59:55Z")

</div>

Hi,

I'm trying to create a datafeed for a ML job which would detect suspicious egress traffic per hosts.

```
PUT _xpack/ml/datafeeds/datafeed-network_out_deriv/
{
  "job_id": "network_out_deriv",
  "indices": [
    "metricbeat-*"
  ],
  "query": {
      "bool": {
        "filter": [
          {
            "term": {
              "host.name": "qa-control"
            }
          }
        ],
        "must": {
          "exists": {
            "field": "system.network.out.bytes"
          }
        }
      }
    },
  "aggregations": {
    "buckets": {
      "date_histogram": {
        "field": "@timestamp",
        "interval": "10s",
        "time_zone": "UTC"
      },
      "aggregations": {
        "@timestamp": {
          "max": {
            "field": "@timestamp"
          }
        },
        "host.name": {
          "terms": {
            "field": "host.name"
          }
        },
        "network_out": {
          "max": {
            "field": "system.network.out.bytes"
          }
        },
        "network_out_deriv": {
          "derivative": {
            "buckets_path": "network_out"
          }
        }
      }
    }
  }
}

```

The above inserted datafeed is working but as you can see the hostname is hardcoded there. The problem is that I dont know how to create another aggeregation for hostnames (and partition the ML job by that) while I keep using the derivative function. As soon as I add another aggeregation the derivative function stops working, see below:

```
GET /_search 
{
  "aggregations": {
    "buckets": {
      "date_histogram": {
        "field": "@timestamp",
        "interval": "1000m",
        "time_zone": "UTC"
      },
      "aggregations": {
        "@timestamp": {
          "max": {
            "field": "@timestamp"
          }
        },
        "aggs": {
          "terms": {
            "field": "host.name"
          },
          "aggs": {
            "network_out": {
              "max": {
                "field": "system.network.out.bytes"
              }
            },
            "network_out_deriv": {
              "derivative": {
                "buckets_path": "network_out"
              }
            }
          }
        }
      }
    }
  }
}

```

Receiving this error:

```
    "type" : "illegal_state_exception",
    "reason" : "derivative aggregation [network_out_deriv] must have a histogram, date_histogram or auto_date_histogram as parent"

```

If anybody could give me some tips how to proceed I would really appreciate

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 3, 2020, 11:59am UTC](https://discuss.elastic.co/t/machine-learning-datafeed-for-egress-traffic/222451/2 "2020-04-03T11:59:59Z")

</div>

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