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?

https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-aggregation-builders.html

And this method: https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/6.5.2/org/elasticsearch/search/aggregations/support/ValuesSourceAggregationBuilder.html#script()

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