# Build Histogram/Percentile based on count from another field

**URL:** <https://discuss.elastic.co/t/build-histogram-percentile-based-on-count-from-another-field/64714>\
**Category:** Elasticsearch\
**Created:** [November 2, 2016, 12:56pm UTC](https://discuss.elastic.co/t/build-histogram-percentile-based-on-count-from-another-field/64714 "2016-11-02T12:56:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sundar\_V](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sundar_v/32/6928_2.png) [@Sundar\_V](https://discuss.elastic.co/u/Sundar_V)\
**Post date:** [November 2, 2016, 12:56pm UTC](https://discuss.elastic.co/t/build-histogram-percentile-based-on-count-from-another-field/64714/1 "2016-11-02T12:56:37Z")

</div>

Hello,

A sample set of documents that we store are

```
{"name": "GET /login", "avg":"2.2", "count": 5}
{"name": "GET /login", "avg":"1.5", "count": 3}
{"name": "GET /login", "avg":"6.9", "count": 1}
{"name": "GET /login", "avg":"3.1", "count": 1}

```

When I run histogram for `GET /login` alone, with interval of 1 second I get

```
1-2 seconds - 1
2-3 seconds - 1
3-4 seconds - 1
5-6 seconds - 1

```

However, what we are doing is, we are only storing the average with the count (to save space and not duplicate the records). But in reality, what we would like to get is

```
1-2 seconds - 3
2-3 seconds - 5
3-4 seconds - 1
5-6 seconds - 1

```

The same problem appears for percentile as well.

`1.5, 2.2, 3.1, 6.9` - The 75th percentile is reported as 3.1 second.  
`1.5, 1.5, 1.5, 2.2, 2.2, 2.2, 2.2, 2.2, 3.1, 6.9` - The real 75th percentile is 2.2 seconds

Is that possible with elastic search?

Sundar.

---

<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:07pm UTC](https://discuss.elastic.co/t/build-histogram-percentile-based-on-count-from-another-field/64714/2 "2017-07-05T22:07:24Z")

</div>


