Hands on Elasticsearch

Mayank Patel
Oct 26, 2017 · 5 min read

Components of the Elastic Stack

Source: https://www.elastic.co/products/elasticsearch
Source: https://www.elastic.co/products/x-pack

What is Elastisearch ? and Benefits:

Elasticsearch Use Cases


Elasticsearch Terminology


Downloading and Running Elasticsearch

bin/elasticsearch
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:5.6.3

Using the REST API

Creating Index

PUT /user
{
"mappings": {
"userprimaryinfo": {
"properties": {
"firstName": {
"type": "text"
},
"lastName": {
"type": "text"
},
"userId": {
"type": "text"
}
}
},
"usercontactinfo": {
"properties": {
"email": {
"type": "text"
},
"phone": {
"type" : "text"
},
"userId": {
"type": "text"
}
}
}
}
}

Create/Insert User information

POST /user/userprimaryinfo
{
"firstName" : "John",
"lastName" : "Smith",
"userId" : "jsmith"
}
POST /user/usercontactinfo
{
"email" : "jsmith@hello.com",
"phone" : "1112223333",
"userId" : "jsmith"
}
POST /user/usercontactinfo
{
"firstName" : "John",
"lastName" : "Doe",
"userId" : "jdoe"
}
POST /user/userprimaryinfo
{
"email" : "jdoe@hello.com",
"phone" : "2223334444",
"userId" : "jdoe"
}
GET /user/userprimaryinfo/_search
{
"query" : {
"term" : { "userId" : "jdoe" }
}
}

Understanding Response

Source: ElasticSearch 101 – a getting started tutorial By Joel Abrahamsson

Searching Examples:

GET /user/userprimaryinfo/_search?q=JohnGET /user/usercontactinfo/_search?q=*333
GET /user/userprimaryinfo,usercontactinfo/_search?q=jdoe
GET /user/userprimaryinfo,usercontactinfo/_search
{
"query": {
"match" : {

"userId" : "jdoe"
}
},
"sort": [
{
"_type": {
"order": "asc"
}
}
]
}

Elasticsearch Awesome Features

Elastisearch Analyzers:




Mayank Patel

Written by

System Architect at Drillinginfo

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade