Hi, I'm using Elasticsearch (ES) and Docker-Compose. Sometimes the ES Docker Container hasn't yet started, when my main container (the one that runs my code and connects to ES) starts. Then
InetAddress.getByName("search") below throws a
java.net.UnknownHostException (because Docker's DNS server hasn't yet assigned an IP address to the
search container, as far as I've understood).
I would like ES to repeatedly try to [resolve the hostname of the ES Docker container], and, eventually, when the name resolves, connect to the host.
I didn't find any built-in functionality for this (in ES 5 alpha 3). I'm getting the impression that ES wants an IP number always, and doesn't work with hostnames at all: all examples I found use
InetAddress.getByName and passes the result to ES.
- Is there any way to have the ES client resolve the host, and politely wait until the hostname resolves to an IP number?
Also, if the ES server suddenly disappears, then, when the client attempts to reconnect, if now again the DNS server cannot resolve the address, the client ought to wait until the hostname resolves, and then continue with attempting to reconnect.
- Do any other people have this same situation? What did you do?
I suppose I can write my own appserver logic that won't create the ES client before the ES server hostname resolves. But I'd rather not :- )
This is my code, and
getByName throws the
val elasticSearchClient = es.client.transport.TransportClient.builder().build() .addTransportAddress( new es.common.transport.InetSocketTransportAddress( java.net.InetAddress.getByName("search"), 9300))
(I hope all this is understandable :- ))