This is a quick mini guide to start with Elasticsearch with Docker.
In this post I'm going to show you the next things:
For install the last Docker versión:
curl -sSL https://get.docker.com/ubuntu/ | sudo sh
docker --version
*This command must be run as root
To use Docker without root privileges:
gpasswd -a $USER docker
*This command must be run as root
Elasticsearch is an open source Search Server.
For pull image from the official repository of Elasticsearch, run the next command y a terminal:
docker pull docker.elastic.co/elasticsearch/elasticsearch:5.5.2
For list the images:
docker images
For run the Elasticsearch container:
docker run --restart=always -d --name elasticsearch -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" docker.elastic.co/elasticsearch/elasticsearch:5.5.2
For show running containers by default and filter by string ‘elasticsearch’
docker ps|grep 'elasticsearch'
For show process that is bound to port 9200
netstat -lpn|grep 9200
Elasticsearch user data by default
user: elastic
password: changeme
For test elasticsearch running
curl -u elastic:changeme -XGET 'http://localhost:9200/'
and you will get a result like this:
{
"name" : "t_QLCEy",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "QMjiT4cNRYOdMADhWw-Wgg",
"version" : {
"number" : "5.5.2",
"build_hash" : "b2f0c09",
"build_date" : "2017-08-14T12:33:14.154Z",
"build_snapshot" : false,
"lucene_version" : "6.6.0"
},
"tagline" : "You Know, for Search"
}
You can use curl command tool to transfer data from or to a Elasticsearch Server.
An index is like a database in a relational database
An type is like a table in a relational database
In the next example, the index name is: my_index, and the type name is: users
Create document
curl -u elastic:changeme -XPUT http://localhost:9200/my_index/users/1?pretty -d '{
"firstname" : "Rodolfo",
"lastname" : "Guzmán",
"alias" : "El Santo"
}'
Create another document
curl -u elastic:changeme -XPUT http://localhost:9200/my_index/users/2?pretty -d '{
"firstname" : "Daniel",
"lastname" : "García Arteaga",
"alias" : "Huracán Ramírez"
}'
Read document
curl -u elastic:changeme -XGET http://localhost:9200/my_index/users/1?pretty
Update document
curl -u elastic:changeme -XPOST http://localhost:9200/my_index/users/1/_update?pretty -d '{
"doc": { "firstname": "Alejandro", "lastname": "Muñoz Moreno", "alias": "Blue Demon" }
}'
1: is the document id
Delete document
curl -u elastic:changeme -XDELETE http://localhost:9200/my_index/users/1?pretty
Show documents
curl -u elastic:changeme http://localhost:9200/my_index/users/_search?pretty
In the next post I'll show you how to dynamically load documents in Elasticsearch with a program in golang ;)
References:
https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html