{"id":3490,"date":"2015-01-08T23:16:14","date_gmt":"2015-01-08T23:16:14","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/2015\/01\/08\/working-with-indexes-in-elasticsearch\/"},"modified":"2021-08-16T22:55:56","modified_gmt":"2021-08-17T02:55:56","slug":"working-with-indexes-in-elasticsearch","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/","title":{"rendered":"Working with indexes in Elasticsearch"},"content":{"rendered":"<p>Indexes in Elasticsearch are collections of data that hold similar characteristics.  For example, if you had an index of web hosting plans, it would contain several documents such as shared, VPS, dedicated, and reseller.  Simply put, indexes allow you to group similar data together to search through those related items.<\/p>\n<div class=\"in_this_tutorial\">\n<h2>In this tutorial:<\/h2>\n<p><a class=\"btn btn-primary\" href=\"#listing\" type=\"button\">Listing indexes<\/a> <a class=\"btn btn-primary\" href=\"#creating\" type=\"button\">Creating indexes<\/a> <a class=\"btn btn-primary\" href=\"#deleting\" type=\"button\">Deleting indexes<\/a><\/p>\n<\/div>\n<p>Information within Elasticsearch is created and retrieved using HTTP requests, usually containing JSON data with the request.<\/p>\n<div class=\"alert alert-warning\">\n<p><strong>Note:<\/strong> This article assumes that you have already <a href=\"\/support\/edu\/software\/how-to-install-elasticsearch\/\">installed Elasticsearch<\/a> as well as know how to use <a href=\"\/support\/server\/ssh\/how-to-login-ssh\/\">SSH<\/a>.<\/p>\n<\/div>\n<p><a name=\"listing\"><\/a><\/p>\n<h2>Listing all indexes in ElasticSearch<\/h2>\n<p>If you have various indexes within Elasticsearch, chances are you haven&#8217;t memorized them all.  The following command will allow you to list all indexes that are present within your Elasticsearch server:<\/p>\n<p class=\"code_block\">curl &#8216;localhost:9200\/_cat\/indices?v&#8217;<\/p>\n<p>As you can see in the above, we are first using the <em>curl<\/em> command to send the HTTP request.  Within the quotes, you see our server, which is <em>localhost<\/em>, meaning that we are making the request to the same server that we are currently in, then the port which is 9200.<\/p>\n<p>After the server is defined, we are then telling Elasticsearch that we will be sending a <em>cat<\/em> command by entering <em>_cat<\/em>, then telling it that we want to obtain the indices.<\/p>\n<p>The last part is <em>?v<\/em> which tells Elasticsearch that we want a verbose output.  This is optional, but allows the column headers to be seen.<\/p>\n<p>Your output should looks something like this:<\/p>\n<p class=\"code_block\">user@server [~]# curl &#8216;localhost:9200\/_cat\/indices?v&#8217;<br \/>\nhealth status index           pri rep docs.count docs.deleted store.size pri.store.size<br \/>\nyellow open   mynewindex        5   1          0            0       575b           575b<br \/>\nyellow open   secondindex       5   1          0            0       575b           575b<br \/>\nyellow open   yetanotherindex   5   1          0            0       575b           575b<\/p>\n<p>There&#8217;s a lot of information here, but for the purpose of this article, we will just focus on the indexes that exist.  If you take a look at the <em>index<\/em> column, there&#8217;s a list of all indexes currently present.  If this command doesn&#8217;t output anything there, you don&#8217;t have any indexes defined and should continue on to the next step which is creating indexes in Elasticsearch.<\/p>\n<p><a name=\"creating\"><\/a><\/p>\n<h2>Creating indexes in Elasticsearch<\/h2>\n<p>In the example below, we are using cURL to send a PUT request to the ElasticSearch server with our new index:<\/p>\n<p class=\"code_block\">curl -XPUT &#8216;localhost:9200\/mynewindex?pretty&#8217;<\/p>\n<p>As you can see above, we first call the <em>curl<\/em> command, then the <em>XPUT<\/em> flag to tell cURL that we want to use the PUT verb when sending the request.<\/p>\n<p>Then within the quotes, we have the location and path that we want to send the request to.  In this example, our server is the same server that we are sending the request from, so we can use <em>localhost<\/em> for the server.  By default, the Elasticsearch server runs on port 9200, so we have also included this as well so that the request is properly passed to Elasticsearch.<\/p>\n<p>Next in the path is <em>mynewindex<\/em>.  This is simply the name of the index that we want to create.  You can name your index absolutely anything you want, but it does need to be all lower-case.<\/p>\n<p>Our final piece of the request being sent to the server is <em>?pretty<\/em>.  This is an optional argument that you can use to return better formatted results.  It&#8217;s all a matter of preference, but most users would like to see the JSON output properly tabbed and easier to read.<\/p>\n<p>Once the request has been completed, you will receive a confirmation that looks like this:<\/p>\n<p class=\"code_block\">user@server [~]# curl -XPUT &#8216;localhost:9200\/mynewindex?pretty&#8217;<br \/>\n{<br \/>\n&#8220;acknowledged&#8221; : true<br \/>\n}<\/p>\n<p>As you can see, we are presented with <em>acknowledged: true<\/em> which means that the query was executed successfully and the index was inserted.<\/p>\n<p><a name=\"deleting\"><\/a><\/p>\n<h2>Deleting indexes in Elasticsearch<\/h2>\n<p>Deleting indexes is very similar to creating them, but instead we use the DELETE verb within our HTTP request.  For example, the following will delete the <em>mynewindex<\/em> index:<\/p>\n<p class=\"code_block\">curl -XDELETE &#8216;localhost:9200\/mynewindex?pretty&#8217;<\/p>\n<p>As you can see, the request is identical with the exception that the verb that we are sending with our HTTP request is DELETE instead of PUT.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Indexes in Elasticsearch are collections of data that hold similar characteristics. For example, if you had an index of web hosting plans, it would contain several documents such as shared, VPS, dedicated, and reseller. Simply put, indexes allow you to group similar data together to search through those related items. In this tutorial: Listing indexes<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/\"> Read More ><\/a><\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4360],"tags":[],"class_list":["post-3490","post","type-post","status-publish","format-standard","hentry","category-software"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Working with indexes in Elasticsearch | InMotion Hosting<\/title>\n<meta name=\"description\" content=\"Working with indexes in Elasticsearch can feel a bit difficult if you&#039;re new to it, but we&#039;ll show you how to work with them like a pro.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Working with indexes in Elasticsearch | InMotion Hosting\" \/>\n<meta property=\"og:description\" content=\"Working with indexes in Elasticsearch can feel a bit difficult if you&#039;re new to it, but we&#039;ll show you how to work with them like a pro.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/\" \/>\n<meta property=\"og:site_name\" content=\"InMotion Hosting Support Center\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/inmotionhosting\/\" \/>\n<meta property=\"article:published_time\" content=\"2015-01-08T23:16:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-17T02:55:56+00:00\" \/>\n<meta name=\"author\" content=\"Jeff Matson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:site\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeff Matson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/\"},\"author\":{\"name\":\"Jeff Matson\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/83776252b196c020e4352a3796e5642b\"},\"headline\":\"Working with indexes in Elasticsearch\",\"datePublished\":\"2015-01-08T23:16:14+00:00\",\"dateModified\":\"2021-08-17T02:55:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/\"},\"wordCount\":684,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"articleSection\":[\"Software\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/\",\"name\":\"Working with indexes in Elasticsearch | InMotion Hosting\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"datePublished\":\"2015-01-08T23:16:14+00:00\",\"dateModified\":\"2021-08-17T02:55:56+00:00\",\"description\":\"Working with indexes in Elasticsearch can feel a bit difficult if you're new to it, but we'll show you how to work with them like a pro.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Working with indexes in Elasticsearch\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"name\":\"InMotion Hosting Support Center\",\"description\":\"Web Hosting Support &amp; Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\",\"name\":\"InMotion Hosting\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"width\":696,\"height\":696,\"caption\":\"InMotion Hosting\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/inmotionhosting\/\",\"https:\/\/x.com\/InMotionHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/83776252b196c020e4352a3796e5642b\",\"name\":\"Jeff Matson\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/author\/jeffma\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Working with indexes in Elasticsearch | InMotion Hosting","description":"Working with indexes in Elasticsearch can feel a bit difficult if you're new to it, but we'll show you how to work with them like a pro.","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:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/","og_locale":"en_US","og_type":"article","og_title":"Working with indexes in Elasticsearch | InMotion Hosting","og_description":"Working with indexes in Elasticsearch can feel a bit difficult if you're new to it, but we'll show you how to work with them like a pro.","og_url":"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2015-01-08T23:16:14+00:00","article_modified_time":"2021-08-17T02:55:56+00:00","author":"Jeff Matson","twitter_card":"summary_large_image","twitter_creator":"@InMotionHosting","twitter_site":"@InMotionHosting","twitter_misc":{"Written by":"Jeff Matson","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/"},"author":{"name":"Jeff Matson","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/83776252b196c020e4352a3796e5642b"},"headline":"Working with indexes in Elasticsearch","datePublished":"2015-01-08T23:16:14+00:00","dateModified":"2021-08-17T02:55:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/"},"wordCount":684,"commentCount":0,"publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"articleSection":["Software"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/","url":"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/","name":"Working with indexes in Elasticsearch | InMotion Hosting","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"datePublished":"2015-01-08T23:16:14+00:00","dateModified":"2021-08-17T02:55:56+00:00","description":"Working with indexes in Elasticsearch can feel a bit difficult if you're new to it, but we'll show you how to work with them like a pro.","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/software\/working-with-indexes-in-elasticsearch\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"Working with indexes in Elasticsearch"}]},{"@type":"WebSite","@id":"https:\/\/www.inmotionhosting.com\/support\/#website","url":"https:\/\/www.inmotionhosting.com\/support\/","name":"InMotion Hosting Support Center","description":"Web Hosting Support &amp; Tutorials","publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.inmotionhosting.com\/support\/#organization","name":"InMotion Hosting","url":"https:\/\/www.inmotionhosting.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","width":696,"height":696,"caption":"InMotion Hosting"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/inmotionhosting\/","https:\/\/x.com\/InMotionHosting"]},{"@type":"Person","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/83776252b196c020e4352a3796e5642b","name":"Jeff Matson","url":"https:\/\/www.inmotionhosting.com\/support\/author\/jeffma\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"primary_category":null,"_links":{"self":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/comments?post=3490"}],"version-history":[{"count":2,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3490\/revisions"}],"predecessor-version":[{"id":84141,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3490\/revisions\/84141"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=3490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=3490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=3490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}