From parameter must be set to 0 when search after is used – 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 the `from` parameter in an Elasticsearch query is not set to 0 while using the `search_after` parameter. The `search_after` parameter is used for pagination of results, and the `from` parameter must be set to 0 to ensure correct pagination. To resolve this issue, you should set the `from` parameter to 0 in your query when using `search_after`. Alternatively, if you need to use the `from` parameter with a value other than 0, you should not use `search_after` in the same query.

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 ” `from` parameter must be set to 0 when `search_after` is used. ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: search.

Log Context

Log “`from` parameter must be set to 0 when `search_after` is used.” class name is We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 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.");
 }  String collapseField = source.collapse() != null ? source.collapse().getField() : null;
 FieldDoc fieldDoc = SearchAfterBuilder.buildFieldDoc(context.sort(); source.searchAfter(); collapseField);


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?