Problem with Bucket Script Aggregation in Machine Learning Datafeed

I'm attempting to create a datafeed for a machine learning job that uses Bucket Script Aggregation as referenced here:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html

The problem comes when referencing the actual final value of the filter aggregation in the bucket script in the datafeed. The filter aggregation from the example:

        "t-shirts": {
          "filter": {
            "term": {
              "type": "t-shirt"
            }
          },
          "aggs": {
            "sales": {
              "sum": {
                "field": "price"
              }
            }
          }
        },

Later, a variable named "tShirtSales" is created and it seems to reference the value of sales aggregation inside the t-shirts aggregation using the syntax "t-shirts>sales". Again from the example:

        "t-shirt-percentage": {
            "bucket_script": {
                "buckets_path": {
                  "tShirtSales": "t-shirts>sales",
                  "totalSales": "total_sales"
                },
                "script": "params.tShirtSales / params.totalSales * 100"
            }
        }

However, when I try to do this in a datafeed, ("tShirtSales": "t-shirts>sales") it doesn't actually set the variable to the value of the "sales" aggregation. When I preview the output of the machine learning job, it just has time buckets and the document count and no detector metric values. The job runs without error but it runs on nothing. The preview looks like this

  {
    "@timestamp": 1544425187000,
    "doc_count": 3509
  }

When it should look like this:

  {
    "t-shirt-percentage": 0.12345,
    "@timestamp": 1544425187000,
    "doc_count": 3509
  }

If I try to reference the "t-shirts" filter aggregation I get the following error demanding a single value metric.

"caused_by": {
  "type": "aggregation_execution_exception",
  "reason": "buckets_path must reference either a number value or a single value numeric metric aggregation, got: org.elasticsearch.search.aggregations.bucket.filter.InternalFilter"
}

If I try to directly reference the "sales" aggregation inside the "t-shirts" aggregation I get a different errors:

  {
    "type": "illegal_argument_exception",
    "reason": "No aggregation found for path [sales]"
  }

How can I make the bucket script in the datafeed recognize the final value of a filter aggregation like it does in a query?

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