Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Crash Course of Elasticsearch in 10 mins

What is Elasticsearch?
Elasticsearch is fast, horizontally scalable open source search engine. It provides HTTP API for storing and indexing JSON documents and with default configuration it behaves a little bit like searchable NoSQL database.

Installation – RHEL/Centos

Install and Configure Elasticsearch: Step by Step Guide

Check node’s health status:
$ curl 127.0.0.1:9200/_cat/health?v

Get list of current indices
$ curl 127.00.1:9200/_cat/indices?v

Understanding Elasticsearch Keywords and Terminology

Understanding Elasticsearch Keywords and Terminology

CRUD Operations using RESTful API of Elasticsearch using Create, Read, Update, Delete

[code]

Create – Adding new document to elasticsearch is as easy as HTTP POST request:
$ curl -X POST 127.0.0.1:9200/monitor/logs?pretty -d ‘{
“kind”: “info”,
“message”: “The server is up and running”
}’
#{
# “_index” : “monitor”,
# “_type” : “logs”,
# “_id” : “AVoWblBE6fU5oFCNC7jY”,
# “_version” : 1,
# “result” : “created”,
# “_shards” : {
# “total” : 2,
# “successful” : 1,
# “failed” : 0
# },
# “created” : true
#}

As not many people would actually enjoy inserting documents one by one, there’s also bulk insert option.

$ curl -X POST 127.0.0.1:9200/monitor/logs/_bulk -d ‘
{ “index”: {}}
{ “kind” : “warn”, “message”: “Using 90% of memory” }
{ “index”: {}}
{ “kind”: “err”, “message”: “OutOfMemoryException: Epic fail has just happened” }

Read – when we have something in the index, we can perform simple search to read the documents back.

curl 127.0.0.1:9200/monitor/_search?pretty
#{
# ………
# “hits” : {
# “total” : 3,
# “max_score” : 1.0,
# “hits” : [
# {
# “_index” : “monitor”,
# “_type” : “logs”,
# “_id” : “AVoWe_7d6fU5oFCNC7jb”,
# “_score” : 1.0,
# “_source” : {
# “kind” : “err”,
# “message” : “OutOfMemoryException: Epic fail has just happened”
# }
# },
# {
# “_index” : “monitor”,
# “_type” : “logs”,
# “_id” : “AVoWe_7d6fU5oFCNC7ja”,
# “_score” : 1.0,
# “_source” : {
# “kind” : “warn”,
# “message” : “Using 90% of memory”
# }
# },
# {
# “_index” : “monitor”,
# “_type” : “logs”,
# “_id” : “AVoWblBE6fU5oFCNC7jY”,
# “_score” : 1.0,
# “_source” : {
# “kind” : “info”,
# “message” : “The server is up and running”
# }
# }
# ]
# }
#}

It’s also possible to get single document by its ID:

curl 127.0.0.1:9200/monitor/logs/AVoWblBE6fU5oFCNC7jY?pretty
#{
# …
# “_source” : {
# “kind” : “info”,
# “message” : “The server is up and running”
# }
#}

Update – Similarly, knowing document ID we can update it.

$ curl -X POST 127.0.0.1:9200/monitor/logs/AVoWe_7d6fU5oFCNC7jb -d ‘
{ “kind”: “err”,
“message”: “OutOfMemoryException: The server process used all available memory”
}’

Delete – When you need to get rid of something, HTTP DELETE will do the trick. E.g.
$ curl -X DELETE 127.0.0.1:9200/monitor/logs/AVoWe_7d6fU5oFCNC7jb

Search – The real power of elasticsearch is in search (duh). There’re two approaches for searching for data: the REST Request API for simple queries and more sophisticated Query DSL.

$ curl -s 127.0.0.1:9200/monitor/_search?q=memory | json_pp
$ curl -s 127.0.0.1:9200/monitor/_search -d ‘

[/code]

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x