Increase or set Memory for Elastic search in Magento 2

Open the jvm.options file for editing:

 

sudo nano /etc/elasticsearch/jvm.options

  1. Replace nano with your preferred text editor if you're using something else.

  2. Locate line 31, which contains the -Xms2g option.

  3. Remove any leading spaces before the -Xms2g option. The line should look like this:

    text
    -Xms2g
     
  4. Save the file and exit the text editor (usually by pressing Ctrl + O to save and Ctrl + X to exit in the nano editor).

  5.  journalctl -u elasticsearch.service

        1.  
           

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:

  1. Navigate to the JVM Options Directory:

     
    cd /etc/elasticsearch/jvm.options.d/
  2. Create a Custom JVM Options File:

     
    sudo nano heap_size.options
  3. Set Heap Size: In the heap_size.options file, add the following lines to set both the initial and maximum heap size to 2GB:

     
    -Xms2g -Xmx2g

    This 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.

  4. Save and Exit: Save the file by pressing Ctrl + O, then press Enter. Exit the text editor by pressing Ctrl + X.

  5. Restart Elasticsearch:

     
    sudo systemctl restart elasticsearch
  6. 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.