Categories

Testing Elasticsearch Locally

Find your OS system and follow the instructions to get Elasticsearch running locally and connect to it.
Last updated
July 7, 2023

Do you need to test a certain analyzer or a new Elasticsearch feature? Testing locally is usually the fastest way to make iterative changes before pushing them to staging or production. Please download an Elasticsearch version that is compatible with your plan. Find your OS system below, and follow the instructions to get Elasticsearch running locally and connect to it.

<div class="code-snippet-container">
<a fs-copyclip-element="click-2" href="#" class="btn w-button code-copy-button" title="Copy">
<img class="copy-image" src="https://global-uploads.webflow.com/63c81e4decde60c281417feb/6483934eeefb356710a1d2e9_icon-copy.svg" loading="lazy" alt="">
<img class="copied-image" src="https://assets-global.website-files.com/63c81e4decde60c281417feb/64839e207c2860eb9e6aa572_icon-copied.svg" loading="lazy" alt="">
</a>
<div class="code-snippet">
<pre><code fs-codehighlight-element="code" fs-copyclip-element="copy-this-2" class="hljs language-javascript">$ brew install elasticsearch</code></pre>
</div>
</div>

Windows

Windows users can download Elasticsearch as a ZIP file. Simply extract the contents of the ZIP file, and run <span class="inline-code"><pre><code>bin/elasticsearch.bat</code></pre></span> to start up an instance. Note that you’ll need Java installed and configured on your system in order for Elasticsearch to run properly.

Elasticsearch can also be run as a service in Windows.

Linux

There are many Linux distributions out there, so the exact method of getting Elasticsearch installed will vary. Generally, you can download a tarball of Elasticsearch, and extract the compressed contents to a folder. It should have all of the proper executable permissions set, so you can just run <span class="inline-code"><pre><code>bin/elasticsearch</code></pre></span> to spin up an instance. Note that if you’re managing Elasticsearch in Linux without a package manager, you’ll need to ensure all the dependencies are met. Java 7+ is a hard requirement, and there may be others.

Arch Linux

Some distributions have preconfigured Elasticsearch binaries available through repositories. Arch Linux, for example, offers it through the community repo, and can be easily installed via pacman:

<div class="code-snippet-container">
<a fs-copyclip-element="click-3" href="#" class="btn w-button code-copy-button" title="Copy">
<img class="copy-image" src="https://global-uploads.webflow.com/63c81e4decde60c281417feb/6483934eeefb356710a1d2e9_icon-copy.svg" loading="lazy" alt="">
<img class="copied-image" src="https://assets-global.website-files.com/63c81e4decde60c281417feb/64839e207c2860eb9e6aa572_icon-copied.svg" loading="lazy" alt="">
</a>
<div class="code-snippet">
<pre><code fs-codehighlight-element="code" fs-copyclip-element="copy-this-3" class="hljs language-javascript">$ sudo pacman -Syu elasticsearch
</code></pre>
</div>
</div>

This package also comes with a systemd service file for starting/stopping Elasticsearch with <span class="inline-code"><pre><code>sudo systemctl elasticsearch.service</code></pre></span>.

One caveat with Arch: packages are bleeding edge, which means updates are pushed out as they become available. Bonsai is not a bleeding edge service, so you’ll need to be careful to version lock the Elasticsearch package to whatever version you’re running on Bonsai. You may also need to edit the PKGBUILD and elasticsearch.install files to ensure you’re running the same version locally and on Bonsai.

Ubuntu and Debian-flavors

Other distros can use the DEB and RPM files that Elasticsearch offers on the download page. Debian-based Linux distributions can use <span class="inline-code"><pre><code>dpkg</code></pre></span> to install Elasticsearch (note that this doesn’t handle configuring dependencies like Java):

<div class="code-snippet-container">
<a fs-copyclip-element="click-4" href="#" class="btn w-button code-copy-button" title="Copy">
<img class="copy-image" src="https://global-uploads.webflow.com/63c81e4decde60c281417feb/6483934eeefb356710a1d2e9_icon-copy.svg" loading="lazy" alt="">
<img class="copied-image" src="https://assets-global.website-files.com/63c81e4decde60c281417feb/64839e207c2860eb9e6aa572_icon-copied.svg" loading="lazy" alt="">
</a>
<div class="code-snippet">
<pre><code fs-codehighlight-element="code" fs-copyclip-element="copy-this-4" class="hljs language-javascript"># Update the package lists
$ sudo apt-get update

# Make sure Java is installed and working:
$ java -version

# If the version of Java shown is not 7+ (1.7+ if using OpenJDK),
# or it doesn't recognize java at all, you need to install it:
$ sudo apt-get install openjdk-7-jre

# Download the DEB from Elasticsearch:
$ wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-X.Y.Z.deb

# Install the DEB:
$ sudo dpkg -i elasticsearch-1.7.2.deb
</code></pre>
</div>
</div>

This approach will install the configuration files to <span class="inline-code"><pre><code>/etc/elasticsearch/</code></pre></span> and will add init scripts to <span class="inline-code"><pre><code>/etc/init.d/elasticsearch</code></pre></span>.

Red Hat / Suse / Fedora / RPM

Elasticsearch does provide an RPM file for installing Elasticsearch on distros using rpm:

<div class="code-snippet-container">
<a fs-copyclip-element="click-5" href="#" class="btn w-button code-copy-button" title="Copy">
<img class="copy-image" src="https://global-uploads.webflow.com/63c81e4decde60c281417feb/6483934eeefb356710a1d2e9_icon-copy.svg" loading="lazy" alt="">
<img class="copied-image" src="https://assets-global.website-files.com/63c81e4decde60c281417feb/64839e207c2860eb9e6aa572_icon-copied.svg" loading="lazy" alt="">
</a>
<div class="code-snippet">
<pre><code fs-codehighlight-element="code" fs-copyclip-element="copy-this-5" class="hljs language-javascript"># Download the package
$ wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-X.Y.Z.rpm

# Install it
$ rpm -Uvh elasticsearch-X.Y.Z.rpm
</code></pre>
</div>
</div>

<span class="inline-code"><pre><code>rpm</code></pre></span> should handle all of the dependency checks as well, so it will tell you if there is something missing.

Testing the Install

Once you have Elasticsearch installed and running on your local machine, you can test to see that it’s up and running with a tool like curl. By default, Elasticsearch will be running on port 9200. Typically the machine will have a name like <span class="inline-code"><pre><code>localhost</code></pre></span>. If that doesn’t work, you can always use the machine’s local IP address (typically 127.0.0.1).

The <span class="inline-code"><pre><code>curl</code></pre></span> request and Elasticsearch response should look something like this:

<div class="code-snippet-container">
<a fs-copyclip-element="click-6" href="#" class="btn w-button code-copy-button" title="Copy">
<img class="copy-image" src="https://global-uploads.webflow.com/63c81e4decde60c281417feb/6483934eeefb356710a1d2e9_icon-copy.svg" loading="lazy" alt="">
<img class="copied-image" src="https://assets-global.website-files.com/63c81e4decde60c281417feb/64839e207c2860eb9e6aa572_icon-copied.svg" loading="lazy" alt="">
</a>
<div class="code-snippet">
<pre><code fs-codehighlight-element="code" fs-copyclip-element="copy-this-6" class="hljs language-javascript">curl localhost:9200/
{
 "name" : "KLJhbnj",
 "cluster_name" : "elasticsearch",
 "cluster_uuid" : "HLUKJBjMGJHFIKUIpjPJuREg",
 "version" : {
   "number" : "6.0.1",
   "build_hash" : "e123a8",
   "build_date" : "2019-01-22T00:34:03.743Z",
   "build_snapshot" : false,
   "lucene_version" : "6.5.1"
 },
 "tagline" : "You Know, for Search"
}
</code></pre>
</div>
</div>

If you see this response, then your local Elasticsearch cluster is up and running! If not, review the documentation for getting Elasticsearch up and running on your operating system and try again.

Once Elasticsearch is running locally, you can configure a local instance of your application to connect to <span class="inline-code"><pre><code>localhost:9200</code></pre></span> (this is probably the default for your Elasticsearch client anyway). Now you can test out your application’s Elasticsearch integration locally!

View code snippet
Close code snippet