Search query Timeout using RestHighLevelClient ES 7.6v

Hi,

We have recently migrated from ES 5.6v to 7.6v.

In ES 5.6 we have been using the below statement to throw an exception and return the default response if the query execution is taking more than the given TimeValue.

requestBuilder.execute().actionGet(timeValue)

While in ES 7.6 we didn't find any method to pass the TimeValue which could throw the Execution exception. We are using the below snippet in 7.6

client().search(requestBuilder, RequestOptions.DEFAULT)

Can you please help me on how to throw an exception in 7.6 if the query is taking more than expected time.

Regards,
Sriram

Hello Sriram,

I guess you are looking for the SearchSourceBuilder.

SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); 
sourceBuilder.query(QueryBuilders.termQuery("user", "kimchy")); 
sourceBuilder.from(0); 
sourceBuilder.size(5); 
sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS)); 

Best regards
Wolfram

1 Like

Thanks for your time. I have tried the logic

sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));

But this is returning a flag "timeout": true/false rather than throwing an exception. I would expecting an exception as below.

ElasticsearchTimeoutException[java.util.concurrent.TimeoutException: Timeout waiting for task.]

Can you not react on the timeout flag and throw an error youself?

Unfortunately, I haven't found a way to make the client throw an exception on timeout.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.