Elastic Delete Docs not waiting

Hi,

We have some integration tests where we also use Elastic.

Before each test, we delete all the documents using the NEST api. However, we sometimes see that the documents are not deleted yet - it appears as the delete call is non-blocking and returns before the actual delete is complete.

Below some code that reproduces the issue:

var searchResponse = ElasticClient.Search<AidaLegitimatiekaartReadModel>(q => q.Type<AidaLegitimatiekaartReadModel>()); foreach (var aidaLegitimatiekaartReadModel in searchResponse.Hits) { ElasticClient.Delete<AidaLegitimatiekaartReadModel>(aidaLegitimatiekaartReadModel.Id); } var after = ElasticClient.Search<AidaLegitimatiekaartReadModel>(q => q.Type<AidaLegitimatiekaartReadModel>()); after.Hits.Should().BeEmpty(); // => BOEM!

An error is thrown on the last line of the provided code block.

We're using ES v2.2.1 and Nest v2.0.2

Any idea what are we doing wrong?

Thanks in advance,
Ronald

You have to refresh the index before searching.

Wauw, thanks for the fast reply. Didn't think of that!