Scripted field in Elastic aggregation using High level Client

How do i create a aggregation with scripted field using Elastic High level client ?

Kibana query like below

GET itil_incidents/_search
  "size": 0,
  "aggs": {
    "create_date": {
      "date_histogram": {
        "field": "Incident_Create_Date",
        "interval": "1d",
        "format": "MM-dd-yyyy"
      "aggs": {
        "avg_date_diff": {
          "avg": {
            "script": {
              "lang": "painless",
              "source": "Math.round((doc.Incident_Close_Date.value.millis-doc.Incident_Create_Date.value.millis))"

Please Help. I dont know how to create scripted field in High Level client

Did you look at this page?

And this method:

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