SearchRequest source timeout not working for Java HighLevelRESTClient

Hello,

I am trying to parse a timeout parameter to searchRequest.source().timeout() in Kotlin and run HighLevelRestClient.search(searchRequest). The timeout interval in my case is set to be 1 ms for testing if the timeout flag works. However, after the execution, I have found searchResponse.took to be greater than 1 ms while searchResponse.isTimedOut is always false, which indicates that the timeout parameter does not work in the tasks.

The timeout parameter is set as the following:

val realTimeoutInterval = timeoutInterval ?: DEFAULT_QUERY_TIMEOUT_MS
checkNotInTransaction()
searchRequest.source().timeout(TimeValue(realTimeoutInterval))
val response = highLevelRestClient.search(searchRequest, options)
println(searchRequest.source().timeout())
println(response.isTimedOut)
println(response.took)
return response

Where DEFAULT_QUERY_TIMEOUT_MS is Long(1), which is 1ms. options is empty.

The debug prints show:

1ms
false
4ms

which shows that the timeout is set to be 1ms, but the searching task is not timed out even it has executed for 4ms to complete.

Any advise on how to solve this issue? Thanks!

1 Like