I'm using a shell script to fire off a curl request that deletes all documents of a certain type in my Elasticsearch cluster. If successful, Logstash starts and attempts to reindex the deleted type's documents.

printf "\n%s\n" "Sending delete request..."

RESPONSE=$(curl --max-time 600 -XPOST 
"https://mycluster.com:9243/locations/ca/_delete_by_query?conflicts=proceed" -H 
'Content-Type: application/json' -d' { "query": { "match_all": {} } }' 
--user user:password)

if [[ $RESPONSE == *"deleted"* ]]; then
  echo $RESPONSE
  printf "\n%s\n" "Delete successful, starting Logstash..."
  cd /home/denroot/EP-logstash && bin/logstash -f /home/denroot/EP-
  echo $RESPONSE
  printf "\n%s\n" "Delete failed, shutting down..."

The issue I've encountered is this particular type has over 5 million documents. The Elasticsearch delete task cannot finish before 5 minutes have elapsed, and my curl request exits with an exit code of 0. I can't seem to prevent this from happening with --max-time. Normally, when the delete task finishes in Elasticsearch, it sends back a JSON response body which I need for my control-flow logic to work properly. Any help preventing this 5 minute exit issue would be greatly appreciated as I can't seem to find a precedent.

  • 1
    Can you rework the logic to delete only a few (tens of) thousand documents at a time, and work at it in smaller bites? – DopeGhoti Nov 9 '17 at 16:48
  • Exit code 0. So curl thinks the request is complete. What HTTP status do you get back? – roaima Nov 9 '17 at 22:19
  • When curl exits, the value of $RESPONSE is empty. – taylorhessel Nov 10 '17 at 16:43
  • curl would return exit code 0 even on a 4xx HTTP error. Try runing your curl command with -I to view the status code returned by the server and other HTTP headers. – cherdt Nov 11 '17 at 0:35

Your script should exit after 10 minutes as it is.

Try increasing (or removing) max-time for lifting that limit

If the 5 minutes timeout is imposed on server side, you could try running the curl command multiple times until you receive the expected output/exit code.

  • You may be onto something that the timeout is imposed server-side. Unfortunately, there doesn't seem to be any documentation in the Elasticsearch delete-by-query API about response timeouts. Thank you anyway! – taylorhessel Nov 9 '17 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.