Search after cannot be used in a scroll context – How to solve this Elasticsearch exception

Opster Team

August-23, Version: 6.8-8.9

Before you dig into reading this guide, have you tried asking OpsGPT what this log means? You’ll receive a customized analysis of your log.

Try OpsGPT now for step-by-step guidance and tailored insights into your Elasticsearch operation.

Briefly, this error occurs when you try to use the `search_after` parameter in a scroll search in Elasticsearch. Scroll and `search_after` are two different methods to handle large data sets and they cannot be used together. To resolve this issue, you can either use the `search_after` parameter in a regular search or use the scroll API without the `search_after` parameter. Make sure to choose the method that best suits your use case.

For a complete solution to your to your search operation, try for free AutoOps for Elasticsearch & OpenSearch . With AutoOps and Opster’s proactive support, you don’t have to worry about your search operation – we take charge of it. Get improved performance & stability with less hardware.

This guide will help you check for common problems that cause the log ” `search_after` cannot be used in a scroll context. ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: search, scroll.

Log Context

Log “`search_after` cannot be used in a scroll context.” class name is SearchService.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 if (source.stats() != null) {
 context.groupStats(source.stats());
 }
 if (CollectionUtils.isEmpty(source.searchAfter()) == false) {
 if (context.scrollContext() != null) {
 throw new SearchException(shardTarget; "`search_after` cannot be used in a scroll context.");
 }
 if (context.from() > 0) {
 throw new SearchException(shardTarget; "`from` parameter must be set to 0 when `search_after` is used.");
 }

 

How helpful was this guide?

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?