{"id":2282,"date":"2016-01-17T02:36:30","date_gmt":"2016-01-17T01:36:30","guid":{"rendered":"http:\/\/codingexplained.com\/?p=2282"},"modified":"2017-06-11T18:05:58","modified_gmt":"2017-06-11T16:05:58","slug":"adding-documents-to-an-index","status":"publish","type":"post","link":"https:\/\/codingexplained.com\/coding\/elasticsearch\/adding-documents-to-an-index","title":{"rendered":"Adding Documents to an Index"},"content":{"rendered":"<p>To add a document to our Elasticsearch index, let&#8217;s open Sense and issue a <span class=\"code\">PUT<\/span> request. When adding a document to an index, it is optional if you want to supply an ID for the document. If the ID is omitted, then Elasticsearch will generate a random ID and then use it to index the document. In this case, you should use the <span class=\"code\">POST<\/span> verb instead of <span class=\"code\">PUT<\/span>. In this example, however, I will supply the ID, so I will issue a <span class=\"code\">PUT<\/span> request and add the ID in the URL.<\/p>\n<p>Enter the following command and issue the request.<\/p>\n<pre><code class=\"json\">PUT \/ecommerce\/product\/1001\r\n{\r\n  \"name\": \"Zend Framework 2: From Beginner to Professional\",\r\n  \"price\": \"40.00\",\r\n  \"description\": \"Learn Zend Framework 2 in just a few hours!\",\r\n  \"status\": \"active\",\r\n  \"quantity\": 1,\r\n  \"categories\": [{\r\n    \"name\": \"Software\"\r\n  }],\r\n  \"tags\": [\"zend framework\", \"zf2\", \"php\", \"programming\"]\r\n}<\/code><\/pre>\n<p>As you can see, adding a document is pretty straightforward, as all it takes is knowledge of basic JSON.<\/p>\n<p>The document has now been added to the index and is now searchable. Let&#8217;s confirm this by opening Kibana and going to the &#8220;Discover&#8221; tab. Remember that Kibana is located at <a href=\"http:\/\/localhost:5601\" target=\"_blank\" rel=\"nofollow\">http:\/\/localhost:5601<\/a>. We should be able to find the document by searching for &#8220;zend framework&#8221;.<\/p>\n<p>As you can see in the results, the document that we just added shows up, and the matching parts of the document are highlighted in yellow. We are going to get into more details of writing search queries later in this course, so for now, I just wanted to show you that our document does indeed exist within the index.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"series\">Part 13 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>To add a document to our Elasticsearch index, let&#8217;s open Sense and issue a PUT request. When adding a document to an index, it is optional if you want to supply an ID for the document. If the ID is omitted, then Elasticsearch will generate a random ID and then use it to index the&hellip; <a href=\"https:\/\/codingexplained.com\/coding\/elasticsearch\/adding-documents-to-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":"Adding Documents to 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>Adding Documents to an Index<\/title>\n<meta name=\"description\" content=\"This article shows you how to easily add documents to an Elasticsearch index. Knowing JSON is enough to add a document to Elasticsearch.\" \/>\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\/adding-documents-to-an-index\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Adding Documents to an Index\" \/>\n<meta property=\"og:description\" content=\"This article shows you how to easily add documents to an Elasticsearch index. Knowing JSON is enough to add a document to Elasticsearch.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codingexplained.com\/coding\/elasticsearch\/adding-documents-to-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-17T01:36:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-06-11T16:05:58+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=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/codingexplained.com\/coding\/elasticsearch\/adding-documents-to-an-index\",\"url\":\"https:\/\/codingexplained.com\/coding\/elasticsearch\/adding-documents-to-an-index\",\"name\":\"Adding Documents to an Index\",\"isPartOf\":{\"@id\":\"https:\/\/codingexplained.com\/#website\"},\"datePublished\":\"2016-01-17T01:36:30+00:00\",\"dateModified\":\"2017-06-11T16:05:58+00:00\",\"author\":{\"@id\":\"https:\/\/codingexplained.com\/#\/schema\/person\/e19c92ec991f571605f047cefeaa950d\"},\"description\":\"This article shows you how to easily add documents to an Elasticsearch index. Knowing JSON is enough to add a document to Elasticsearch.\",\"breadcrumb\":{\"@id\":\"https:\/\/codingexplained.com\/coding\/elasticsearch\/adding-documents-to-an-index#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/codingexplained.com\/coding\/elasticsearch\/adding-documents-to-an-index\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/codingexplained.com\/coding\/elasticsearch\/adding-documents-to-an-index#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/codingexplained.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Adding Documents to 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":"Adding Documents to an Index","description":"This article shows you how to easily add documents to an Elasticsearch index. Knowing JSON is enough to add a document to Elasticsearch.","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\/adding-documents-to-an-index","og_locale":"en_US","og_type":"article","og_title":"Adding Documents to an Index","og_description":"This article shows you how to easily add documents to an Elasticsearch index. Knowing JSON is enough to add a document to Elasticsearch.","og_url":"https:\/\/codingexplained.com\/coding\/elasticsearch\/adding-documents-to-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-17T01:36:30+00:00","article_modified_time":"2017-06-11T16:05:58+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":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/codingexplained.com\/coding\/elasticsearch\/adding-documents-to-an-index","url":"https:\/\/codingexplained.com\/coding\/elasticsearch\/adding-documents-to-an-index","name":"Adding Documents to an Index","isPartOf":{"@id":"https:\/\/codingexplained.com\/#website"},"datePublished":"2016-01-17T01:36:30+00:00","dateModified":"2017-06-11T16:05:58+00:00","author":{"@id":"https:\/\/codingexplained.com\/#\/schema\/person\/e19c92ec991f571605f047cefeaa950d"},"description":"This article shows you how to easily add documents to an Elasticsearch index. Knowing JSON is enough to add a document to Elasticsearch.","breadcrumb":{"@id":"https:\/\/codingexplained.com\/coding\/elasticsearch\/adding-documents-to-an-index#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codingexplained.com\/coding\/elasticsearch\/adding-documents-to-an-index"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/codingexplained.com\/coding\/elasticsearch\/adding-documents-to-an-index#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codingexplained.com\/"},{"@type":"ListItem","position":2,"name":"Adding Documents to 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-AO","_links":{"self":[{"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts\/2282"}],"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=2282"}],"version-history":[{"count":3,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts\/2282\/revisions"}],"predecessor-version":[{"id":2902,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts\/2282\/revisions\/2902"}],"wp:attachment":[{"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/media?parent=2282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/categories?post=2282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/tags?post=2282"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/series?post=2282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}