# Elasticsearch query SQL Server LAG function analog

**URL:** <https://discuss.elastic.co/t/elasticsearch-query-sql-server-lag-function-analog/18715>\
**Category:** Elasticsearch\
**Created:** [July 17, 2014, 9:51am UTC](https://discuss.elastic.co/t/elasticsearch-query-sql-server-lag-function-analog/18715 "2014-07-17T09:51:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dmitriy\_Shilonosov](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Dmitriy\_Shilonosov](https://discuss.elastic.co/u/Dmitriy_Shilonosov)\
**Post date:** [July 17, 2014, 9:51am UTC](https://discuss.elastic.co/t/elasticsearch-query-sql-server-lag-function-analog/18715/1 "2014-07-17T09:51:49Z")

</div>

Hi,

I am looking for a SQL Server LAG  
[http://msdn.microsoft.com/en-us/library/hh231256(v=sql.110).aspx](http://msdn.microsoft.com/en-us/library/hh231256(v=sql.110).aspx)/LEAD  
[http://msdn.microsoft.com/en-us/library/hh213125(v=sql.110).aspx](http://msdn.microsoft.com/en-us/library/hh213125(v=sql.110).aspx)functions  
analog in Elasticsearch.

Assume I have a list of documents in result set found by particular  
criteria. The result set is also ordered in some order.

I know the id of one of the documents in that result set and I need to find  
next and/or previous document in the same result set.

SQL Server 2012 and above has LAG/LEAD functions to get next/previous row  
in the recordset. So I wondering if there is such functionality in the  
elasticsearch.

Could you please point me on the corresponding documentation/examples  
please?

Here is my question on  
stackoverflow: [http://stackoverflow.com/questions/24779002/elasticsearch-query-sql-server-lag-function-analog](http://stackoverflow.com/questions/24779002/elasticsearch-query-sql-server-lag-function-analog)  
in case if you'd like to share knowledge there.

Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9321fae0-7b55-4c85-bae5-49875859974c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9321fae0-7b55-4c85-bae5-49875859974c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:15am UTC](https://discuss.elastic.co/t/elasticsearch-query-sql-server-lag-function-analog/18715/2 "2017-07-06T01:15:15Z")

</div>


