Getting Started With Elasticsearch
A visitor to an eCommerce website would look up a product by searching for it in an input text box with the search term, such as “cookie cutter”. A good eCommerce website then uses a search engine to find all variations of the search terms, ranks the results, and displays the results ordered by relevance to the user. ElasticSearch is one such search engine that is commonly used as a document-oriented database for the text-search use case.
To install ElasticSearch on a RedHat-based operating system, we follow the ElasticSearch website’s instructions here. In this example, we are installing on an Amazon Linux EC2 virtual machine where we already have the OpenJDK installed with “yum install java-1.8.0-openjdk”.
The first step is to add the location for the ElasticSearch RPM repository. To do this, we create the repo file in /etc/yum.repos.d/(any name).repo as instructed on the ElasticSearch website (see URL above), and we install the elasticsearch package with “sudo yum install -y –enablerepo=elasticsearch elasticsearch”.
After installing the elasticsearch package, we edit the ElasticSearch configuration file with the command “sudo vi /etc/elasticsearch/elasticsearch.yml” and we change the following (press “i” to enter the edit mode of the vi editor):
node.name: node-1
network-host: 0.0.0.0
http.port: 9200 #This is the default port number
discovery.seed_hosts: ["127.0.0.1"]
cluster.initial_master_nodes: ["node-1"]
We then save the file (press Esc followed by “:x” and press enter to leave the edit mode and to save the file and exit from the vi editor), and start the service with “sudo systemctl start elasticsearch” (use “sudo systemctl enable elasticsearch” to get ElasticSearch to launch on bootup).
Note: You can add a user to the elasticsearch Linux user group with the command “sudo usermod -a -G elasticsearch (username)” (the “-a” stands for append, to prevent usermod from dropping the user from the existing groups that he or she is a member of). Also see the “gpasswd” utility.
To test if ElasticSearch is running, we use the curl command like this:
curl localhost:9200