Problem with rounding value of avg calculation

Hi,

I call elasticsearch api via curl from a shell script.

Using following aggregation returns sometimes very little values like 8.058358080730823e-15.

  "aggs": {
    "1": {
      "avg": {
        "field": "metricsM1"
      }
    }
  }

I found some info to use the math functions, but I don't get it running:

  "aggs": {
    "1": {
      "avg": {
        "script": "Math.round(doc['metricsM1'].value * 100.0)/100.0"
      }
    }
  }

I get following error:

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "Unexpected token VALUE_STRING [script] in [1].",
        "line": 31,
        "col": 19
      }
    ],
    "type": "parsing_exception",
    "reason": "Unexpected token VALUE_STRING [script] in [1].",
    "line": 31,
    "col": 19
  },
  "status": 400
}

What is my problem? I just want the precisely calculated average value to be rounded by 2 decimal digits.

I am using elasticsearch 5.1.2.

Thanks, Andreas

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