Try our conversational search powered by Generative AI!

Clear index programatically



I have a custom indexing scheduled job. The files that needs to be indexed varies based on few dynamic criterias. Hence I want my schedule job to clear all indexed data and start indexing afresh. So is there a way that I can clear the index programatically?

Feb 22, 2013 13:45


You could do something like:

SearchClient.Instance.Delete<object>(x => x.GetType().Name.Exists() | !x.GetType().Name.Exists());

The expression passed to the Delete method doesn't make much sense in other contexts, we just use it to supply a filter that wil match anything.

However, instead of deleting everything and reindexing all your data, I'd recommend doing the following:

  1. Create an extension method for the relevant types, or for object. Name Timestamp and have it return DateTime.Now.
  2. Configure SearchClient's conventions to include the extension method for all relevant types.
  3. When you start your scheduled job create a variable, like var indexingStart = DateTime.Now
  4. Index all objects that should be indexed.
  5. Delete all objects of relevant types whose Timestamp is before indexingStart, ie SearchClient.Instance.Delete<SomeType>(x => x.Timestamp().Before(indexingStart))
Feb 22, 2013 18:11

Hi Joel, thanks for the information.

Feb 26, 2013 14:44

Hi Joel,

THanks for this great suggestion. i am extremly new to episerver. can you update the broken link for "Include"

"Configure SearchClient's conventions to include the extension method for all relevant types."

Nov 09, 2016 8:53
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.