Elastic search is occupying more than 25 GBs of RAM. Data that I gave for indexing to elastic search is around 1 GB. Why elastic search needs this much of space?
2 Answers
Whenever an Elastic Search starts with default settings it consumes about 1 GB RAM because of their heap space allocation defaults to 1GB setting.
Make sure to check the "jvm.options" File
For Ubuntu Linux OS :- {if installed using debian File} File Location :- /etc/elasticsearch/
or
For Windows OS :- File Location is the extracted folder Location {extacted_folder_path/config/jvm.options}
Inside jvm.options file you need to configure some settings of JVM Heap
-Xms1g
-Xmx1g
-Xms1g is set to acquire 1 GB of initial RAM size whenever elastic search starts. -Xmx1g defines the maximum allocation of RAM to Elastic Search JVM Heap.
You need to tune these two parameters to 4 GB or whatever suits your needs.
-Xms4g
-Xmx4g
Note :- Do not set more than 32 GB Java Heap Space it will not lead to any benefit.

- 376
- 3
- 5
-
More info https://www.elastic.co/guide/en/elasticsearch/reference/current/important-settings.html#heap-size-settings – Digvijay May 07 '21 at 11:18
From some reason "elasticsearch" used 53% of my 24G memory by default which is insane if you ask me. Maybe because it is auto configured as it stated in the text below. Anyway, to set custom JVM heap size, one should create a file "jvm.options" in jvm.options.d
directory and add custom values as stated in default "jvm.options" file:
################################################################
## 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:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
I've set the memory usage to 1G, so the file look like this:
-Xms1g
-Xmx1g
Then you should restart "elasticsearch" service and you can check the memory usage with:
sudo service elasticsearch status
Elasticsearch and jvm versons:
Version: 7.11.0, Build: default/deb/8ced7813d6f16d2ef30792e2fcde3e755795ee04/2021-02-08T22:44:01.320463Z, JVM: 15.0.1

- 328
- 2
- 14
-
4Thanks bro! I tried all above except for the file name I used custom file: "heap_size" instead of the "jvm.options", which didn't work. Then I renamed the file name to "jvm.options" and restarted ES everything worked. – Salim Ibrohimi Feb 23 '21 at 08:41
-
-
5For some reason they don't tell you that the file needs to end in ".options". Mine is named "heap.options" and also works. – tcbcw Sep 16 '21 at 22:49
-
If you are running ElasticSearch in a Docker container, it will respect the container's memory limit - so you can run it like `docker run --memory 800M elasticsearch`. – diachedelic Nov 16 '22 at 23:14