Downloading and installing ElasticSearch
ElasticSearch has an active community and the release cycles are very fast.
Because ElasticSearch depends on many common Java libraries (Lucene, Guice, and Jackson are the most famous), the ElasticSearch community tries to keep them updated and fixes bugs that are discovered in them and the ElasticSearch core. The large user base is also a source of new ideas and features to improve ElasticSearch use cases.
For these reasons, if it's possible, best practice is to use the latest available release (usually, the most stable release and with the least bugs).
Getting ready
You need an ElasticSearch supported operating system (Linux / Mac OS X / Windows) with JVM 1.7 or above installed. A web browser is required to download the ElasticSearch binary release.
How to do it…
In order to download and install an ElasticSearch server, we will perform the following steps:
- Download ElasticSearch from the web. The latest version is always downloadable at http://www.elasticsearch.org/download/. Different versions are available for different operating systems:
elasticsearch-{version-number}.zip
: This is used for both Linux (or Mac OS X) and Windows operating systemselasticsearch-{version-number}.tar.gz
: This is used for Linux and Mac operating systemselasticsearch-{version-number}.deb
: This is used for a Debian-based Linux distribution (this also covers the Ubuntu family). It can be installed with the Debian commanddpkg –i elasticsearch-*.deb
.elasticsearch-{version-number}.rpm
: This is used for Red Hat-based Linux distributions (this also covers the CentOS family). You can install this version with the commandrpm –i elasticsearch-{version number}.rpm
.Note
These packages contain everything to start using ElasticSearch. At the time of writing this book, the latest and most stable version of ElasticSearch is 1.4.0. To check whether this is the latest available version, please visit http://www.elasticsearch.org/download/.
- Extract the binary content:
- After downloading the correct release for your platform, the installation consists of extracting the archive to a working directory.
- For the Windows platform, a good directory can be
c:\es
, while on Unix and Mac OS X, you can use/opt/es
. - To run ElasticSearch, you need a Java Virtual Machine version 1.7 or above installed. For better performance, I suggest that you use the latest Sun/Oracle 1.7 version.
- If you are a Mac OS X user and you have installed Homebrew (http://brew.sh/), the first and second step is automatically managed by the
brew install elasticsearch
command.
- Now, start the ElasticSearch executable to check whether everything is working. To start your ElasticSearch server, just navigate to the installation directory and type either of the following command lines depending on your platform:
- For Linux and Mac OS X:
# bin/elasticsearch
- For Windows:
# bin\elasticserch.bat
- For Linux and Mac OS X:
- Your server should now start, as shown in the following screenshot:
How it works...
The ElasticSearch package generally contains three directories:
Another directory that will be present in the future is the plugins directory. It's the one that stores the plugin code.
There's more...
During the ElasticSearch startup, there are a lot of events that occur:
- A node name is chosen automatically (such as
Robert Kelly
) if it is not provided inelasticsearch.yml
. The name is randomly taken from an in-code embedded ElasticSearch text file (src/main/resources/config/names.txt
). - A node name hash is generated for this node (such as,
whqVp_4zQGCgMvJ1CXhcWQ
). - If there are plugins (native or site), they are loaded. In this example, there are no plugins.
- If it is not configured automatically, ElasticSearch binds to all the network addresses, using two ports:
- Port 9300 is used for internal intranode communication
- Port 9200 is used for the HTTP REST API
- After the startup, if indices are available, they are restored.
If the given port numbers are already bound, ElasticSearch automatically increments the port number and tries to bind to them until a port is available (such as 9201, 9202, and so on). This feature is very useful when you want to fire up several nodes on the same machine for testing.
Many events are fired during ElasticSearch startup; we'll see them in detail in the upcoming recipes.