# Elastic 8.1 RAM memory leak

**URL:** <https://discuss.elastic.co/t/elastic-8-1-ram-memory-leak/302497>\
**Category:** Elasticsearch\
**Created:** [April 15, 2022, 9:55am UTC](https://discuss.elastic.co/t/elastic-8-1-ram-memory-leak/302497 "2022-04-15T09:55:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_A](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@Alex\_A](https://discuss.elastic.co/u/Alex_A)\
**Post date:** [April 15, 2022, 9:55am UTC](https://discuss.elastic.co/t/elastic-8-1-ram-memory-leak/302497/1 "2022-04-15T09:55:31Z")

</div>

Hello. I'm using Elasticsearch 8.1, dependency co.elastic.clients Elasticsearch-java version 8.1.2. When creating one scroll request for 15\_000 records, a large memory consumption occurs. The request consumed 8 GB of memory and vened 8 GB after 20 - 25 minutes (1 GB freed up after about 6 minutes). Who's to say what's the matter? The code for the scroll request is given below:

```auto
RestClient httpClient = RestClient.builder(new HttpHost("localhost", 9200)).build();
ElasticsearchTransport transport = new RestClientTransport(httpClient, new JacksonJsonpMapper());
ElasticsearchClient client = new ElasticsearchClient(transport);

public Long createScrollRequest(String input) throws IOException {
        //List<News> list = new LinkedList<>();

        SearchRequest searchRequest = new SearchRequest.Builder()
                .scroll(new Time.Builder().time("20s").build())
                .query(qb -> qb.multiMatch(mmqb -> mmqb.query(input).fields("status")))
                .build();
        SearchResponse<News> searchResponse = client.search(searchRequest, News.class);
        String scrollId = searchResponse.scrollId();
        List<Hit<News>> searchHits = searchResponse.hits().hits();
        while (searchHits != null && searchHits.size() > 0) {
            ScrollRequest scrollRequest = new ScrollRequest.Builder()
                    .scroll(new Time.Builder().time("20s").build())
                    .scrollId(scrollId)
                    .build();
            searchResponse = client.scroll(scrollRequest, News.class);
            scrollId = searchResponse.scrollId();
            searchHits = searchResponse.hits().hits();
        }

        ClearScrollRequest clearScrollRequest = new ClearScrollRequest.Builder()
                .scrollId(scrollId)
                .build();
        client.clearScroll(clearScrollRequest);

        return searchResponse.hits().total().value();
    }

```

 ![3](https://us1.discourse-cdn.com/elastic/original/3X/b/2/b23fcf13e9b2f8b344cd3c6355e2bda6be267b93.png)

 ![5](https://us1.discourse-cdn.com/elastic/original/3X/e/8/e8419557dc5a2f7bb6530262a7b9ed2070c83b54.png)

If we add property searchRequest.size (10000) it saves memory. Instead of Gigabytes, 100 - 300 Megabytes will be spent. Which is quite a lot (

---

<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:** [May 13, 2022, 9:55am UTC](https://discuss.elastic.co/t/elastic-8-1-ram-memory-leak/302497/2 "2022-05-13T09:55:42Z")

</div>

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