mardi 29 août 2017

Check if Elasticsearch has finished indexing

Is there a way to check if Elasticsearch has finished processing my request?
I want to perform integration tests for my application checking if a record can be found after insertion. For example if I make a following request:

POST /_all/_bulk
{  
   "update":{  
      "_id":419,
      "_index":"popc",
      "_type":"offers"
   }
}
{  
   "doc":{  
      "id":"419",
      "author":"foo bar",
      "number":"642-00419"
   },
   "doc_as_upsert":true
}

And I check immediately, the test fails, because it takes some time for Elasticsearch to complete my request.
If I sleep for 1 second before the assertion it works most of the time, but not always.
I could extend the sleep time to eg. 3 seconds, but it makes the tests very slow, hence my question.

I have tried using cat pending tasks and pending cluster tasks endpoints, but the responses are always empty.

If any of this is relevant, I'm using Elasticsearch 5.4, Laravel Scout 3.0.5 and tamayo/laravel-scout-elastic 3.0.3

Aucun commentaire:

Enregistrer un commentaire