# Want to fetch latest record from the list of records in kibana using DSL query

**URL:** <https://discuss.elastic.co/t/want-to-fetch-latest-record-from-the-list-of-records-in-kibana-using-dsl-query/207081>\
**Category:** Kibana\
**Created:** [November 8, 2019, 9:40am UTC](https://discuss.elastic.co/t/want-to-fetch-latest-record-from-the-list-of-records-in-kibana-using-dsl-query/207081 "2019-11-08T09:40:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![salahali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/salahali/32/47922_2.png) [@salahali](https://discuss.elastic.co/u/salahali)\
**Post date:** [November 8, 2019, 9:40am UTC](https://discuss.elastic.co/t/want-to-fetch-latest-record-from-the-list-of-records-in-kibana-using-dsl-query/207081/1 "2019-11-08T09:40:43Z")

</div>

We are using the ELK v7.3.2 version.

We have requirement in Kibana that we have list of records which are displaying in the Kibana data table. We need to display last updated record on top of the table. For which we are using below DSL query but which is not working.Can you please help us to resolve this issue.

```
    {

  "query": {

    "match_all": { }

  },

"aggs": {

"actual_trans_type.keyword": {

    "terms": {

        "field": "@timestamp"

    },

    "aggs": {

            "top_hit": {

                "sort": [

                    {

                        "fieldName": {

                            "order": "desc"

                        }

                    }

                ],

                "size": 2

            }

        }

        }

     }

}
```

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [November 18, 2019, 6:45pm UTC](https://discuss.elastic.co/t/want-to-fetch-latest-record-from-the-list-of-records-in-kibana-using-dsl-query/207081/2 "2019-11-18T18:45:19Z")

</div>

You need to set the sorting field for top hit to your timestamp in order to get the latest document.  
Easy way to debug would be this: set it up in a metric visualization and use inspector to look at how the request is built.  
This is how to do it in a metric visualization: [Display latest value in a „Metric“](https://discuss.elastic.co/t/display-latest-value-in-a-metric/114930/2)

---

<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:** [December 16, 2019, 6:45pm UTC](https://discuss.elastic.co/t/want-to-fetch-latest-record-from-the-list-of-records-in-kibana-using-dsl-query/207081/3 "2019-12-16T18:45:28Z")

</div>

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