# Search timeout not working

**URL:** <https://discuss.elastic.co/t/search-timeout-not-working/303044>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [April 22, 2022, 2:36pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044 "2022-04-22T14:36:15Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrFantastic2022](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MrFantastic2022](https://discuss.elastic.co/u/MrFantastic2022)\
**Post date:** [April 22, 2022, 2:36pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/1 "2022-04-22T14:36:15Z")

</div>

Hello.

I have a small index (~10000 documents) and have specified 1000 as the argument to the _size()_ method of **SearchSourceBuilder**. When I inspect the _totalHits_ value for some of my searches, that number is in excess of the size limit I've set so I increased it to a larger number, say, 5000. However, when I do that, the searches fail with a SocketTimeout exception. So, I set a value of 120 seconds as the timeout, which should be more than enough to complete the query, yet it still fails with a SocketTimeout. What am I missing here? Is there some setting on the Elasticsearch server which I need to modify in order to keep the handshake alive? I am working with the Elasticsearch service hosted in AWS. Also, my code is in Java.

Thanks in advance to all who respond.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 22, 2022, 2:53pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/2 "2022-04-22T14:53:59Z")

</div>

Hi!  
Show how you can set timeout, please.

---

<div class="post-metadata">

**Author:** ![MrFantastic2022](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MrFantastic2022](https://discuss.elastic.co/u/MrFantastic2022)\
**Post date:** [April 22, 2022, 3:31pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/3 "2022-04-22T15:31:04Z")

</div>

I followed the example given on this page [Search](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.8/java-rest-high-search.html)

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

```

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 22, 2022, 3:52pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/4 "2022-04-22T15:52:03Z")

</div>

Try this in your client:

```auto
        var builder = RestClient.builder(HttpHost.create( **ecsHost** ))
                .setRequestConfigCallback(
                        requestConfigBuilder -> requestConfigBuilder
                                .setConnectTimeout( **connectTimeout** )
                                .setSocketTimeout( **socketTimeout** )
                )
                .setHttpClientConfigCallback(httpClientBuilder ->
                    httpClientBuilder.setDefaultIOReactorConfig(
                        IOReactorConfig.custom()
                            .setSoTimeout( **socketTimeout** )
                            .setConnectTimeout( **connectTimeout** )
                            .setIoThreadCount(getIoThreadCount())
                            .build())
                );
        return new RestHighLevelClient(builder);

```

---

<div class="post-metadata">

**Author:** ![MrFantastic2022](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MrFantastic2022](https://discuss.elastic.co/u/MrFantastic2022)\
**Post date:** [April 22, 2022, 5:05pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/5 "2022-04-22T17:05:52Z")

</div>

Okay, I am writing in Java, but this code gives me a hint! I will try setting the timeout on both the client call and the search request. I may not get to it today, since I have another fire to put out. But I will report back next week. Thanks for taking the time to code this up!

---

<div class="post-metadata">

**Author:** ![MrFantastic2022](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MrFantastic2022](https://discuss.elastic.co/u/MrFantastic2022)\
**Post date:** [April 22, 2022, 6:15pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/6 "2022-04-22T18:15:40Z")

</div>

Okay, I took a quick look at the 6.8 docs (which is the version I'm using) and there doesn't appear to be any way to set the socket timeout, just maxRetries. There is some code which shows how to set the callback but I don't think that is what I want. Looks like I'm stuck at this point with being able to configure the client with a different socket timeout value. Any other thoughts would be appreciated.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 23, 2022, 3:20pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/7 "2022-04-23T15:20:17Z")

</div>

Changing the timeout on the client doesn't work?

---

<div class="post-metadata">

**Author:** ![MrFantastic2022](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MrFantastic2022](https://discuss.elastic.co/u/MrFantastic2022)\
**Post date:** [April 25, 2022, 2:22pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/8 "2022-04-25T14:22:36Z")

</div>

I can't change the timeout for the client, there is no method to do that, at least none that I could see. I can set the timeout in the SearchSourceBuilder but that doesn't seem to make a difference.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 25, 2022, 2:50pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/9 "2022-04-25T14:50:19Z")

</div>

Curious, this code I sent is java (Java High Level REST Client).

---

<div class="post-metadata">

**Author:** ![MrFantastic2022](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MrFantastic2022](https://discuss.elastic.co/u/MrFantastic2022)\
**Post date:** [April 25, 2022, 2:55pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/10 "2022-04-25T14:55:54Z")

</div>

which version? I have never declared anything **var** in Java

---

<div class="post-metadata">

**Author:** ![MrFantastic2022](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MrFantastic2022](https://discuss.elastic.co/u/MrFantastic2022)\
**Post date:** [April 25, 2022, 2:59pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/12 "2022-04-25T14:59:43Z")

</div>

okay, that makes sense. We actually have lombok in our project but not using it in this way. I will try your code and see if that works. Should I also set the timeout on the call to the client? As I described before?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 25, 2022, 3:01pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/13 "2022-04-25T15:01:19Z")

</div>

Sorry, is Java 11.

> [@MrFantastic2022](#):
>
> hould I also set the timeout on the call to the client? As I described before?

No.

---

<div class="post-metadata">

**Author:** ![MrFantastic2022](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MrFantastic2022](https://discuss.elastic.co/u/MrFantastic2022)\
**Post date:** [April 25, 2022, 3:24pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/14 "2022-04-25T15:24:14Z")

</div>

oh, we are on 8

---

<div class="post-metadata">

**Author:** ![MrFantastic2022](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MrFantastic2022](https://discuss.elastic.co/u/MrFantastic2022)\
**Post date:** [April 25, 2022, 3:24pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/15 "2022-04-25T15:24:55Z")

</div>

okay, I'll try that later today. Trying to get a range query to work right now 😃

---

<div class="post-metadata">

**Author:** ![MrFantastic2022](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MrFantastic2022](https://discuss.elastic.co/u/MrFantastic2022)\
**Post date:** [April 29, 2022, 2:28pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/16 "2022-04-29T14:28:19Z")

</div>

Well, it turns out that my team lead is no longer "hot" on the issue of fixing the timeout. He is satisfied if the result set is capped at 1000 even though there may be significantly more than that returned as hits. I'll keep this in my back pocket should things change but I appreciate the time and effort you put into helping me out.

---

<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:** [May 27, 2022, 2:29pm UTC](https://discuss.elastic.co/t/search-timeout-not-working/303044/17 "2022-05-27T14:29:04Z")

</div>

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