Elasticsearch is an open-source search and analytics engine built on Apache Lucene. It is designed to store, search, and analyze large amounts of data. This guide introduces installation, configuration, and common ways to work with Elasticsearch.
Installing Elasticsearch
Elasticsearch can be installed directly on an operating system, run with Docker, or used through a cloud service. This walkthrough uses Docker Compose as one way to configure Elasticsearch and Kibana together.
Docker
Docker is a platform for developing, delivering, and running applications in containers. A container packages an application and its components so they can be installed and run in a consistent environment.
Docker Compose
Docker Compose defines and runs applications made up of multiple Docker containers. A YAML file can describe services such as Elasticsearch and Kibana.
Download and install
Download Docker and Docker Compose if they are not already installed, then follow the instructions for your operating system.
Create a Docker Compose file
Create a file named docker-compose.yml to define Elasticsearch and Kibana. The sample below uses Elasticsearch and Kibana 7.13.3; check compatibility with the versions you currently use before adapting it.
version: "3.9"
services:
elasticsearch:
container_name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:7.13.3
environment:
- discovery.type=single-node
- ES_JAVA_OPTS=-Xms512m -Xmx512m
ports:
- "9200:9200"
- "9300:9300"
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
kibana:
container_name: kibana
image: docker.elastic.co/kibana/kibana:7.13.3
ports:
- "5601:5601"
depends_on:
- elasticsearch
volumes:
elasticsearch-data:
Container names
Setting a container_name for Elasticsearch and Kibana can make containers easier to identify and manage.
Docker Hub
Docker Hub is a public registry for Docker images where you can find and download images.
Install Kibana and connect it to Elasticsearch
Kibana is a tool for managing and visualizing data in Elasticsearch. It can be included in a Docker Compose setup. After it starts, configure the Elasticsearch URL in Kibana so it can connect to the Elasticsearch service.
Using the REST API
Elasticsearch provides a REST API that lets you interact with it over HTTP.
REST API operations
The REST API can create, retrieve, update, and delete data (CRUD operations), manage indexes, and search records.
cURL and jq
cURL is a command-line tool for sending HTTP requests to the Elasticsearch REST API. jq is a command-line tool for formatting and filtering JSON responses.
Kibana dashboards and cluster health
Kibana dashboards can display Elasticsearch data in a visual format. The Cluster Health API reports the status of an Elasticsearch cluster.
Indexes and documents
An index stores data in Elasticsearch. A document is an individual record stored in an index.
Create an index and use HTTP methods
You can create an index through the REST API. The POST method can create an index or add a document; GET can retrieve an index or document.
Cat API, headings, JSON, and jq
The Cat API presents information about an Elasticsearch cluster in a readable format. Elasticsearch stores and exchanges data as JSON, and jq can process JSON responses. The source article also refers to headings as a way to group and organize information.
Add documents and choose an ID
Add a document to an index through the REST API. You can specify a document ID when adding it.
Bulk API and NDJSON
The Bulk API can add many records in one request. Create a newline-delimited JSON file, usually with an .ndjson extension, to send multiple operations through the Bulk API.
Text analysis
Analysis prepares text for search before it is stored in an index.
Analyzers
An analyzer processes text before indexing. The Standard Analyzer is a general option for English text, while a Thai analyzer is designed for Thai-language search.
OpenSearch
OpenSearch is described in the source article as a fork of Elasticsearch developed by Amazon. Installing OpenSearch follows a similar general process. The article suggests switching from Elasticsearch by changing the URL and related settings; check the relevant product documentation and compatibility requirements before migrating.
Summary
- Elasticsearch is a search engine that you can run and configure for your own data.
- It provides a REST API, while Kibana can be used to manage and visualize Elasticsearch data.
- Docker Compose can help configure services such as Elasticsearch and Kibana together.
- The Bulk API can send many documents in one request.
- Analyzers prepare text for search; language-specific analysis matters for Thai content.