Add first pass at handling error codes from ElasticSearch

Also adds some debug output that can be removed / changed to logging
debug messages.