{"id":2338,"date":"2016-07-15T18:27:35","date_gmt":"2016-07-15T18:27:35","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=2338"},"modified":"2025-06-13T17:24:39","modified_gmt":"2025-06-14T00:24:39","slug":"deferring-of-index-creation","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/","title":{"rendered":"Deferring Index Creation"},"content":{"rendered":"<p>There is a feature in Couchbase 4.x that can really help with <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/architecture\/global-secondary-indexes.html\">Global Secondary Index<\/a> creation and many do not know about. It is the ability to queue index creation statements and then parallelize their creation for efficiency and performance.<\/p>\n<p>If you need to create multiple indexes at one time, you can defer the creation of the indexes. Then when you are ready, you tell the cluster to build those indexes. For example, I need to create two indexes, but I also want High Availability of my indexes, so I need a copy of each index on each of the <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/architecture\/global-secondary-indexes.html\">Index Service (IS)<\/a> nodes. In other words, four <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/n1ql\/n1ql-language-reference\/createindex.html\">CREATE INDEX<\/a> statements total.<\/p>\n<pre>CREATE INDEX idx01 ON bucketname(prop1) WHERE prop1 = \"value\" WITH {\"nodes\": [ \"node1:8091\" ], \"defer_build\":true};\r\n\r\nCREATE INDEX idx02 ON bucketname(prop1) WHERE prop1 = \"value\" WITH {\"nodes\": [ \"node2:8091\" ], \"defer_build\":true};\r\n\r\nCREATE INDEX idx03 ON bucketname(prop2) WHERE prop2 = \"value\" WITH {\"nodes\": [ \"node1:8091\" ], \"defer_build\":true};\r\n\r\nCREATE INDEX idx04 ON bucketname(prop2) WHERE prop2 = \"value\" WITH {\"nodes\": [ \"node2:8091\" ], \"defer_build\":true};\r\n\r\n<\/pre>\n<p>If you did nothing else, these indexes would stay in deferred\/created status. The next statement you need to call is <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/n1ql\/n1ql-language-reference\/build-index.html\">BUILD INDEX<\/a> as it will tell the cluster to actually initiate the build.<\/p>\n<pre>BUILD INDEX ON `bucketname`(`idx01`,`idx02`,`idx03`,`idx04`) USING GSI;<\/pre>\n<p>At this point the IS nodes will begin creating the indexes, but in parallel and even better is uses the same <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/architecture\/high-availability-replication-architecture.html\">Database Change Protocol (DCP)<\/a> stream from the Data Service nodes for better network IO utilization. If you built these without the defer, one would create and you\u2019d wait. Under the covers the index service node would create that one from a DCP stream. When that one was complete, you\u2019d put the next CREATE statement in and wait&#8230;another DCP stream of the same data. Keep doing that until all four are complete. All serially.<\/p>\n<p>With the defer_build and then the BUILD INDEX statement, you put all the create statements in at once and then go get coffee. Not only will the indexes be built in parallel on each IS node and between the two IS nodes, but each IS node will only need a DCP stream of the bucket\u2019s data once. So the whole process completes much faster and far more efficiently. Especially when scripting the creation of a lot <a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/createindex.html\">index creations<\/a>, then you can group these into batches.<\/p>\n<p>Give it a try and report back. For more information refer to the documentation on <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/n1ql\/n1ql-language-reference\/createindex.html\" target=\"_blank\" rel=\"noopener\">CREATE INDEX<\/a> and <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/n1ql\/n1ql-language-reference\/build-index.html\">BUILD INDEX<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is a feature in Couchbase 4.x that can really help with Global Secondary Index creation and many do not know about. It is the ability to queue index creation statements and then parallelize their creation for efficiency and performance. [&hellip;]<\/p>\n","protected":false},"author":23,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1821,1812],"tags":[1697,1695,1696],"ppma_author":[9008],"class_list":["post-2338","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-couchbase-architecture","category-n1ql-query","tag-create-index","tag-gsi","tag-indexing"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.7.1 (Yoast SEO v25.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Deferring Index Creation | Create Multiple Indexes at One Time<\/title>\n<meta name=\"description\" content=\"Defer the creation of the indexes if you need to create multiple indexes at one time. When you are ready you tell the cluster to build those indexes.\" \/>\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.couchbase.com\/blog\/deferring-of-index-creation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Deferring Index Creation\" \/>\n<meta property=\"og:description\" content=\"Defer the creation of the indexes if you need to create multiple indexes at one time. When you are ready you tell the cluster to build those indexes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-15T18:27:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T00:24:39+00:00\" \/>\n<meta name=\"author\" content=\"Kirk Kirkconnell, Senior Solutions Engineer, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirk Kirkconnell, Senior Solutions Engineer, Couchbase\" \/>\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\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/\"},\"author\":{\"name\":\"Kirk Kirkconnell, Senior Solutions Engineer, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/2887e38425754897cea2d896bf082e6d\"},\"headline\":\"Deferring Index Creation\",\"datePublished\":\"2016-07-15T18:27:35+00:00\",\"dateModified\":\"2025-06-14T00:24:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/\"},\"wordCount\":353,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"keywords\":[\"create index\",\"GSI\",\"Indexing\"],\"articleSection\":[\"Couchbase Architecture\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/\",\"name\":\"Deferring Index Creation | Create Multiple Indexes at One Time\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2016-07-15T18:27:35+00:00\",\"dateModified\":\"2025-06-14T00:24:39+00:00\",\"description\":\"Defer the creation of the indexes if you need to create multiple indexes at one time. When you are ready you tell the cluster to build those indexes.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deferring Index Creation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/2887e38425754897cea2d896bf082e6d\",\"name\":\"Kirk Kirkconnell, Senior Solutions Engineer, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/60a4ddb304fde12e65369919433b8dc7\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f704905856dcd1767d50024da51e2fa159eea665c85aff3224bc8763551d4e35?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f704905856dcd1767d50024da51e2fa159eea665c85aff3224bc8763551d4e35?s=96&d=mm&r=g\",\"caption\":\"Kirk Kirkconnell, Senior Solutions Engineer, Couchbase\"},\"description\":\"Kirk Kirkconnell was a Senior Solutions Engineer at Couchbase working with customers in multiple capacities to assist them in architecting, deploying, and managing Couchbase. His expertise is in operations, hosting, and support of large-scale application and database infrastructures.\",\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/kirk-kirkconnell\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Deferring Index Creation | Create Multiple Indexes at One Time","description":"Defer the creation of the indexes if you need to create multiple indexes at one time. When you are ready you tell the cluster to build those indexes.","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.couchbase.com\/blog\/deferring-of-index-creation\/","og_locale":"en_US","og_type":"article","og_title":"Deferring Index Creation","og_description":"Defer the creation of the indexes if you need to create multiple indexes at one time. When you are ready you tell the cluster to build those indexes.","og_url":"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/","og_site_name":"The Couchbase Blog","article_published_time":"2016-07-15T18:27:35+00:00","article_modified_time":"2025-06-14T00:24:39+00:00","author":"Kirk Kirkconnell, Senior Solutions Engineer, Couchbase","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirk Kirkconnell, Senior Solutions Engineer, Couchbase","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/"},"author":{"name":"Kirk Kirkconnell, Senior Solutions Engineer, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/2887e38425754897cea2d896bf082e6d"},"headline":"Deferring Index Creation","datePublished":"2016-07-15T18:27:35+00:00","dateModified":"2025-06-14T00:24:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/"},"wordCount":353,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","keywords":["create index","GSI","Indexing"],"articleSection":["Couchbase Architecture","SQL++ \/ N1QL Query"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/","url":"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/","name":"Deferring Index Creation | Create Multiple Indexes at One Time","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2016-07-15T18:27:35+00:00","dateModified":"2025-06-14T00:24:39+00:00","description":"Defer the creation of the indexes if you need to create multiple indexes at one time. When you are ready you tell the cluster to build those indexes.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/deferring-of-index-creation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Deferring Index Creation"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/2887e38425754897cea2d896bf082e6d","name":"Kirk Kirkconnell, Senior Solutions Engineer, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/60a4ddb304fde12e65369919433b8dc7","url":"https:\/\/secure.gravatar.com\/avatar\/f704905856dcd1767d50024da51e2fa159eea665c85aff3224bc8763551d4e35?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f704905856dcd1767d50024da51e2fa159eea665c85aff3224bc8763551d4e35?s=96&d=mm&r=g","caption":"Kirk Kirkconnell, Senior Solutions Engineer, Couchbase"},"description":"Kirk Kirkconnell was a Senior Solutions Engineer at Couchbase working with customers in multiple capacities to assist them in architecting, deploying, and managing Couchbase. His expertise is in operations, hosting, and support of large-scale application and database infrastructures.","url":"https:\/\/www.couchbase.com\/blog\/author\/kirk-kirkconnell\/"}]}},"authors":[{"term_id":9008,"user_id":23,"is_guest":0,"slug":"kirk-kirkconnell","display_name":"Kirk Kirkconnell, Senior Solutions Engineer, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/f704905856dcd1767d50024da51e2fa159eea665c85aff3224bc8763551d4e35?s=96&d=mm&r=g","author_category":"","last_name":"Kirkconnell","first_name":"Kirk","job_title":"","user_url":"","description":"Kirk Kirkconnell was a Senior Solutions Engineer at Couchbase working with customers in multiple capacities to assist them in architecting, deploying, and managing Couchbase. His expertise is in operations, hosting, and support of large-scale application and database infrastructures."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/2338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=2338"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/2338\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=2338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=2338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=2338"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=2338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}