Increase or set Memory for Elastic search in Magento 2
Open the jvm.options file for editing:
sudo nano /etc/elasticsearch/jvm.options
-
Replace
nanowith your preferred text editor if you're using something else. -
Locate line 31, which contains the
-Xms2goption. -
Remove any leading spaces before the
-Xms2goption. The line should look like this:text-Xms2g -
Save the file and exit the text editor (usually by pressing
Ctrl+Oto save andCtrl+Xto exit in thenanoeditor). -
journalctl -u elasticsearch.service
To set the heap size for Elasticsearch, you can create a custom JVM options file with the .options extension and store it in the jvm.options.d/ directory. Here's how you can do it:
-
Navigate to the JVM Options Directory:
cd /etc/elasticsearch/jvm.options.d/ -
Create a Custom JVM Options File:
sudo nano heap_size.options -
Set Heap Size: In the
heap_size.optionsfile, add the following lines to set both the initial and maximum heap size to 2GB:-Xms2g -Xmx2gThis configuration allocates 2GB of memory for both the initial heap size (
-Xms) and the maximum heap size (-Xmx). Adjust the values (e.g.,2g) according to your system's memory and Elasticsearch's requirements. -
Save and Exit: Save the file by pressing
Ctrl + O, then pressEnter. Exit the text editor by pressingCtrl + X. -
Restart Elasticsearch:
sudo systemctl restart elasticsearch -
Verify Elasticsearch Status: Check the status of the Elasticsearch service to ensure it starts without errors:
sudo systemctl status elasticsearch
By following these steps, you should be able to configure the heap size for Elasticsearch according to your requirements.

