Elasticsearch return search response very quickly with timeout:true

Elasticsearch version

bin/elasticsearch --version
7.6.0

Problem
I use go-elasticsearch client query from elasticsearch.


	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

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

but the ES return empty result with timeout:true

{
  "_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

Can anyone help me :star_struck:

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

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

1 Like

Thank you so much for your reply :heart:

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

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

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.

1 Like

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.

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

1 Like

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!

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