# Slow percentile aggregation: Is it unusual or normal?

**URL:** <https://discuss.elastic.co/t/slow-percentile-aggregation-is-it-unusual-or-normal/47418>\
**Category:** Elasticsearch\
**Created:** [April 14, 2016, 4:59pm UTC](https://discuss.elastic.co/t/slow-percentile-aggregation-is-it-unusual-or-normal/47418 "2016-04-14T16:59:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anhlqn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anhlqn/32/5454_2.png) [@anhlqn](https://discuss.elastic.co/u/anhlqn)\
**Post date:** [April 14, 2016, 4:59pm UTC](https://discuss.elastic.co/t/slow-percentile-aggregation-is-it-unusual-or-normal/47418/1 "2016-04-14T16:59:21Z")

</div>

Hi All,

I have a dashboard about Netflow data. The dashboard has 10 visualization of different types. 9 visualizations took under 2s to load while 1 percentile aggregation took 21s which is too slow for users.

 ![](https://us1.discourse-cdn.com/elastic/original/2X/0/0d13a2d72f5b53dd9586b33121271bb5a2a74c81.jpg)

 ![](https://us1.discourse-cdn.com/elastic/original/2X/b/b4afd891725fd9fe30c8e35757b094bc41af8156.jpg)

More info about my ES cluster is at: [How can I speed up Kibana aggregation?](https://discuss.elastic.co/t/how-can-i-speed-up-kibana-aggregation/47161)

Is such slow percentiles aggregation is normal?

Same amount of documents took a very short time under average aggregation

 ![](https://us1.discourse-cdn.com/elastic/original/2X/e/eb3e402ec695f76c68c843ee00cdcdebb43fe89b.jpg)

 ![](https://us1.discourse-cdn.com/elastic/original/2X/8/8626d2c460f1314498cc3599db81deac1cf248c3.jpg)

Request body of the percentile aggregation

```auto
{
  "size": 0,
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "query": "*",
          "analyze_wildcard": true
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "range": {
                "@timestamp": {
                  "gte": 1460401200000,
                  "lte": 1460412000000,
                  "format": "epoch_millis"
                }
              }
            }
          ],
          "must_not": []
        }
      }
    }
  },
  "aggs": {
    "2": {
      "date_histogram": {
        "field": "@timestamp",
        "interval": "5m",
        "time_zone": "America/Los_Angeles",
        "min_doc_count": 1,
        "extended_bounds": {
          "min": 1460401200000,
          "max": 1460412000000
        }
      },
      "aggs": {
        "1": {
          "percentiles": {
            "field": "time-taken",
            "percents": [
              95,
              99,
              99.9
            ]
          }
        }
      }
    }
  }
}

```

Request body of the average aggregation

```auto
{
  "size": 0,
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "analyze_wildcard": true,
          "query": "*"
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "range": {
                "@timestamp": {
                  "gte": 1460401200000,
                  "lte": 1460412000000,
                  "format": "epoch_millis"
                }
              }
            }
          ],
          "must_not": []
        }
      }
    }
  },
  "aggs": {
    "2": {
      "date_histogram": {
        "field": "@timestamp",
        "interval": "5m",
        "time_zone": "America/Los_Angeles",
        "min_doc_count": 1,
        "extended_bounds": {
          "min": 1460401200000,
          "max": 1460412000000
        }
      },
      "aggs": {
        "1": {
          "avg": {
            "field": "time-taken"
          }
        }
      }
    }
  }
}

```

Thanks,

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [April 18, 2016, 1:53pm UTC](https://discuss.elastic.co/t/slow-percentile-aggregation-is-it-unusual-or-normal/47418/2 "2016-04-18T13:53:01Z")

</div>

Percentiles are indeed much more costly than average or stats aggregations. Since the field that you are aggregating is a response time, you should be able to use the `HDR Histogram` alternative implementation, which is expected to perform better: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html#\_hdr\_histogram](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html#_hdr_histogram) (the end of the section explains why we are not making it the default).

---

<div class="post-metadata">

**Author:** ![anhlqn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anhlqn/32/5454_2.png) [@anhlqn](https://discuss.elastic.co/u/anhlqn)\
**Post date:** [April 19, 2016, 5:11am UTC](https://discuss.elastic.co/t/slow-percentile-aggregation-is-it-unusual-or-normal/47418/3 "2016-04-19T05:11:15Z")

</div>

Thanks, I'll try HDR

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:58pm UTC](https://discuss.elastic.co/t/slow-percentile-aggregation-is-it-unusual-or-normal/47418/4 "2017-07-05T22:58:18Z")

</div>


