# Out of memory error in elasticsearch

**URL:** <https://discuss.elastic.co/t/out-of-memory-error-in-elasticsearch/273785>\
**Category:** Elasticsearch\
**Created:** [May 24, 2021, 6:13am UTC](https://discuss.elastic.co/t/out-of-memory-error-in-elasticsearch/273785 "2021-05-24T06:13:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jake\_JJ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jake_jj/32/89150_2.png) [@jake\_JJ](https://discuss.elastic.co/u/jake_JJ)\
**Post date:** [May 24, 2021, 6:13am UTC](https://discuss.elastic.co/t/out-of-memory-error-in-elasticsearch/273785/1 "2021-05-24T06:13:40Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/d/2/d2c2295bce4b0026f31991e0ae715af190d0016e.png)  
jvm.options

```nohighlight
################################################################
##
## JVM configuration
##
################################################################
##
## WARNING: DO NOT EDIT THIS FILE. If you want to override the
## JVM options in this file, or set any additional options, you
## should create one or more files in the jvm.options.d
## directory containing your adjustments.
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/jvm-options.html
## for more information.
##
################################################################

-Des.insecure.allow.root=true
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## The heap size is automatically configured by Elasticsearch
## based on the available memory in your system and the roles
## each node is configured to fulfill. If specifying heap is
## required, it should be done through a file in jvm.options.d,
## and the min and max should be set to the same value. For
## example, to set the heap to 4 GB, create a new file in the
## jvm.options.d directory containing these lines:
##
-Xms3g
-Xmx3g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################

################################################################
## Expert settings
################################################################
##
## All settings below here are considered expert settings. Do
## not adjust them unless you understand what you are doing. Do
## not edit them in this file; instead, create a new file in the
## jvm.options.d directory containing your adjustments.
##
################################################################

## GC configuration
8-13:-XX:+UseConcMarkSweepGC
8-13:-XX:CMSInitiatingOccupancyFraction=75
8-13:-XX:+UseCMSInitiatingOccupancyOnly

## G1GC Configuration
# NOTE: G1 GC is only supported on JDK version 10 or later
# to use G1GC, uncomment the next two lines and update the version on the
# following three lines to your version of the JDK
# 10-13:-XX:-UseConcMarkSweepGC
# 10-13:-XX:-UseCMSInitiatingOccupancyOnly
14-:-XX:+UseG1GC

## JVM temporary directory
-Djava.io.tmpdir=${ES_TMPDIR}

## heap dumps

# generate a heap dump when an allocation from the Java heap fails; heap dumps
# are created in the working directory of the JVM unless an alternative path is
# specified
-XX:+HeapDumpOnOutOfMemoryError

# specify an alternative path for heap dumps; ensure the directory exists and
# has sufficient space
-XX:HeapDumpPath=data

# specify an alternative path for JVM fatal error logs
-XX:ErrorFile=logs/hs_err_pid%p.log

## JDK 8 GC logging
8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc.log
8:-XX:+UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=32
8:-XX:GCLogFileSize=64m

# JDK 9+ GC logging
9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m

```

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/7/779c924ed78813ba5cd92d8f72696f6f7b097dcd.png)  
os: CentOS Linux release 7.7.1908 (Core)  
java version:

```nohighlight
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)

```

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/7/77b12e44dd5a30443c0e323480e371440b5f77ed.png)

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 24, 2021, 6:39am UTC](https://discuss.elastic.co/t/out-of-memory-error-in-elasticsearch/273785/2 "2021-05-24T06:39:05Z")

</div>

You have far, far too many shards given the number of nodes and heap size of your cluster. Have a look at [this blog post](https://www.elastic.co/blog/how-many-shards-should-i-have-in-my-elasticsearch-cluster) for some practical guidance and then change your sharding strategy to reduce the shard count in the cluster significantly.

---

<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:** [June 21, 2021, 6:39am UTC](https://discuss.elastic.co/t/out-of-memory-error-in-elasticsearch/273785/3 "2021-06-21T06:39:49Z")

</div>

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