Hi,
I am trying to set up an automation test where I add a record to our DB and then force a run of the indexer via the Search SDK. The code I have to run the indexer and wait for a success status is below however after this code runs a call to the search index
returns 0 items when performing a search via the API. If I put in a few seconds sleep between running the indexer and performing the actual search call then it works as expected but this doesn't seem ideal.
Does anyone know if this is a known issue or should I be using different code?
Appreciate any help.
Cheers,
Mark.
public static void RunIndexer()
{
SearchServiceClient searchService = new SearchServiceClient(_searchServiceName, new SearchCredentials(_searchApiKey));
IIndexersOperations searchServiceIndexers = searchService.Indexers;
Task indexOperation = searchServiceIndexers.RunAsync("digitalregister-person");
indexOperation.Wait();
bool rebuiltIndex = false;
while(!rebuiltIndex)
{
Task<IndexerExecutionInfo> status = searchServiceIndexers.GetStatusAsync("digitalregister-person");
status.Wait();
if (status.Result.LastResult.Status.Equals(IndexerExecutionStatus.Success) && status.Result.LastResult.ItemCount > 0)
{
rebuiltIndex = true;
}
}
}