Elasticsearch with Docker in five minutes

What is Elasticsearch?

Elasticsearch is a search server based on Lucene. It provides a distributed, multitenant-capable full-text search engine with a RESTful web interface and schema-free JSON documents.
Elasticsearch is a registered trademark of Elasticsearch BV.

What is Docker?

Docker is the world’s leading software container platform. Developers use Docker to eliminate “works on my machine” problems when collaborating on code with co-workers. Operators use Docker to run and manage apps side-by-side in isolated containers to get better compute density. Enterprises use Docker to build agile software delivery pipelines to ship new features faster, more securely

Installing Elasticsearch

docker pull docker.elastic.co/elasticsearch/elasticsearch:5.6.0

You should see something like this in the terminal.

Running Elasticsearch

docker run -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" docker.elastic.co/elasticsearch/elasticsearch:5.6.0

You can access it at http://localhost:9200 on your web browser.
Note: X-Pack is preinstalled in this image. Please take a few minutes to familiarize yourself with X-Pack Security and how to change default passwords. The default password for the elastic user is changeme.

{  
"name":"4BzXx7i",
"cluster_name":"docker-cluster",
"cluster_uuid":"_W9BMdIfTsutBADi2pyKWg",
"version":{
"number":"5.6.0",
"build_hash":"781a835",
"build_date":"2017-09-07T03:09:58.087Z",
"build_snapshot":false,
"lucene_version":"6.6.0"
},
"tagline":"You Know, for Search"
}

Indexing new items

#request
curl --user elastic:changeme -XPUT 'http://localhost:9200/recipes/recipe/3' -d '
{
"title": "Roasted Pepper and Bacon Omelet",
"href": "http://www.bigoven.com/43919-Roasted-Pepper-and-Bacon-Omelet-recipe.html",
"ingredients": "eggs, salt, black pepper, butter, black pepper, bacon, onions, garlic, roasted red peppers, oregano, black pepper",
"thumbnail": ""
}'
#response
{"_index":"recipes","_type":"recipe","_id":"3","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"created":true

Searching for items

Search all the recipes with contains Broccoli in the title

curl --user elastic:changeme 'http://localhost:9200/recipes/recipe/_search?q=title:Broccoli&pretty=true
#response
{  
"took":11,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"skipped":0,
"failed":0
},
"hits":{
"total":1,
"max_score":0.2876821,
"hits":[
{
"_index":"recipes",
"_type":"recipe",
"_id":"2",
"_score":0.2876821,
"_source":{
"title":"Broccoli and Cheese Omelet",
"href":"http://www.bigoven.com/45151-Broccoli-and-Cheese-Omelet-recipe.html",
"ingredients":"onions, garlic, chicken broth, cottage cheese, oregano, black pepper, egg substitute, bread, mozzarella cheese, butter",
"thumbnail":""
}
}
]
}
}

Shutdown

To shutdown Elasticsearch, hit Ctrl+C. This will shutdown ElasticSearch cleanly.