I am experiencing connection issues with my Elasticsearch client running locally. Specifically, when I try to connect using localhost in the RestClient.builder, I receive a java.net.connectException: connection refused error, and when I try to use my IP address, I get a timeout error. I have developed two different versions of my test app, one using a low-level REST client and the other using the Java API, both of which were developed using Kotlin for and android application. Despite this, I still receive the same errors. I have included the code for both versions below. Can anyone suggest a solution or help me diagnose the issue?
Here are a code snipet to better understand my situation. Code used in the low level rest client:
private fun sendFileStandard() {
val restClient = RestClient.builder(
HttpHost("192.167.208.131", 9200, "http"),
HttpHost("localhost", 9200, "http")
).build()
val request = Request(
"GET",
"/"
)
var risultato = "defualt value"
doAsync {
val cancellable: Cancellable = restClient.performRequestAsync(request,
object : ResponseListener {
override fun onSuccess(response: Response) {
dii("onsuccess", response)
risultato = "success" +response.toString()
}
override fun onFailure(exception: Exception) {
dii("onfailure", exception)
risultato = "exception" + exception.toString()
}
})
}
dii("risultato", risultato)
Thread.sleep(9000)
restClient.close();
}
the java api ones:
val restClient = RestClient.builder(
HttpHost("localhost", 9200)
).build()
val transport: ElasticsearchTransport = RestClientTransport(
restClient, JacksonJsonpMapper()
)
val client = ElasticsearchClient(transport)
val input: Reader = StringReader(
"{'@timestamp': '2022-04-08T13:55:32Z', 'level': 'warn', 'message': 'Some log message'}"
.replace('\'', '"')
)
val request = IndexRequest.of { i: IndexRequest.Builder<JsonData?> ->
i
.index("logs")
.withJson(input)
}
doAsync {
val response: IndexResponse = client.index(request)
}