# How can i rebuild all search indices through api

**URL:** <https://forum.litium.com/t/how-can-i-rebuild-all-search-indices-through-api/20>\
**Category:** Questions\
**Tags:** search\
**Created:** [April 17, 2018, 1:11pm UTC](https://forum.litium.com/t/how-can-i-rebuild-all-search-indices-through-api/20 "2018-04-17T13:11:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marten](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/marten/32/11_2.png) [@marten](https://forum.litium.com/u/marten)\
**Post date:** [April 17, 2018, 1:11pm UTC](https://forum.litium.com/t/how-can-i-rebuild-all-search-indices-through-api/20/1 "2018-04-17T13:11:53Z")

</div>

I would like to have the functionality found in Litium backoffice to rebuild and/or update search indexes for all or specific areas through API, is there an easy way to do this?

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [April 18, 2018, 7:32am UTC](https://forum.litium.com/t/how-can-i-rebuild-all-search-indices-through-api/20/2 "2018-04-18T07:32:23Z")

</div>

You can trigger the search index rebuild with the following code.

```auto
ModuleCMS.Instance.PageIndexingService.QueueIndexRebuild(Solution.Instance.SystemToken, true);
ModuleECommerce.Instance.OrderIndexingService.QueueIndexRebuild(Solution.Instance.SystemToken, true);
ModuleProductCatalog.Instance.CategoryIndexingService.QueueIndexRebuild(Solution.Instance.SystemToken, true);
ModuleProductCatalog.Instance.ProductIndexingService.QueueIndexRebuild(Solution.Instance.SystemToken, true);

```

---

<div class="post-metadata">

**Author:** ![abergman](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@abergman](https://forum.litium.com/u/abergman)\
**Post date:** [November 15, 2018, 9:11am UTC](https://forum.litium.com/t/how-can-i-rebuild-all-search-indices-through-api/20/3 "2018-11-15T09:11:34Z")

</div>

@patric.forsgard Is there a way to identify if search index needs a rebuild?  
If we for example reinstall a machine, then the search index will be empty. We want to automatically trigger a rebuild.

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [November 15, 2018, 9:59am UTC](https://forum.litium.com/t/how-can-i-rebuild-all-search-indices-through-api/20/4 "2018-11-15T09:59:09Z")

</div>

You can use the `Solution.Instance.SearchConfigurationService.GetIndexSize("indexname")` to see if you have any data in the search index. If the index size is small the index is probably missing or the index should only contains limited amount of items.
