# Splitting by document ID and do max aggregation to retrieve one value

**URL:** <https://discuss.elastic.co/t/splitting-by-document-id-and-do-max-aggregation-to-retrieve-one-value/130033>\
**Category:** Kibana\
**Created:** [April 30, 2018, 2:09pm UTC](https://discuss.elastic.co/t/splitting-by-document-id-and-do-max-aggregation-to-retrieve-one-value/130033 "2018-04-30T14:09:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![didinyah](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/didinyah/32/30859_2.png) [@didinyah](https://discuss.elastic.co/u/didinyah)\
**Post date:** [April 30, 2018, 2:09pm UTC](https://discuss.elastic.co/t/splitting-by-document-id-and-do-max-aggregation-to-retrieve-one-value/130033/1 "2018-04-30T14:09:47Z")

</div>

I'm looking for a way in kibana to split data and recover only one value.

This is my data :

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/1/91236566877a59177dd9a3a993f16e4cbd0b26ac.png)

I splitted by the ID of the document.

Then I have done a min and max metric

Then with the plugin [https://github.com/datasweet-fr/kibana-datasweet-formula](https://github.com/datasweet-fr/kibana-datasweet-formula) I managed to make a custom metric (the delay between Date 1 and Date 2).

Then I have done the max of this metric (so the max delay is 38 there).

However, since I have splitted my data by the ID, I have the max value many times, and I only need it once.

I want it to display in a metric in kibana like this :

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/f/af44ba52b5f0fb9befef1cdc8e0aae8885c8a4c3.png)

As you can see, the formula is displaying 107 because it's taking the delay between the min of ALL the Date 1 values and the max of ALL the Date 2 values. But I want it to split by DocumentID and then display the max of the metric.

I tried to use max bucket metric and other things but I didn't manage to make it work.

Is there a way to achieve this ?

---

<div class="post-metadata">

**Author:** ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)\
**Post date:** [May 1, 2018, 2:46am UTC](https://discuss.elastic.co/t/splitting-by-document-id-and-do-max-aggregation-to-retrieve-one-value/130033/2 "2018-05-01T02:46:24Z")

</div>

The max appears to be across all the documents. I wonder if this is an issue with the Datasweet plugin.

---

<div class="post-metadata">

**Author:** ![didinyah](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/didinyah/32/30859_2.png) [@didinyah](https://discuss.elastic.co/u/didinyah)\
**Post date:** [May 2, 2018, 7:25am UTC](https://discuss.elastic.co/t/splitting-by-document-id-and-do-max-aggregation-to-retrieve-one-value/130033/3 "2018-05-02T07:25:47Z")

</div>

It's not an issue, actually I would like to have the max of the column "Delay" but it's not a field and not a scripted field either so I can't have it like that. In order to have the values in this column I had to split the document to make individual calculations and then make a custom metric (with the datasweet plugin).

I wondered if we can do the max of this column but only to recover one value. Or is there a solution to do something else to have this value ?

---

<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:** [May 30, 2018, 7:25am UTC](https://discuss.elastic.co/t/splitting-by-document-id-and-do-max-aggregation-to-retrieve-one-value/130033/4 "2018-05-30T07:25:59Z")

</div>

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