Setting Elasticsearch Heap Size in Windows

Elasticsearch has an option to configure the memory which is used by elasticsearch java process.

The memory can be configured using various Environmental Variables.

The default Heap Size of an elasticsearch process in 1gb. The ES_HEAP_SIZE environment variable allows setting the heap memory that will be allocated to elasticsearch java process.

We can set Environment Variable as follows

ES_HEAP_SIZE
4g

 

We can check allocated memory using service manager of elasticsearch as follows

cmd

 

manager

 

And another option is to lock the process address space into RAM, preventing any Elasticsearch memory from being swapped out by configuring as follows in Elasticsearch configuration file (config/elasticsearch.yml)

bootstrap.mlockall: true

 

We can check whether settings are applied to the nodes or not by using any one of the following commands

curl http://localhost:9200/_nodes/process?pretty
GET /_nodes/process?pretty
If we receive mlockall is false by running above commands, then it means that the mlockall request has failed.
Explore data using Elastic 🙂
Note:
Note that the environment configuration options available during the installation are copied and will be used during the service life cycle. This means any changes made to them after the installation will not be picked up unless the service is reinstalled.

Elasticsearch is having some minor issue in locking the memory(using Virtual lock) in Windows OS; there is already an open issue raised in Github repository of elastic.

 

How to install Elasticsearch?

In this post, lets discus about the installation of Elasticsearch on windows.

The requirement for installing Elasticsearch is a Java. Elasticsearch recommends its user to install latest version of Java.

We can get the latest version of Java from the official website www.java.com.

The Elasticsearch package can be downloaded from the official link https://www.elastic.co/downloads/elasticsearch

The packages are available as follows,

Elasticsearch installation

Download zip file to install Elasticsearch on windows.

Unzip the package and place it appropriate directory as needed.

To run the Elasticsearch, traverse to elasticsearch\bin path in command prompt and open the elasticsearch.bat file.

By doing this, the Elasticsearch service will start running in command prompt. But when we close the command prompt, the Elasticsearch service will stop running.

So, the Elasticsearch should be installed as window service by running the following command in command prompt

elasticsearch\bin>service install

When command executed successfully, we will receive message as “The service elasticsearch-service-x64 has been installed”.

The Elasticsearch service can be start by using the following command

elasticsearch\bin>service start

Once the service is started, we can confirm it by browsing URL http://localhost:9200/ in browser.

If the service started successfully, it will return 200 status.

 

Note:

Sometimes, we get error while starting windows service which is installed using service install command.

Mostly, it will be because of JVM conflict with the environment variable %JAVA_HOME%. We can fix this by running the following command in command prompt which will set the default JVM to our elasticsearch service (reference)

elasticsearch-service-x64.exe //US//YOUR_SERVICE_NAME --Jvm auto

example:

elasticsearch-service-x64.exe //US//my-elastic-service --Jvm auto

where my-elastic-service is the custom name of our elasticsearch service.