Briefly, this error occurs when Elasticsearch fails to create a scroll entity, which is used for retrieving large numbers of results from a search query. This could be due to a variety of reasons such as incorrect query syntax, insufficient memory, or an issue with the Elasticsearch cluster. To resolve this issue, you can check your query syntax, increase the memory allocation for Elasticsearch, or troubleshoot your Elasticsearch cluster for any potential issues.
This guide will help you check for common problems that cause the log ” failed to build scroll entity ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: scroll, reindex.
Overview
In Elasticsearch, the concept of scroll comes into play when you have a large set of search results. Large search results are exhaustive for both the Elasticsearch cluster and the requesting client in terms of memory and processing. The scroll API enables you to take a snapshot of a large number of results from a single search request.
Examples
To perform a scroll search, you need to add the scroll parameter to a search query and specify how long Elasticsearch should keep the search context viable.
GET mydocs-2019/_search?scroll=40s { "size": 5000, "query": { "match_all": {} }, "sort": [ { "_doc": { "order": "asc" } } ] }
This query will return a maximum of 5000 hits. If the scroll is idle for more than 40 seconds, it will be deleted. The response will return the first page of the results and a scroll ID. You can use the scroll ID to get additional documents from the scroll. You’ll be able to keep retrieving the documents until you have all of them.
Notes
- Changes made to documents after the scroll will not show up in your results.
- When you are done with the scroll, you can delete it manually using the scroll ID.
DELETE _search/scroll/<scroll_id>
Overview
Reindex is the concept of copying existing data from a source index to a destination index which can be inside the same or a different cluster. Elasticsearch has a dedicated endpoint _reindex for this purpose. A reindexing is mostly required for updating mapping or settings.
Examples
Reindex data from a source index to destination index in the same cluster:
POST /_reindex?pretty { "source": { "index": "news" }, "dest": { "index": "news_v2" } }
Notes
- Reindex API does not copy settings and mappings from the source index to the destination index. You need to create the destination index with the desired settings and mappings before you begin the reindexing process.
- The API exposes an extensive list of configuration options to fetch data from the source index, such as query-based indexing and selecting multiple indices as the source index.
- In some scenarios reindex API is not useful, where reindexing requires complex data processing and data modification based on application logic. In this case, you can write your custom script using Elasticsearch scroll API to fetch the data from source index and bulk API to index data into destination index.
Log Context
Log “failed to build scroll entity” class name is RemoteRequestBuilders.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :
try (XContentBuilder entity = JsonXContent.contentBuilder()) { entity.startObject().field("scroll_id"; scroll).endObject(); request.setJsonEntity(Strings.toString(entity)); } catch (IOException e) { throw new ElasticsearchException("failed to build scroll entity"; e); } return request; } static Request clearScroll(String scroll; Version remoteVersion) {
[ratemypost]