Search code examples
c#.netelasticsearchnest

NEST Wait for the server to finish indexing after bulk insert


I'm indexing a number of documents using Nest 7.0:

await client.IndexManyAsync(docs, myAlias, cancellationToken);

For my tests I need to make sure I can query the indexed documents with 100% guarantee because wait for a fixed amount of time after IndexManyAsync() doesn't always work. I think I need an equivalent of ?refresh=wait_for parameter but cannot find any examples in the fluent API and IndexManyAsync() doesn't have any suitable overloads :( How can I do that?


Solution

  • Calling index refresh after IndexManyAsync will do the job

    await elasticClient.Indices.RefreshAsync("index_name");