I am using olivere/elastic to work with elasticsearch in Go. Here is my code:
// (1) delete document
_, err := e.client.Delete().Index(index).Type("entity").
Id(id).Do(e.ctx)
if err != nil {
fmt.Println(err.Error())
}
// (2) get all documents
result, err := e.client.Search().Index(index).From(1).Size(100).Do(e.ctx)
if err != nil {
log.Println(err)
}
fmt.Println(result.TotalHits())
// (3) wait
time.Sleep(3 * time.Second)
// (4) get all documents
result, err = e.client.Search().Index(index).From(1).Size(100).Do(e.ctx)
if err != nil {
log.Println(err)
}
fmt.Println(result.TotalHits())
Here I am:
- delete document
- get all documents from collection
- wait 3 seconds
- get the same documents from collection
Now on the step (2) I get one more document than step (4). Looks like the document is deleted in Elastic with some delay and I am searching the way to delete the document synchronously.