Hi I am using below libraries to connect to elasticsearch from java
implementation group: 'co.elastic.clients', name: 'elasticsearch-java', version: '8.11.4'
implementation group: 'org.elasticsearch.client', name: 'elasticsearch-rest-client', version: '8.11.4'
I need to provide timeout in my queries to cancel the running query after 50-60 ms as i need to provide response in given time frame.
I explored .timeout() in queries but it didn't work and in my knowledge it was working on per shard level and not on client level.
Then i found we can pass socket timeout to terminate the queries in low level client. This I am using as :
RestClient restClient = RestClient.builder(
new HttpHost(esHost, Integer.parseInt(esPort)))
requestConfigBuilder -> requestConfigBuilder
ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
return new ElasticsearchClient(transport);
But as I am testing this it is also not working. As you can see i have given 1 ms in both timeout values but request doesn't timeout and keeps on running for response. Please suggest me what I am missing as I have read tonnes of articles on this but anything doesn't seems to explain this.
@dadoonet Apologies for directly tagging you.
Thanks, the code is working properly using async client and is giving timeout as intended.
But Is there any way we can achieve this using synchronous client and why
RequestConfigCallback is not working as expected even when we set socketTimeout. It would be really helpful if you can explain on this?
It's strange that RequestConfigCallback is not working here, I have just tested it with those same libraries and configurations and it returns java.net.SocketTimeoutException: 1 milliseconds timeout on connection
If this is still an issue could you provide more information so that we can try to reproduce the problem?
Thanks for taking time to solve this. But for sync client I am using it in basic way as provided earlier. Not sure what is causing the issue here. Anyways async client works for me for now. Will get back to it if needed in future.