{"id":62762,"date":"2016-10-21T15:59:45","date_gmt":"2016-10-21T15:59:45","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=62762"},"modified":"2024-03-28T12:01:16","modified_gmt":"2024-03-28T12:01:16","slug":"reindexing-programmatically-magento-2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/","title":{"rendered":"Reindexing programmatically in magento 2"},"content":{"rendered":"\n<p>Reindexing programmatically in magento 2.<\/p>\n\n\n\n<p>Reindex is\u00a0<strong>the process of updating the transformed data as the data changes<\/strong>. E.g.: when updating a product price the data should be reindexed to be correctly displayed on the frontend.<\/p>\n\n\n\n<p>In this article we will learn how to <a href=\"https:\/\/webkul.com\/blog\/reindexing-for-one-product-in-magento-2\/\">reindexing<\/a> through code\u00a0in magento 2.<\/p>\n\n\n\n<p>You can write the below code in any class&nbsp;according to your need :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\/**\n * @var \\Magento\\Indexer\\Model\\IndexerFactory\n *\/\nprotected $_indexerFactory;\n\/**\n * @var \\Magento\\Indexer\\Model\\Indexer\\CollectionFactory\n *\/\nprotected $_indexerCollectionFactory;\n\npublic function __construct(\n    \\Magento\\Indexer\\Model\\IndexerFactory $indexerFactory,\n    \\Magento\\Indexer\\Model\\Indexer\\CollectionFactory $indexerCollectionFactory\n){\n   $this-&gt;_indexerFactory = $indexerFactory;\n   $this-&gt;_indexerCollectionFactory = $indexerCollectionFactory;\n}\n\n\/\/ you can call this function to do reindexing\npublic function reIndexing(){\n   $indexerCollection = $this-&gt;_indexerCollectionFactory-&gt;create();\n   $ids = $indexerCollection-&gt;getAllIds();\n   foreach ($ids as $id) {\n   $idx = $this-&gt;_indexerFactory-&gt;create()-&gt;load($id);\n   $idx-&gt;reindexAll($id); \/\/ this reindexes all\n   \/\/$idx-&gt;reindexRow($id); \/\/ or you can use reindexRow according to your need\n}<\/pre>\n\n\n\n<p>That&#8217;s all in this article, hope it will help you to call custom block and links inside footer. Try the above code and&nbsp;if you have any issue just comment below. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Reindexing programmatically in magento 2. Reindex is\u00a0the process of updating the transformed data as the data changes. E.g.: when updating a product price the data should be reindexed to be correctly displayed on the frontend. In this article we will learn how to reindexing through code\u00a0in magento 2. You can write the below code in <a href=\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":103,"featured_media":61510,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[3848],"class_list":["post-62762","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento2","tag-reindexing-programmatically-in-magento-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Reindexing programmatically in magento 2 - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Reindexing programmatically in magento 2 - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Reindexing programmatically in magento 2. Reindex is\u00a0the process of updating the transformed data as the data changes. E.g.: when updating a product price the data should be reindexed to be correctly displayed on the frontend. In this article we will learn how to reindexing through code\u00a0in magento 2. You can write the below code in [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-10-21T15:59:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-28T12:01:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Pranjali Goel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pranjali Goel\" \/>\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\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/\"},\"author\":{\"name\":\"Pranjali Goel\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/c1964884ceb33a5ffdf322ee5424f692\"},\"headline\":\"Reindexing programmatically in magento 2\",\"datePublished\":\"2016-10-21T15:59:45+00:00\",\"dateModified\":\"2024-03-28T12:01:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/\"},\"wordCount\":99,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png\",\"keywords\":[\"reindexing programmatically in magento 2\"],\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/\",\"url\":\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/\",\"name\":\"Reindexing programmatically in magento 2 - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png\",\"datePublished\":\"2016-10-21T15:59:45+00:00\",\"dateModified\":\"2024-03-28T12:01:16+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png\",\"width\":825,\"height\":260,\"caption\":\"Ui Component Form\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Reindexing programmatically in magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/c1964884ceb33a5ffdf322ee5424f692\",\"name\":\"Pranjali Goel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e670273251719f83735534af186231dd99fbe378466fef356d4e55de5b46244f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e670273251719f83735534af186231dd99fbe378466fef356d4e55de5b46244f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Pranjali Goel\"},\"description\":\"Believes in simple lifestyle and follow a simple logic to make herself better than yesterday.\",\"url\":\"https:\/\/webkul.com\/blog\/author\/pranjali968\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Reindexing programmatically in magento 2 - Webkul Blog","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:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"Reindexing programmatically in magento 2 - Webkul Blog","og_description":"Reindexing programmatically in magento 2. Reindex is\u00a0the process of updating the transformed data as the data changes. E.g.: when updating a product price the data should be reindexed to be correctly displayed on the frontend. In this article we will learn how to reindexing through code\u00a0in magento 2. You can write the below code in [...]","og_url":"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-10-21T15:59:45+00:00","article_modified_time":"2024-03-28T12:01:16+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","type":"image\/png"}],"author":"Pranjali Goel","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Pranjali Goel","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/"},"author":{"name":"Pranjali Goel","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/c1964884ceb33a5ffdf322ee5424f692"},"headline":"Reindexing programmatically in magento 2","datePublished":"2016-10-21T15:59:45+00:00","dateModified":"2024-03-28T12:01:16+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/"},"wordCount":99,"commentCount":2,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","keywords":["reindexing programmatically in magento 2"],"articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/","url":"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/","name":"Reindexing programmatically in magento 2 - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","datePublished":"2016-10-21T15:59:45+00:00","dateModified":"2024-03-28T12:01:16+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/Magneto-Code-Snippet-1.png","width":825,"height":260,"caption":"Ui Component Form"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/reindexing-programmatically-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Reindexing programmatically in magento 2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/c1964884ceb33a5ffdf322ee5424f692","name":"Pranjali Goel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e670273251719f83735534af186231dd99fbe378466fef356d4e55de5b46244f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e670273251719f83735534af186231dd99fbe378466fef356d4e55de5b46244f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Pranjali Goel"},"description":"Believes in simple lifestyle and follow a simple logic to make herself better than yesterday.","url":"https:\/\/webkul.com\/blog\/author\/pranjali968\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/62762","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/103"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=62762"}],"version-history":[{"count":4,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/62762\/revisions"}],"predecessor-version":[{"id":430176,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/62762\/revisions\/430176"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/61510"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=62762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=62762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=62762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}