How to execute scripts in Elastic aggregation

I queried elasticsearch use aggregation My response is

 "aggregations" : {
    "time" : {
      "buckets" : [
        {
          "key_as_string" : "2019-01-01",
          "key" : 1546300800000,
          "doc_count" : 12,
          "look_up" : {
            "doc_count" : 5,
            "unlock_not_suggested" : {
              "doc_count" : 2
            }
          }
        },

. Now I want to use script to transform data like this

['lookup': 5, 'unlock_not_suggested': 2 ]

I find and see an advice use script like this but i don't know how to add this in my querry

aggs.stream().flatMap(a -> a.stream().flatMap( b->b.stream().map( c-> -> ['A': a.key, 'B': b.key, 'C': c.key ] ) ) ).collect(Collectors.toList())

My query is

POST test.userstats/_search
{
    "size": 0,
    "aggs": {
        "time": {
            "date_histogram": {
                "field": "event_stats.watch_10_percent_video.first_time",
                "format": "yyyy-MM-dd",
                "interval": "year",
                "min_doc_count": 0
            },
                    "aggs": {
                        "look_up": {
                            "filter": {
                                "exists": {
                                    "field": "event_stats.look_up"
                                }
                            },
                            "aggs": {
                                "unlock_not_suggested": {
                                    "filter": {
                                        "exists": {
                                            "field": "event_stats.unlock_not_suggested_video"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

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