{"id":5380,"date":"2018-09-27T03:15:15","date_gmt":"2018-09-27T03:15:15","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=5380"},"modified":"2025-05-04T06:08:22","modified_gmt":"2025-05-04T06:08:22","slug":"crash-course-of-elasticsearch-in-10-mins","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/crash-course-of-elasticsearch-in-10-mins\/","title":{"rendered":"Crash Course of Elasticsearch in 10 mins"},"content":{"rendered":"<p><strong>What is Elasticsearch?<\/strong><br \/>\nElasticsearch 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.<\/p>\n<p><strong>Installation &#8211; RHEL\/Centos<\/strong><\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"rEV1tGVSZd\"><p><a href=\"https:\/\/www.devopsschool.com\/blog\/install-and-configure-elasticsearch-step-by-step-guide\/\">Install and Configure Elasticsearch: Step by Step Guide<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;Install and Configure Elasticsearch: Step by Step Guide&#8221; &#8212; \" src=\"https:\/\/www.devopsschool.com\/blog\/install-and-configure-elasticsearch-step-by-step-guide\/embed\/#?secret=usJszIHMYj#?secret=rEV1tGVSZd\" data-secret=\"rEV1tGVSZd\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p><strong>Check node\u2019s health status:<\/strong><br \/>\n$ curl 127.0.0.1:9200\/_cat\/health?v<\/p>\n<p><strong>Get list of current indices<\/strong><br \/>\n$ curl 127.00.1:9200\/_cat\/indices?v<\/p>\n<p><strong>Understanding Elasticsearch Keywords and Terminology<\/strong><\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"qy9GRfSBx5\"><p><a href=\"https:\/\/www.devopsschool.com\/blog\/understanding-elasticsearch-keywords-and-terminology\/\">Understanding Elasticsearch Keywords and Terminology<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;Understanding Elasticsearch Keywords and Terminology&#8221; &#8212; \" src=\"https:\/\/www.devopsschool.com\/blog\/understanding-elasticsearch-keywords-and-terminology\/embed\/#?secret=QfJblPyLwe#?secret=qy9GRfSBx5\" data-secret=\"qy9GRfSBx5\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p><strong>CRUD Operations using RESTful API of Elasticsearch using Create, Read, Update, Delete<\/strong><\/p>\n<p>[code]<\/p>\n<p>Create &#8211; Adding new document to elasticsearch is as easy as HTTP POST request:<br \/>\n$ curl -X POST 127.0.0.1:9200\/monitor\/logs?pretty -d &#8216;{<br \/>\n&#8220;kind&#8221;: &#8220;info&#8221;,<br \/>\n&#8220;message&#8221;: &#8220;The server is up and running&#8221;<br \/>\n}&#8217;<br \/>\n#{<br \/>\n# &#8220;_index&#8221; : &#8220;monitor&#8221;,<br \/>\n# &#8220;_type&#8221; : &#8220;logs&#8221;,<br \/>\n# &#8220;_id&#8221; : &#8220;AVoWblBE6fU5oFCNC7jY&#8221;,<br \/>\n# &#8220;_version&#8221; : 1,<br \/>\n# &#8220;result&#8221; : &#8220;created&#8221;,<br \/>\n# &#8220;_shards&#8221; : {<br \/>\n# &#8220;total&#8221; : 2,<br \/>\n# &#8220;successful&#8221; : 1,<br \/>\n# &#8220;failed&#8221; : 0<br \/>\n# },<br \/>\n# &#8220;created&#8221; : true<br \/>\n#}<\/p>\n<p>As not many people would actually enjoy inserting documents one by one, there\u2019s also bulk insert option.<\/p>\n<p>$ curl -X POST 127.0.0.1:9200\/monitor\/logs\/_bulk -d &#8216;<br \/>\n{ &#8220;index&#8221;: {}}<br \/>\n{ &#8220;kind&#8221; : &#8220;warn&#8221;, &#8220;message&#8221;: &#8220;Using 90% of memory&#8221; }<br \/>\n{ &#8220;index&#8221;: {}}<br \/>\n{ &#8220;kind&#8221;: &#8220;err&#8221;, &#8220;message&#8221;: &#8220;OutOfMemoryException: Epic fail has just happened&#8221; }<br \/>\n&#8216;<\/p>\n<p>Read &#8211; when we have something in the index, we can perform simple search to read the documents back.<\/p>\n<p>curl 127.0.0.1:9200\/monitor\/_search?pretty<br \/>\n#{<br \/>\n# &#8230;&#8230;&#8230;<br \/>\n# &#8220;hits&#8221; : {<br \/>\n# &#8220;total&#8221; : 3,<br \/>\n# &#8220;max_score&#8221; : 1.0,<br \/>\n# &#8220;hits&#8221; : [<br \/>\n# {<br \/>\n# &#8220;_index&#8221; : &#8220;monitor&#8221;,<br \/>\n# &#8220;_type&#8221; : &#8220;logs&#8221;,<br \/>\n# &#8220;_id&#8221; : &#8220;AVoWe_7d6fU5oFCNC7jb&#8221;,<br \/>\n# &#8220;_score&#8221; : 1.0,<br \/>\n# &#8220;_source&#8221; : {<br \/>\n# &#8220;kind&#8221; : &#8220;err&#8221;,<br \/>\n# &#8220;message&#8221; : &#8220;OutOfMemoryException: Epic fail has just happened&#8221;<br \/>\n# }<br \/>\n# },<br \/>\n# {<br \/>\n# &#8220;_index&#8221; : &#8220;monitor&#8221;,<br \/>\n# &#8220;_type&#8221; : &#8220;logs&#8221;,<br \/>\n# &#8220;_id&#8221; : &#8220;AVoWe_7d6fU5oFCNC7ja&#8221;,<br \/>\n# &#8220;_score&#8221; : 1.0,<br \/>\n# &#8220;_source&#8221; : {<br \/>\n# &#8220;kind&#8221; : &#8220;warn&#8221;,<br \/>\n# &#8220;message&#8221; : &#8220;Using 90% of memory&#8221;<br \/>\n# }<br \/>\n# },<br \/>\n# {<br \/>\n# &#8220;_index&#8221; : &#8220;monitor&#8221;,<br \/>\n# &#8220;_type&#8221; : &#8220;logs&#8221;,<br \/>\n# &#8220;_id&#8221; : &#8220;AVoWblBE6fU5oFCNC7jY&#8221;,<br \/>\n# &#8220;_score&#8221; : 1.0,<br \/>\n# &#8220;_source&#8221; : {<br \/>\n# &#8220;kind&#8221; : &#8220;info&#8221;,<br \/>\n# &#8220;message&#8221; : &#8220;The server is up and running&#8221;<br \/>\n# }<br \/>\n# }<br \/>\n# ]<br \/>\n# }<br \/>\n#}<\/p>\n<p>It\u2019s also possible to get single document by its ID:<\/p>\n<p>curl 127.0.0.1:9200\/monitor\/logs\/AVoWblBE6fU5oFCNC7jY?pretty<br \/>\n#{<br \/>\n# &#8230;<br \/>\n# &#8220;_source&#8221; : {<br \/>\n# &#8220;kind&#8221; : &#8220;info&#8221;,<br \/>\n# &#8220;message&#8221; : &#8220;The server is up and running&#8221;<br \/>\n# }<br \/>\n#}<\/p>\n<p>Update &#8211; Similarly, knowing document ID we can update it.<\/p>\n<p>$ curl -X POST 127.0.0.1:9200\/monitor\/logs\/AVoWe_7d6fU5oFCNC7jb -d &#8216;<br \/>\n{ &#8220;kind&#8221;: &#8220;err&#8221;,<br \/>\n&#8220;message&#8221;: &#8220;OutOfMemoryException: The server process used all available memory&#8221;<br \/>\n}&#8217;<\/p>\n<p>Delete &#8211; When you need to get rid of something, HTTP DELETE will do the trick. E.g.<br \/>\n$ curl -X DELETE 127.0.0.1:9200\/monitor\/logs\/AVoWe_7d6fU5oFCNC7jb<\/p>\n<p>Search &#8211; The real power of elasticsearch is in search (duh). There\u2019re two approaches for searching for data: the REST Request API for simple queries and more sophisticated Query DSL.<\/p>\n<p>$ curl -s 127.0.0.1:9200\/monitor\/_search?q=memory | json_pp<br \/>\n$ curl -s 127.0.0.1:9200\/monitor\/_search -d &#8216;<\/p>\n<p>[\/code]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8211; RHEL\/Centos Install and Configure Elasticsearch: Step by Step Guide Check node\u2019s health status: $ curl 127.0.0.1:9200\/_cat\/health?v Get list&#8230;<\/p>\n","protected":false},"author":1,"featured_media":8088,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[5936],"tags":[535,883,5062,5063,5057,4666],"class_list":["post-5380","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-elastic","tag-centos","tag-course","tag-crash","tag-dummies","tag-elastic","tag-elasticsearch"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=5380"}],"version-history":[{"count":5,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5380\/revisions"}],"predecessor-version":[{"id":23788,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5380\/revisions\/23788"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/8088"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=5380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=5380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=5380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}