{"id":2233,"date":"2016-01-06T20:07:56","date_gmt":"2016-01-06T19:07:56","guid":{"rendered":"http:\/\/codingexplained.com\/?p=2233"},"modified":"2017-06-11T18:56:09","modified_gmt":"2017-06-11T16:56:09","slug":"creating-an-index","status":"publish","type":"post","link":"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index","title":{"rendered":"Creating an Index"},"content":{"rendered":"<p>In this article, we\u00a0will see\u00a0how to add an index to our Elasticsearch cluster. To do this, we will be using the Kibana plugin, Sense, which we installed in a previous article. To create an index in Elasticsearch, simply issue a PUT request like below.<\/p>\n<pre><code>PUT \/ecommerce\r\n{\r\n\r\n}<\/code><\/pre>\n<p>This command is translated into an HTTP request that uses the HTTP verb <span class=\"code\">PUT<\/span>. So while we are\u00a0using a relative URI, you would have to use a fully qualified URL when using cURL or when connecting to Elasticsearch in an application. In fact, Sense can help you with this; by\u00a0clicking the wrench icon and clicking &#8220;Copy as cURL&#8221;, Sense will give you the corresponding cURL request.\u00a0Additionally, if you copy a cURL request into Sense, it will automatically format it to the Sense syntax, which is pretty useful.<\/p>\n<p>After issuing the request,\u00a0let&#8217;s confirm that the index has been created\u00a0by issuing another request. Using the <span class=\"code\">_cat<\/span> API, we can retrieve a lot of information about our cluster in a human friendly format (i.e. not JSON). For now, we will just make use of the indices command.<\/p>\n<pre><code>GET \/_cat\/indices?v<\/code><\/pre>\n<p>The <span class=\"code\">v<\/span> query parameter is used to make the output verbose, i.e. including descriptive column headers.\u00a0The result shows various information about the indexes in our cluster, such as the number of primary shards, replicas, documents, deleted documents, etc.<\/p>\n<pre><code>health status index pri rep docs.count docs.deleted store.size pri.store.size\r\nyellow open .kibana 1 1 2 0 5kb 5kb\r\nyellow open ecommerce 5 1 4110 5 681kb 681kb<\/code><\/pre>\n<p>Note that the indexes have a yellow health tagged to them. Yellow means that some replicas are not allocated. The reason this happens is that by default,\u00a0Elasticsearch created one replica for the indexes. Since we only have one node running at the moment, that one replica cannot yet be allocated for high\u00a0availability, until a later point in time when another node joins the cluster. Once an indexe&#8217;s replica gets allocated onto a second node, the health\u00a0status for that index will turn to green.<\/p>\n<p>It is also worth mentioning that one does not have to create an index before adding a document to it. By simply adding a document with a <span class=\"code\">PUT<\/span> request,\u00a0Elasticsearch will take care of creating the index for us, using default settings. While this is very convenient, adding an index in advance gives you\u00a0more control up-front.<\/p>\n<p>We have now added the first index to our Elasticsearch cluster, and that&#8217;s all we set out to accomplish in this article.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"series\">Part 6 of 35 in the <a href=\"https:\/\/codingexplained.com\/tutorial\/complete-guide-to-elasticsearch\" class=\"series-163\" title=\"Complete Guide to Elasticsearch\">Complete Guide to Elasticsearch<\/a> series<\/div><p>In this article, we\u00a0will see\u00a0how to add an index to our Elasticsearch cluster. To do this, we will be using the Kibana plugin, Sense, which we installed in a previous article. To create an index in Elasticsearch, simply issue a PUT request like below. PUT \/ecommerce { } This command is translated into an HTTP&hellip; <a href=\"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index\" class=\"more-link\">read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"Creating an Index","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[154],"tags":[155],"series":[163],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Creating an Index in Elasticsearch - Coding Explained<\/title>\n<meta name=\"description\" content=\"This article shows how to easily add an index to an Elasticsearch cluster. Adding an index to Elasticsearch can be done with one request.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating an Index in Elasticsearch - Coding Explained\" \/>\n<meta property=\"og:description\" content=\"This article shows how to easily add an index to an Elasticsearch cluster. Adding an index to Elasticsearch can be done with one request.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index\" \/>\n<meta property=\"og:site_name\" content=\"Coding Explained\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codingexplained\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codingexplained\" \/>\n<meta property=\"article:published_time\" content=\"2016-01-06T19:07:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-06-11T16:56:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codingexplained.com\/wp-content\/uploads\/2015\/11\/codingexplained-fb-promote.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"444\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Bo Andersen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codingexplained\" \/>\n<meta name=\"twitter:site\" content=\"@codingexplained\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bo Andersen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index\",\"url\":\"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index\",\"name\":\"Creating an Index in Elasticsearch - Coding Explained\",\"isPartOf\":{\"@id\":\"https:\/\/codingexplained.com\/#website\"},\"datePublished\":\"2016-01-06T19:07:56+00:00\",\"dateModified\":\"2017-06-11T16:56:09+00:00\",\"author\":{\"@id\":\"https:\/\/codingexplained.com\/#\/schema\/person\/e19c92ec991f571605f047cefeaa950d\"},\"description\":\"This article shows how to easily add an index to an Elasticsearch cluster. Adding an index to Elasticsearch can be done with one request.\",\"breadcrumb\":{\"@id\":\"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/codingexplained.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Creating an Index\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/codingexplained.com\/#website\",\"url\":\"https:\/\/codingexplained.com\/\",\"name\":\"Coding Explained\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/codingexplained.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/codingexplained.com\/#\/schema\/person\/e19c92ec991f571605f047cefeaa950d\",\"name\":\"Bo Andersen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codingexplained.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/28f5826f9d5d544b0c5e1ec321dfdfb8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/28f5826f9d5d544b0c5e1ec321dfdfb8?s=96&d=mm&r=g\",\"caption\":\"Bo Andersen\"},\"description\":\"I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!\",\"sameAs\":[\"https:\/\/codingexplained.com\",\"https:\/\/www.facebook.com\/codingexplained\",\"https:\/\/www.linkedin.com\/in\/ba0708\",\"https:\/\/twitter.com\/codingexplained\",\"https:\/\/www.youtube.com\/c\/codingexplained\"],\"url\":\"https:\/\/codingexplained.com\/author\/andy\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Creating an Index in Elasticsearch - Coding Explained","description":"This article shows how to easily add an index to an Elasticsearch cluster. Adding an index to Elasticsearch can be done with one request.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index","og_locale":"en_US","og_type":"article","og_title":"Creating an Index in Elasticsearch - Coding Explained","og_description":"This article shows how to easily add an index to an Elasticsearch cluster. Adding an index to Elasticsearch can be done with one request.","og_url":"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index","og_site_name":"Coding Explained","article_publisher":"https:\/\/www.facebook.com\/codingexplained","article_author":"https:\/\/www.facebook.com\/codingexplained","article_published_time":"2016-01-06T19:07:56+00:00","article_modified_time":"2017-06-11T16:56:09+00:00","og_image":[{"width":1200,"height":444,"url":"https:\/\/codingexplained.com\/wp-content\/uploads\/2015\/11\/codingexplained-fb-promote.png","type":"image\/png"}],"author":"Bo Andersen","twitter_card":"summary_large_image","twitter_creator":"@codingexplained","twitter_site":"@codingexplained","twitter_misc":{"Written by":"Bo Andersen","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index","url":"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index","name":"Creating an Index in Elasticsearch - Coding Explained","isPartOf":{"@id":"https:\/\/codingexplained.com\/#website"},"datePublished":"2016-01-06T19:07:56+00:00","dateModified":"2017-06-11T16:56:09+00:00","author":{"@id":"https:\/\/codingexplained.com\/#\/schema\/person\/e19c92ec991f571605f047cefeaa950d"},"description":"This article shows how to easily add an index to an Elasticsearch cluster. Adding an index to Elasticsearch can be done with one request.","breadcrumb":{"@id":"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/codingexplained.com\/coding\/elasticsearch\/creating-an-index#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codingexplained.com\/"},{"@type":"ListItem","position":2,"name":"Creating an Index"}]},{"@type":"WebSite","@id":"https:\/\/codingexplained.com\/#website","url":"https:\/\/codingexplained.com\/","name":"Coding Explained","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codingexplained.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/codingexplained.com\/#\/schema\/person\/e19c92ec991f571605f047cefeaa950d","name":"Bo Andersen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codingexplained.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/28f5826f9d5d544b0c5e1ec321dfdfb8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/28f5826f9d5d544b0c5e1ec321dfdfb8?s=96&d=mm&r=g","caption":"Bo Andersen"},"description":"I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!","sameAs":["https:\/\/codingexplained.com","https:\/\/www.facebook.com\/codingexplained","https:\/\/www.linkedin.com\/in\/ba0708","https:\/\/twitter.com\/codingexplained","https:\/\/www.youtube.com\/c\/codingexplained"],"url":"https:\/\/codingexplained.com\/author\/andy"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3mJkW-A1","_links":{"self":[{"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts\/2233"}],"collection":[{"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/comments?post=2233"}],"version-history":[{"count":4,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts\/2233\/revisions"}],"predecessor-version":[{"id":2910,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts\/2233\/revisions\/2910"}],"wp:attachment":[{"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/media?parent=2233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/categories?post=2233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/tags?post=2233"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/series?post=2233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}