# Alternative search using “Scroll” API and “Search After” API for real-time queries

**URL:** https://discuss.elastic.co/t/alternative-search-using-scroll-api-and-search-after-api-for-real-time-queries/196270
**Category:** Elasticsearch
**Created:** [August 22, 2019, 8:05am UTC](https://discuss.elastic.co/t/alternative-search-using-scroll-api-and-search-after-api-for-real-time-queries/196270 "2019-08-22T08:05:03Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![SuperSpike77](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@SuperSpike77](https://discuss.elastic.co/u/SuperSpike77)
#### Post date: [August 22, 2019, 8:05am UTC](https://discuss.elastic.co/t/alternative-search-using-scroll-api-and-search-after-api-for-real-time-queries/196270/1 "2019-08-22T08:05:03Z")

</div>

I need to send **real-time queries** for getting data from the dynamic index, that can be changed anytime. I speak about _millions of docs_ in the index.

The usage of `Scroll` API was useful to me, given that it stored _state_ and worked with _consistency_ data. But on a big amount of records - it had a very bad performance. And depend on `timeout` parameter, that unacceptable for my purposes. `Search After` API looks good, but anyway it _stateless_, so it can lead to data loss or duplication of records in the sample.

Is there are some way to resolve this? Aggregating/filtering queries not acceptable in my situation.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [August 22, 2019, 8:23am UTC](https://discuss.elastic.co/t/alternative-search-using-scroll-api-and-search-after-api-for-real-time-queries/196270/2 "2019-08-22T08:23:30Z")

</div>

Welcome!

Using the Scroll API is the way to go.

> But on a big amount of records - it had a very bad performance.

What do you mean?

---

<div class="post-metadata">

### Author: ![SuperSpike77](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@SuperSpike77](https://discuss.elastic.co/u/SuperSpike77)
#### Post date: [August 22, 2019, 8:30am UTC](https://discuss.elastic.co/t/alternative-search-using-scroll-api-and-search-after-api-for-real-time-queries/196270/3 "2019-08-22T08:30:29Z")

</div>

I'm using `Scroll` API for _simulation of pagination_ in my back-end. So I don't know in advance when my user needs to get a new page with data. In this way, `timeout` of `Scroll` context need to be as max as possible, but I think it isn't the acceptable road of resolving my problem(_for example if I set timeout = 1h_)...

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [August 22, 2019, 9:26am UTC](https://discuss.elastic.co/t/alternative-search-using-scroll-api-and-search-after-api-for-real-time-queries/196270/4 "2019-08-22T09:26:00Z")

</div>

I see. Can't really think of an option you can have.  
I'd probably give a 10 minutes timeout (or whatever) but anytime I'm detecting that the user is not going to the next page (like running another search, exiting the app, ...) I'd cancel its scroll id explicitly.

---

<div class="post-metadata">

### Author: ![SuperSpike77](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@SuperSpike77](https://discuss.elastic.co/u/SuperSpike77)
#### Post date: [August 22, 2019, 9:35am UTC](https://discuss.elastic.co/t/alternative-search-using-scroll-api-and-search-after-api-for-real-time-queries/196270/5 "2019-08-22T09:35:17Z")

</div>

Got it, thank you! I agree with your opinion.

---

<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: [September 19, 2019, 9:35am UTC](https://discuss.elastic.co/t/alternative-search-using-scroll-api-and-search-after-api-for-real-time-queries/196270/6 "2019-09-19T09:35:18Z")

</div>

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