# Display latest value in a \`Bucket\`

**URL:** <https://discuss.elastic.co/t/display-latest-value-in-a-bucket/259577>\
**Category:** Kibana\
**Created:** [December 24, 2020, 10:11am UTC](https://discuss.elastic.co/t/display-latest-value-in-a-bucket/259577 "2020-12-24T10:11:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![grra](https://avatars.discourse-cdn.com/v4/letter/g/a6a055/32.png) [@grra](https://discuss.elastic.co/u/grra)\
**Post date:** [December 24, 2020, 10:11am UTC](https://discuss.elastic.co/t/display-latest-value-in-a-bucket/259577/1 "2020-12-24T10:11:26Z")

</div>

Hey,  
Let's say I have a set of numbers, and every minute another incremented number appears in my data. Now in `Buckets` I would like to visualize the highest 20 values of that set of numbers, but in `ascending order`. That happens in a aws instance of Kibana.  
How is it possible to do that?

E.g. if I have a document `numbers` with values like {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}..  
And in my dashboard I want to show the latest 5 numbers in Buckets like {5, 6, 7, 8, 9, 10}. (`ascending` order)

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [December 28, 2020, 4:01pm UTC](https://discuss.elastic.co/t/display-latest-value-in-a-bucket/259577/2 "2020-12-28T16:01:46Z")

</div>

Thanks for the extra detail- I can try to give more possibilities, but I need to make some assumptions because you haven't described what visualization you would like. I am going to assume that you want this in a table, because you've only described one dimension.

It sounds like the "largest 20 values" is the same thing as "last 20 values" in your data. This gives you a lot more flexibility. Here are the options I can think of:

1. You can create a Saved Search from the Discover app, which is a table based on individual documents. You can change the sort order of the columns, for example you can sort the `numbers` in ascending order, but it will sort **all the values in the time range, there is no way to limit to 20 values**. I think this solves your use case if you set the time range to 20 minutes.

2. You can use the "Top hits" aggregation as a **Metric, not a bucket** inside the data table visualization:

 ![Screen Shot 2020-12-28 at 11.00.56 AM](https://us1.discourse-cdn.com/elastic/original/3X/9/0/902f184e8be3d946ba44d3c3ff53b8b4a6890899.png)

1. You can use Vega, like I described in the previous thread.

---

<div class="post-metadata">

**Author:** ![grra](https://avatars.discourse-cdn.com/v4/letter/g/a6a055/32.png) [@grra](https://discuss.elastic.co/u/grra)\
**Post date:** [December 29, 2020, 9:08am UTC](https://discuss.elastic.co/t/display-latest-value-in-a-bucket/259577/3 "2020-12-29T09:08:49Z")

</div>

Thanks for the quick reply.

Sorry, I forgot to mention:  
I would like to create a **Line Graph** Visualization, with `"metrics": "ram_usage"` on the **y-Axis** and the corresponding `build_numbers` as **buckets** on the **x-Axis**.

Also I would like to achieve that **without** any **timestamps**.

1. I already created a Saved Search from Discover app, where I get the `Build_Numbers` in a descending Order.  
What I am missing, is **to display the 20 biggest numbers in an ascending order**.

2. I can not use the **Top-Hit Aggregation**. Because the **Line Graph does not provide that**.

3. I did not try to use **Vega** yet, because I thought the limitations are quite the same.

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [December 29, 2020, 4:00pm UTC](https://discuss.elastic.co/t/display-latest-value-in-a-bucket/259577/4 "2020-12-29T16:00:29Z")

</div>

Now that you've described the inputs and outputs that you want, I can give you a possible solution or a recommendation to use Vega. Your assumption about Vega is wrong: Vega is the solution if you need complete control.

If I understand correctly about your data, you might not need Vega. I think you can use the Visualize \> Line chart builder. Set your metric on the Y axis. On the X axis, choose `Terms` of `build_numbers`. Choose the sort order to be `Custom Metric`. The metric is `Max of timestamp`, sorted in ascending order. The size is 20.

The result of this chart is that the buckets on the X axis will show the _20 most recent build numbers_, while the Y axis will show the metric _based on each build_.

---

<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:** [January 26, 2021, 4:00pm UTC](https://discuss.elastic.co/t/display-latest-value-in-a-bucket/259577/5 "2021-01-26T16:00:34Z")

</div>

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