Book Image

Elasticsearch 7.0 Cookbook - Fourth Edition

By : Alberto Paro
Book Image

Elasticsearch 7.0 Cookbook - Fourth Edition

By: Alberto Paro

Overview of this book

Elasticsearch is a Lucene-based distributed search server that allows users to index and search unstructured content with petabytes of data. With this book, you'll be guided through comprehensive recipes on what's new in Elasticsearch 7, and see how to create and run complex queries and analytics. Packed with recipes on performing index mapping, aggregation, and scripting using Elasticsearch, this fourth edition of Elasticsearch Cookbook will get you acquainted with numerous solutions and quick techniques for performing both every day and uncommon tasks such as deploying Elasticsearch nodes, integrating other tools to Elasticsearch, and creating different visualizations. You will install Kibana to monitor a cluster and also extend it using a variety of plugins. Finally, you will integrate your Java, Scala, Python, and big data applications such as Apache Spark and Pig with Elasticsearch, and create efficient data applications powered by enhanced functionalities and custom plugins. By the end of this book, you will have gained in-depth knowledge of implementing Elasticsearch architecture, and you'll be able to manage, search, and store data efficiently and effectively using Elasticsearch.
Table of Contents (23 chapters)
Title Page

Setting up a node via Docker

Docker ( https://www.docker.com/ ) has become a common way to deploy application servers for testing or production.

Docker is a container system that makes it possible to easily deploy replicable installations of server applications. With Docker, you don't need to set up a host, configure it, download the Elasticsearch server, unzip it, or start the server—everything is done automatically by Docker.

Getting ready

How to do it…

  1. If you want to start a vanilla server, just execute the following command:
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.0.0
  1. An output similar to the following will be shown:
7.0.0: Pulling from elasticsearch/elasticsearch
256b176beaff: Already exists
1af8ca1bb9f4: Pull complete
f910411dc8e2: Pull complete
0c0400545052: Pull complete
6e4d2771ff41: Pull complete
a14f19907b79: Pull complete
ea299a414bdf: Pull complete
a644b305c472: Pull complete
Digest: sha256:3da16b2f3b1d4e151c44f1a54f4f29d8be64884a64504b24ebcbdb4e14c80aa1
Status: Downloaded newer image for docker.elastic.co/elasticsearch/elasticsearch:7.0.0
  1. After downloading the Elasticsearch image, we can start a develop instance that can be accessed outside from Docker:
docker run -p 9200:9200 -p 9300:9300 -e "http.host=0.0.0.0" -e "transport.host=0.0.0.0" docker.elastic.co/elasticsearch/elasticsearch:7.0.0

You'll see the output of the ElasticSearch server starting.

  1. In another window/Terminal, to check if the Elasticsearch server is running, execute the following command:
docker ps

The output will be similar to the following:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b99b252732af docker.elastic.co/elasticsearch/elasticsearch:7.0.0 "/usr/local/bin/dock…" 2 minutes ago Up 2 minutes 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp gracious_bassi
  1. The default exported ports are 9200 and 9300.

How it works…

The Docker container provides a Debian Linux installation with Elasticsearch installed.

Elasticsearch Docker installation is easily repeatable and does not require a lot of editing and configuration.

The default installation can be tuned into in several ways, for example:

  1. You can pass a parameter to Elasticsearch via the command line using the -e flag, as follows:
docker run -d docker.elastic.co/elasticsearch/elasticsearch:7.0.0 elasticsearch -e "node.name=NodeName"
  1. You can customize the default settings of the environment that's providing custom Elasticsearch configuration by providing a volume mount point at /usr/share/elasticsearch/configas follows:
docker run -d -v "$PWD/config":/usr/share/elasticsearch/config docker.elastic.co/elasticsearch/elasticsearch:7.0.0
  1. You can persist the data between Docker reboots configuring a local data mount point to store index data. The path to be used as a mount point is /usr/share/elasticsearch/configas follows:
docker run -d -v "$PWD/esdata":/usr/share/elasticsearch/data docker.elastic.co/elasticsearch/elasticsearch:7.0.0

There's more…

The official Elasticsearch images are not only provided by Docker. There are also several customized images for custom purposes. Some of these are optimized for large cluster deployments or more complex Elasticsearch cluster topologies than the standard ones.

Docker is very handy for testing several versions of Elasticsearch in a clean way, without installing too much stuff on the host machine.

In the code repository directory ch01/docker/, there is a docker-compose.yaml file that provides a full environment that will set up the following elements:

  • elasticsearch, which will be available at http://localhost:9200
  • kibana, which will be available at http://localhost:5601
  • cerebro, which will be available at http://localhost:9000

To install all the applications, you can simply execute docker-compose up -d. All the required binaries will be downloaded and installed in Docker, and they will then be ready to be used.

See also