# SearchRequest source timeout not working for Java HighLevelRESTClient

**URL:** <https://discuss.elastic.co/t/searchrequest-source-timeout-not-working-for-java-highlevelrestclient/304507>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [May 11, 2022, 9:39pm UTC](https://discuss.elastic.co/t/searchrequest-source-timeout-not-working-for-java-highlevelrestclient/304507 "2022-05-11T21:39:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Constantine\_Cheng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/constantine_cheng/32/99342_2.png) [@Constantine\_Cheng](https://discuss.elastic.co/u/Constantine_Cheng)\
**Post date:** [May 11, 2022, 9:39pm UTC](https://discuss.elastic.co/t/searchrequest-source-timeout-not-working-for-java-highlevelrestclient/304507/1 "2022-05-11T21:39:01Z")

</div>

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:

```auto
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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 8, 2022, 9:39pm UTC](https://discuss.elastic.co/t/searchrequest-source-timeout-not-working-for-java-highlevelrestclient/304507/2 "2022-06-08T21:39:22Z")

</div>

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