# Maintaining Order of logs with elastic-search search API

**URL:** https://discuss.elastic.co/t/maintaining-order-of-logs-with-elastic-search-search-api/130962
**Category:** Elasticsearch
**Created:** [May 8, 2018, 9:10am UTC](https://discuss.elastic.co/t/maintaining-order-of-logs-with-elastic-search-search-api/130962 "2018-05-08T09:10:41Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![shaheryar](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@shaheryar](https://discuss.elastic.co/u/shaheryar)
#### Post date: [May 8, 2018, 9:10am UTC](https://discuss.elastic.co/t/maintaining-order-of-logs-with-elastic-search-search-api/130962/1 "2018-05-08T09:10:41Z")

</div>

How can i retrieve logs from elastic search in the order they were generated?

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [May 8, 2018, 9:30am UTC](https://discuss.elastic.co/t/maintaining-order-of-logs-with-elastic-search-search-api/130962/2 "2018-05-08T09:30:55Z")

</div>

If you are gathering logs using Filebeat, this will record a timestamp as well as the filename and the offset of the log entry within this file. When you search you should be able to get the correct order by sorting based on timestamp and offset.

---

<div class="post-metadata">

### Author: ![shaheryar](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@shaheryar](https://discuss.elastic.co/u/shaheryar)
#### Post date: [May 8, 2018, 9:47am UTC](https://discuss.elastic.co/t/maintaining-order-of-logs-with-elastic-search-search-api/130962/3 "2018-05-08T09:47:22Z")

</div>

I have time stamp but not the offset. I am gathering logs from a tcp (input plugin) connection to logstash and forwarding it to elastic search.

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [May 8, 2018, 9:50am UTC](https://discuss.elastic.co/t/maintaining-order-of-logs-with-elastic-search-search-api/130962/4 "2018-05-08T09:50:25Z")

</div>

Then you will only be able to order them by timestamp. If multiple documents have the same timestamp I do not you can establish the order between these.

---

<div class="post-metadata">

### Author: ![shaheryar](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@shaheryar](https://discuss.elastic.co/u/shaheryar)
#### Post date: [May 8, 2018, 9:52am UTC](https://discuss.elastic.co/t/maintaining-order-of-logs-with-elastic-search-search-api/130962/5 "2018-05-08T09:52:11Z")

</div>

ok. thanks for quick response.

---

<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: [June 5, 2018, 9:52am UTC](https://discuss.elastic.co/t/maintaining-order-of-logs-with-elastic-search-search-api/130962/6 "2018-06-05T09:52:21Z")

</div>

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