# Search query Timeout using RestHighLevelClient ES 7.6v

**URL:** <https://discuss.elastic.co/t/search-query-timeout-using-resthighlevelclient-es-7-6v/239784>\
**Category:** Elasticsearch\
**Created:** [July 3, 2020, 11:04am UTC](https://discuss.elastic.co/t/search-query-timeout-using-resthighlevelclient-es-7-6v/239784 "2020-07-03T11:04:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sriram8894](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@Sriram8894](https://discuss.elastic.co/u/Sriram8894)\
**Post date:** [July 3, 2020, 11:04am UTC](https://discuss.elastic.co/t/search-query-timeout-using-resthighlevelclient-es-7-6v/239784/1 "2020-07-03T11:04:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [July 3, 2020, 11:15am UTC](https://discuss.elastic.co/t/search-query-timeout-using-resthighlevelclient-es-7-6v/239784/2 "2020-07-03T11:15:53Z")

</div>

Hello Sriram,

I guess you are looking for the [SearchSourceBuilder](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-search.html#_using_the_searchsourcebuilder).

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

---

<div class="post-metadata">

**Author:** ![Sriram8894](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@Sriram8894](https://discuss.elastic.co/u/Sriram8894)\
**Post date:** [July 3, 2020, 11:42am UTC](https://discuss.elastic.co/t/search-query-timeout-using-resthighlevelclient-es-7-6v/239784/3 "2020-07-03T11:42:14Z")

</div>

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.]`

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [July 3, 2020, 11:49am UTC](https://discuss.elastic.co/t/search-query-timeout-using-resthighlevelclient-es-7-6v/239784/4 "2020-07-03T11:49:04Z")

</div>

> [@Sriram8894](#):
>
> But this is returning a flag "timeout": true/false rather than throwing an exception.

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.

---

<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:** [July 31, 2020, 12:00pm UTC](https://discuss.elastic.co/t/search-query-timeout-using-resthighlevelclient-es-7-6v/239784/5 "2020-07-31T12:00:32Z")

</div>

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