Course Materials: Elasticsearch and the Elastic Stack – In Depth and Hands On!

Course Materials

Thank you for enrolling in our Elasticsearch course!

First things first – here are links to the slides for the course, so you can keep them for future reference. There are three versions of this course out there for Elasticsearch 5, 6, and 7 – so be sure to follow along for the version you’re taking as you go through this page.

Elasticsearch 5: http://media.sundog-soft.com/es/ElasticStack.pdf

Elasticsearch 6: http://media.sundog-soft.com/es6/ElasticStack.pdf

Elasticsearch 7: http://media.sundog-soft.com/es7/ElasticStack7.pdf

These slides also contain text versions of the various snippets of code and configuration we use in the course. You can save time in the course activities by copying and pasting from the slides.

(We have discontinued our Facebook group due to abuse.)

Setup Instructions

Setting Up a Virtual Machine (if you don’t have an Ubuntu system)

Watch the setup video in the course to see how this all works! My notes are below for reference only.

Install Virtualbox from https://www.virtualbox.org/wiki/Downloads

Download Ubuntu server ISO from https://www.ubuntu.com/download/server

In VirtualBox, select Machine / New and set up a Linux, Ubuntu 64-bit system. Set however much RAM you can spare on your system (I use 8GB on my 16GB system – at least 2GB to be safe.) Create a virtual drive wherever you can spare the space; you’ll need at least 20GB for this course. Start it, and select the ISO file you downloaded for Ubuntu to start the Ubuntu installation process. Go with the defaults unless you have reason to do otherwise, and enter whatever username and password you want for your root account. When prompted to write changes to disk, select “yes”. You can change selections using the TAB key, and confirm selections with ENTER.

In VirtualBox, bring up the settings for your Ubuntu virtual machine, and select Network, then advanced, and hit the port forwarding button.  Add an entry for “Elasticsearch” for TCP on host IP 127.0.0.1, and enter 9200 for the host port and guest port. Leave the Guest IP blank. Also add a “Kibana” entry in the same way, with port 5601, and an “SSH” entry, with port 22. On MacOS, you may have a conflict with port 22 – so try setting the host port for SSH to 2222 instead, and connect to your virtual server using port 2222 instead of 22 as shown in the course videos.

VirtualBox Troubleshooting

If you are running the Avast anti-virus program, it will conflict with VirtualBox. There is a registry hack that gets around the problem, but you might consider switching to Microsoft’s free Windows Defender instead while using this course.

Don’t forget to check your BIOS settings if you’re having trouble. Virtualization needs to be enabled, and I’ve seen reports of “Hyper-V” virtualization causing problems if it’s on.

Installing Elasticsearch

Start your Ubuntu virtual machine and log in.

For the Elasticsearch 5 course:

First we need a Java environment:

sudo apt-get install openjdk-8-jre-headless -y
sudo apt-get install openjdk-8-jdk-headless -y

Now we can install Elasticsearch itself:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

sudo apt-get install apt-transport-https

echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo
tee -a /etc/apt/sources.list.d/elastic-5.x.list

sudo apt-get update && sudo apt-get install elasticsearch

Now, edit the elasticsearch.yml file:

sudo vi /etc/elasticsearch/elasticsearch.yml

Change network.host to 0.0.0.0 (in vi, use the arrow keys to where you want to edit, then hit “i” to enter “insert mode” and make your edits. When done, hit ESC to exit “insert mode”, then type :wq to write your changes and quit vi.)

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
sudo /bin/systemctl start elasticsearch.service

Elasticsearch is now up and running!

Hit 127.0.0.1:9200 from a browser to test it.

For the Elasticsearch 6 course:

First we need a Java environment:

sudo apt-get install openjdk-8-jre-headless -y
sudo apt-get install openjdk-8-jdk-headless -y

Now we can install Elasticsearch itself:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

sudo apt-get install apt-transport-https

echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo
tee -a /etc/apt/sources.list.d/elastic-6.x.list

sudo apt-get update && sudo apt-get install elasticsearch

Now, edit the elasticsearch.yml file:

sudo vi /etc/elasticsearch/elasticsearch.yml

Change network.host to 0.0.0.0 (in vi, use the arrow keys to where you want to edit, then hit “i” to enter “insert mode” and make your edits. When done, hit ESC to exit “insert mode”, then type :wq to write your changes and quit vi.)

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
sudo /bin/systemctl start elasticsearch.service

Elasticsearch is now up and running!

Hit 127.0.0.1:9200 from a browser to test it.

For the Elasticsearch 7 Course:

After logging into your virtual Ubuntu server, use the following commands to install Elasticsearch itself:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

sudo apt-get install apt-transport-https

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" |
sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

sudo apt-get update && sudo apt-get install elasticsearch


Next, edit the Elasticsearch configuration using vi:

sudo vi /etc/elasticsearch/elasticsearch.yml

Uncomment the node.name line (in vi, use the arrow keys to where you want to edit, then hit “i” to enter “insert mode” and make your edits.)

Change network.host to 0.0.0.0, discovery.seed.hosts to [“127.0.0.1”], and cluster.initial_master_nodes to [“node-1”]

When done, hit ESC to exit “insert mode”, then type :wq to write your changes and quit vi.

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
sudo /bin/systemctl start elasticsearch.service

Elasticsearch is now up and running! Or, it will be in a couple of minutes after everything spins up.

Troubleshooting

If Elasticsearch doesn’t seem to be running, give it a few minutes and try again. But you may be encountering an issue specific to Ubuntu 16.04 that has a workaround described at https://lxadm.com/Problems_starting_elasticsearch_in_Ubuntu_16.04

Install the Shakespeare Search Index in Elasticsearch 5:

wget http://media.sundog-soft.com/es/shakes-mapping.json
curl -XPUT 127.0.0.1:9200/shakespeare --data-binary @shakes-mapping.json
wget http://media.sundog-soft.com/es/shakespeare.json
curl -XPOST '127.0.0.1:9200/shakespeare/_bulk' --data-binary @shakespeare.json    
curl -XGET '127.0.0.1:9200/shakespeare/_search?pretty' -d '
{
"query" : {
"match_phrase" : {
"text_entry" : "to be or not to be"
}
}
}
'

Install the Shakespeare Search Index in Elasticsearch 6:

wget http://media.sundog-soft.com/es6/shakes-mapping.json

curl -H 'Content-Type: application/json' -XPUT 127.0.0.1:9200/shakespeare 
--data-binary @shakes-mapping.json

wget http://media.sundog-soft.com/es6/shakespeare_6.0.json

curl -H 'Content-Type: application/json' -XPOST
'localhost:9200/shakespeare/_doc/_bulk?pretty' --data-binary
@shakespeare_6.0.json

curl -H 'Content-Type: application/json' -XGET
'127.0.0.1:9200/shakespeare/_search?pretty' -d '
{
"query" : {
"match_phrase" : {
"text_entry" : "to be or not to be"
}
}
}
'

Install the Shakespeare Search Index in Elasticsearch 7:

wget http://media.sundog-soft.com/es7/shakes-mapping.json

curl -H 'Content-Type: application/json' -XPUT 127.0.0.1:9200/shakespeare 
--data-binary @shakes-mapping.json

wget http://media.sundog-soft.com/es7/shakespeare_7.0.json

curl -H 'Content-Type: application/json' -XPOST
'127.0.0.1:9200/shakespeare/_bulk?pretty' --data-binary
@shakespeare_7.0.json

curl -H 'Content-Type: application/json' -XGET
'127.0.0.1:9200/shakespeare/_search?pretty' -d '
{
"query" : {
"match_phrase" : {
"text_entry" : "to be or not to be"
}
}
}
'
 

Optional: Join Our List

Join our low-frequency mailing list to stay informed on new courses and promotions from Sundog Education. As a thank you, we’ll send you a free course on Deep Learning and Neural Networks with Python, and discounts on all of Sundog Education’s other courses! Just click the button to get started.