# Elasticsearch return search response very quickly with timeout:true

**URL:** <https://discuss.elastic.co/t/elasticsearch-return-search-response-very-quickly-with-timeout-true/322537>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [January 5, 2023, 11:18am UTC](https://discuss.elastic.co/t/elasticsearch-return-search-response-very-quickly-with-timeout-true/322537 "2023-01-05T11:18:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![chenchuangc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chenchuangc/32/40017_2.png) [@chenchuangc](https://discuss.elastic.co/u/chenchuangc)\
**Post date:** [January 5, 2023, 11:18am UTC](https://discuss.elastic.co/t/elasticsearch-return-search-response-very-quickly-with-timeout-true/322537/1 "2023-01-05T11:18:13Z")

</div>

**Elasticsearch version**

```auto
bin/elasticsearch --version
7.6.0

```

**Problem**  
I use [go-elasticsearch client](https://github.com/elastic/go-elasticsearch/v7) query from elasticsearch.

```auto

	resp, err := client.Search(
		client.Search.WithContext(d.ctx),
		client.Search.WithIndex(index),
		client.Search.WithBody(body),
		client.Search.WithTimeout(timeout), // 200ms
		client.Search.WithPreference(preference),
		client.Search.WithRouting(routing...),
	)

```

the query body is just ids query

```auto
{
  "query": {
    "ids": {
      "values": [
        "123"
      ]
    }
  },
  "size": 1
}

```

but the ES return empty result with timeout:true

```auto
{
  "_shards": {
    "failed": 0,
    "skipped": 0,
    "successful": 20,
    "total": 20
  },
  "hits": {
    "hits": [

    ],
    "max_score": null,
    "total": {
      "relation": "eq",
      "value": 0
    }
  },
  "timed_out": true,
  "took": 1
}

```

the took=1ms , and the caller time i record is also 1ms, this means the ES server give me the response in 1ms after i send the request to the server .  
But the timeout i set is 200ms .  
The probability of this happening is very low and cannot be reproduced

Sorry for bother you

---

<div class="post-metadata">

**Author:** ![chenchuangc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chenchuangc/32/40017_2.png) [@chenchuangc](https://discuss.elastic.co/u/chenchuangc)\
**Post date:** [January 6, 2023, 1:46am UTC](https://discuss.elastic.co/t/elasticsearch-return-search-response-very-quickly-with-timeout-true/322537/2 "2023-01-06T01:46:05Z")

</div>

Can anyone help me 🤩

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 6, 2023, 7:23am UTC](https://discuss.elastic.co/t/elasticsearch-return-search-response-very-quickly-with-timeout-true/322537/3 "2023-01-06T07:23:43Z")

</div>

I have no idea. But why are you setting such a timeout in the first place?

> [@chenchuangc](#):
>
> **Elasticsearch version**
> 
> ```auto
> bin/elasticsearch --version
> 7.6.0
> 
> ```

I'd definitely upgrade to the latest 7.17.8 version (or 8.5.3). This one is a way too old.

---

<div class="post-metadata">

**Author:** ![chenchuangc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chenchuangc/32/40017_2.png) [@chenchuangc](https://discuss.elastic.co/u/chenchuangc)\
**Post date:** [January 6, 2023, 10:48am UTC](https://discuss.elastic.co/t/elasticsearch-return-search-response-very-quickly-with-timeout-true/322537/4 "2023-01-06T10:48:39Z")

</div>

Thank you so much for your reply ❤

> But why are you setting such a timeout in the first place?

Because if the ES server return very slow, i will discard the results from ES

> I'd definitely upgrade to the latest 7.17.8 version (or 8.5.3). This one is a way too old.

ES cluster are uniformly maintained by a dedicated team, and it is difficult to upgrade directly

---

<div class="post-metadata">

**Author:** ![chenchuangc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chenchuangc/32/40017_2.png) [@chenchuangc](https://discuss.elastic.co/u/chenchuangc)\
**Post date:** [January 6, 2023, 10:49am UTC](https://discuss.elastic.co/t/elasticsearch-return-search-response-very-quickly-with-timeout-true/322537/5 "2023-01-06T10:49:10Z")

</div>

I have currently escaped this issue by retry once if the response is empty and timeout=true

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 6, 2023, 7:41pm UTC](https://discuss.elastic.co/t/elasticsearch-return-search-response-very-quickly-with-timeout-true/322537/6 "2023-01-06T19:41:34Z")

</div>

In which case you are basically doubling the timeout value.  
Question is: why not doubling it?

I mean that setting a timeout is not going to speed up your queries.

---

<div class="post-metadata">

**Author:** ![chenchuangc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chenchuangc/32/40017_2.png) [@chenchuangc](https://discuss.elastic.co/u/chenchuangc)\
**Post date:** [January 9, 2023, 1:41am UTC](https://discuss.elastic.co/t/elasticsearch-return-search-response-very-quickly-with-timeout-true/322537/7 "2023-01-09T01:41:52Z")

</div>

Oh, I get what you said.  
I want to say that the problem is not because of the timeout value is not enough. I set 200ms, but ES server just use 1ms and give me an empty response.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 9, 2023, 2:45pm UTC](https://discuss.elastic.co/t/elasticsearch-return-search-response-very-quickly-with-timeout-true/322537/8 "2023-01-09T14:45:44Z")

</div>

Does this happen when you don't set any timeout?

---

<div class="post-metadata">

**Author:** ![chenchuangc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chenchuangc/32/40017_2.png) [@chenchuangc](https://discuss.elastic.co/u/chenchuangc)\
**Post date:** [January 10, 2023, 7:01am UTC](https://discuss.elastic.co/t/elasticsearch-return-search-response-very-quickly-with-timeout-true/322537/9 "2023-01-10T07:01:56Z")

</div>

Thank you for your advice, you mean that this `timeout` param may have some bad effect on this problem?

I will try this way next time. Thank you!

---

<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:** [February 7, 2023, 7:02am UTC](https://discuss.elastic.co/t/elasticsearch-return-search-response-very-quickly-with-timeout-true/322537/10 "2023-02-07T07:02:28Z")

</div>

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