Query to get percentiles of a calculated sum value

Based on the query below, I want to find percentile bucket of the values I am getting from date_histogram aggregation.

Below is my working query to find the day-wise total for the last 7 days, I am not sure where should I add the query code to find the 80th percentile of the daily sum of baseValueUnitAmount as well as what aggregation I should use percentiles_bucket or percentiles?

my query :

{
 "query": {
    "bool": {
      "must": [],
      "filter": [
        {
          "bool": {
            "filter": [
              {
                "bool": {
                  "should": [
                    {
                      "match_phrase": {
                        "displayName.keyword": "Cold"
                      }
                    }
                  ],
                  "minimum_should_match": 1
                }
              },
              {
                "bool": {
                  "should": [
                    {
                      "match_phrase": {
                        "type.keyword": "send"
                      }
                    }
                  ],
                  "minimum_should_match": 1
                }
              }
            ]
          }
        },
        {
          "range": {
            "date": {
              "gte": "now-7d",
              "lte": "now",
              "format": "strict_date_optional_time"
            }
          }
        }
      ],
      "should": [],
      "must_not": []
    }
  },
"aggs": {
    "2": {
      "date_histogram": {
        "field": "date",
        "calendar_interval": "1d",
        "time_zone": "Asia/Calcutta",
        "min_doc_count": 1
      },
      "aggs": {
        "1": {
          "sum": {
            "field": "baseValueUnitAmount"
          }
        }
      }
    }
  },
  "_source": false,
  "fields": ["baseValueUnitAmount"]
}

@Mark_Harwood can you help ?

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