The Elasticsearch upgrade process is somewhat straightforward. Download the upgrade, apply it, and then restart the Elasticsearch service. However, in NetVizura we are not using elastic-licensed Elasticsearch but apache-licensed installation. Elasticsearch doesn't deliver such a version in EXE or MSI flavor, therefore you can only download the zip file. To avoid ZIP and BAT file and registry struggles, we have decided to build an EXE file.

In this blog post, you can see how we to create the aforementioned EXE file, as well as the entire NetVizura Elasticsearch Windows upgrade process. We have a lot of things to cover, so let's dive right in.

How to build an EXE file from Elasticsearch provided ZIP file

Here we want to show how easy it is to make an Elasticsearch EXE file from the ZIP file, and that we don't add anything except configuration parameters to it.

1. Download ZIP file with the new version of Elasticsearch from the Elasticsearch website

2. Unpack the file and add a few lines to elasticsearch.yml file (these lines we are currently using, however they may change in the future)

bootstrap.system_call_filter: false
cluster.name: netvizura
node.name: nv1
node.master: true
node.data: true
discovery.type: single-node
cluster.routing.allocation.disk.threshold_enabled: false

 3. Add inside elasticsearch-service.bat file, due to the possible issues while starting the ES caused by another java present on the system

set ES_START_TYPE=auto
set JAVA_HOME=C:\elasticsearch\elasticsearch-7.9.2\jdk

4. Add another file, which calculates RAM, and then sets regedits for Elasticsearch usage

powershell -command "(Get-WMIObject Win32_PhysicalMemory | Measure-Object Capacity -Sum).sum/1MB" > ram
findstr /r /v "^$" ram
set /P ram=<ram
if %ram% LSS 90000 set /a ram1 = %ram% / 3
if %ram% GTR 90000 set /a ram1 = 32000
rem echo %ram1% is in megabytes
reg add "HKLM\SOFTWARE\WOW6432Node\Apache Software Foundation\Procrun 2.0\elasticsearch-service-x64\Parameters\Java" -v JvmMs -t REG_DWORD /d %ram1% /f
reg add "HKLM\SOFTWARE\WOW6432Node\Apache Software Foundation\Procrun 2.0\elasticsearch-service-x64\Parameters\Java" -v JvmMx -t REG_DWORD /d %ram1% /f

5. To build an EXE file we are using NSIS. It is a lightweight and powerful builder with simple actions. Unpack the folder, install ES service, run RAM script, and then start ES.

With this step completed, we have our NetVizura Elasticsearch installer ready to be used.

NetVizura Elasticsearch Windows Upgrade

Let's get started with the Elasticsearch upgrade procedure within NetVizura application:

1. Turn off Tomcat on your machine

2. Turn off Elasticsearch on your machine

3. Start the new Elasticsearch installer (EXE file created in the first part of this text) and then turn off Elasticsearch again, as it will be turned on automatically with the new installer

4. Remove the current service from the folder where Elasticsearch 7.9.2 version was installed with the following command:

C:\elasticsearch\elasticsearch-7.9.2\bin\elasticsearch-service.bat remove

5. Add the new service with the command:

C:\elasticsearch\elasticsearch-7.9.2\bin\elasticsearch-service.bat install

6. Copy data folder from the old Elasticsearch folder to the new one

7. Turn on Elasticsearch on your machine

8. Turn on Tomcat on your machine

The described procedure should be completed quite quickly, and the new version should work instantaneously.