Installing Elasticsearch 5.0 as Service on Windows

In previous version (example Elasticsearch 1.7 ), we have used service.bat script to create an Elasticsearch windows service.(link)
In Elasticsearch 5.0, the same achieved using the script named “elasticsearch-service.bat” which is available inside the bin folder of Elasticsearch package.

The following services are available in package

elasticsearch-service-x64 - 64 bit
 elasticsearch-service-x86 - 32 bit

Base on our JDK architecture, the appropriate service will be installed.

One more configuration needs to add before installing the Elasticsearch service, which is the part of the installation process in Elastic 5.0 version.

We need to update the thread stack size setting in the file jvm.options, which is available in the path of config folder.

We have to add the following line in config if we are using 32 bit Windows

-Xss320k

We have to add the following line in config if we are using 64 bit Windows

-Xss1m

 

Elasticsearch Service can be installed with the following command

elasticsearch-service.bat install

elastic-installation

We can set various elasticsearch service options using the manager available in elasticsearch-service script.

elasticsearch-service.bat manager

I’m adding few snapshots of various options available. And also have a look at my previous post of installing Elasticsearch 1.x versions. (How to install Elasticsearch?)

This slideshow requires JavaScript.

Happy exploring data 🙂

Local vs Global scope – JavaScript

Local scope

Let’s start by declaring a variable inside a function called cool (just a name) to understand the difference between local and global scope

Let’s declare a variable called localVariable with type var in our function as below

var cool = function (){
 var localVariable = 10;
 console.log('Inside function: ' +localVariable)
}
cool();
console.log('Outside variable: ' +localVariable);

And we call our function, and also we are trying to write our variable value inside and outside the function in the console.

Once the following line is executed

console.log('Inside function:' +localVariable)

We will be getting output as

Inside function: 10

Whereas when the following line is executed

console.log('Outside variable: ' +localVariable);
Uncaught ReferenceError: localVariable is not defined(…)

We’re getting above error because the localVariable is a local variable and its scope is available within the function only.

Global scope

Let’s edit the same function by renaming the localVariable into localVariable2

And this time we are going to remove the variable type in our code.

Let’s execute and check what will be output.

var cool = function (){
 var localVariable2 = 10;
 console.log('Inside function: ' +localVariable2) // Inside function: 10
}
cool();
console.log('Outside variable: ' +localVariable2); //Outside variable: 10

Now the output will be

Inside function: 10
Outside variable: 10

The interesting thing happening when we are initializing a variable without declaring the type, the JavaScript decides to make it as Global variable with Global scope.

When the variable which is initialized inside a function is assumed as Global scope by JavaScript, we can able to use it outside the function too.

JavaScript has function scope, not block scope. 

Let’s see another example about local and global scope.

var myVariable= "global"; // global
var cool= function() {
 var myVariable = "local";
 console.log(window.myVariable); // global
 console.log(myVariable); // local
}
cool();

Output

global
local

Here we are writing a global and local variable inside the function just by differentiating using window from browser environments.
We can access the variable as the property of global object (using window). And it’s not recommended to use window to access global objects.

Happy exploring JavaScript 🙂