# CURL returns immediately whereas RestClient timesout

**URL:** <https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802>\
**Category:** Elasticsearch\
**Created:** [December 21, 2018, 7:53am UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802 "2018-12-21T07:53:58Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![madhan3396](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/madhan3396/32/57318_2.png) [@madhan3396](https://discuss.elastic.co/u/madhan3396)\
**Post date:** [December 21, 2018, 7:53am UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/1 "2018-12-21T07:53:59Z")

</div>

Hi,

I'm using elasticsearch version 6.4.

An index pri.store.size is 25GB and it contains 47 Million documents.  
My query includes a termsquery and cardinality.

When i execute the query using CURL i got the response in 3-4 seconds.

But when the same query is executed by RestClient java api, i got the exception `java.io.IOException: listener timeout after waiting for [30000] ms`.

Then i increased my setMaxRetryTimeoutMillis to 60000. Still timeout happened. Then further to 90 seconds, 2 minute, 10 min, 20 min. I failed every time.

What i'm missing?

Simple queries are executed successfully via RestClient. But a query with termsquery and cardinality timesout everytime (only RestClient fails but CURL returns response)

Help me to achieve via RestClient.

---

<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:** [December 21, 2018, 9:32am UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/2 "2018-12-21T09:32:20Z")

</div>

I'd say that you are not exactly running the same thing.

Could you share both things:

- The curl query you ran
- The Java code you used

---

<div class="post-metadata">

**Author:** ![madhan3396](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/madhan3396/32/57318_2.png) [@madhan3396](https://discuss.elastic.co/u/madhan3396)\
**Post date:** [December 21, 2018, 11:00am UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/3 "2018-12-21T11:00:24Z")

</div>

This is how i queried.  
Using CURL:

```
curl -XGET "localhost:9200/my_index_name/_search?pretty" -H 'Content-Type: application/json' -d'{
	"query":{
		"bool":{
			"must":[
				{"terms":{"Operation":["Operation", "SIGN_IN", "SIGN_OUT", "VALIDATE"]}}
			]
		}
	},
	"aggs":{
		"TokenCards":{
			"cardinality":{
				"field":"Token"
			}
		}
	}
}'

```

USING JAVA:

```
		BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
		TermsQueryBuilder termsQueryBuilder = new TermsQueryBuilder("Operation", "SIGN_IN", "SIGN_OUT", "VALIDATE");
		SearchRequest request = new SearchRequest("my_index_name");
		SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
		sourceBuilder.query(boolQueryBuilder.must(termsQueryBuilder));
		sourceBuilder.aggregation(AggregationBuilders.cardinality("TokenCards").field("Token"));
		request.source(sourceBuilder);
		SearchResponse searchResponse = client.search(request, RequestOptions.DEFAULT);
```

---

<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:** [December 21, 2018, 11:18am UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/4 "2018-12-21T11:18:42Z")

</div>

Please format your code according to the rules of this forum. I edited your post to make it readable but next time please do it.

Can you share the full content of:

```auto
searchResponse.toString();

```

And the full content of your curl call:

```auto
curl -XGET "localhost:9200/my_index_name/_search?pretty" -H 'Content-Type: application/json' -d'{
...

```

---

<div class="post-metadata">

**Author:** ![madhan3396](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/madhan3396/32/57318_2.png) [@madhan3396](https://discuss.elastic.co/u/madhan3396)\
**Post date:** [December 21, 2018, 12:44pm UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/5 "2018-12-21T12:44:47Z")

</div>

Full response of my curl call:

```auto
    {
      "took" : 10890,
      "timed_out" : false,
      "_shards" : {
        "total" : 21,
        "successful" : 21,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : 1250832,
        "max_score" : 0.0,
        "hits" : []
      },
      "aggregations" : {
        "TokenCards" : {
          "value" : 1262042
        }
      }
    }

```

**searchResponse** is null because of listener timeout exception.

---

<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:** [December 21, 2018, 1:15pm UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/6 "2018-12-21T13:15:50Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Here I think you edited the response right?  
`hits` can not be empty.

---

<div class="post-metadata">

**Author:** ![madhan3396](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/madhan3396/32/57318_2.png) [@madhan3396](https://discuss.elastic.co/u/madhan3396)\
**Post date:** [December 21, 2018, 1:38pm UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/7 "2018-12-21T13:38:06Z")

</div>

I just executed the same query by giving

```auto
"size":100

```

---

<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:** [December 21, 2018, 2:54pm UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/8 "2018-12-21T14:54:29Z")

</div>

I don't understand.

If you need help you must:

- Provide the **exact** queries/code you are running **with no modification**
- Provide the **exact** results you are getting **without any modification** (or at least clearly state what has been modified)

If this forum does not allow you uploading a big piece of code, please upload it to [gist.github.com](http://gist.github.com) and share the link here.

---

<div class="post-metadata">

**Author:** ![madhan3396](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/madhan3396/32/57318_2.png) [@madhan3396](https://discuss.elastic.co/u/madhan3396)\
**Post date:** [December 22, 2018, 4:38pm UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/9 "2018-12-22T16:38:47Z")

</div>

Oops. I'm so sorry.

Its a typo.

I mean't be say i just executed the query by giving

```auto
"size": 0

```

Reason for typo is that when i enter `:` followed by 0 it displays some suggestion and replaces my content and i didn't notice that. Sorry for that.

Cardinality value is my need. So i give size:0.

Please 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:** [December 22, 2018, 11:52pm UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/10 "2018-12-22T23:52:46Z")

</div>

If you need help answer the questions I asked.

---

<div class="post-metadata">

**Author:** ![madhan3396](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/madhan3396/32/57318_2.png) [@madhan3396](https://discuss.elastic.co/u/madhan3396)\
**Post date:** [December 23, 2018, 2:29pm UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/11 "2018-12-23T14:29:52Z")

</div>

You asked two things.  
1.searchResponse.toString();  
It is null  
2.full content of your curl call:  
I shared you that.

what more do you want ? 🙂

---

<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:** [December 23, 2018, 3:03pm UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/12 "2018-12-23T15:03:34Z")

</div>

Let me copy and paste the relevant part:

> If you need help you must:
> 
> - Provide the **exact** queries/code you are running **with no modification**
> - Provide the **exact** results you are getting **without any modification** (or at least clearly state what has been modified)

By the way, are you able to execute a simple MatchAllQuery using your Java code?

---

<div class="post-metadata">

**Author:** ![madhan3396](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/madhan3396/32/57318_2.png) [@madhan3396](https://discuss.elastic.co/u/madhan3396)\
**Post date:** [December 24, 2018, 11:39am UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/13 "2018-12-24T11:39:34Z")

</div>

Yes. MatchAllQuery woks fine.

Even TermsQuery works normally. But when it comes to cardinality, timesout happening .

---

<div class="post-metadata">

**Author:** ![madhan3396](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/madhan3396/32/57318_2.png) [@madhan3396](https://discuss.elastic.co/u/madhan3396)\
**Post date:** [December 27, 2018, 8:36am UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/14 "2018-12-27T08:36:51Z")

</div>

@dadoonet Can you please help me? \_/\_

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [December 27, 2018, 9:48am UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/15 "2018-12-27T09:48:10Z")

</div>

if you do not provide the information people are requesting when trying to help you, it is possible that people lose patience and possibly give up. This forum is manned by volunteers, so no one has any obligation to respond to a thread until it has been resolved. I would therefore recommend trying to help the people helping you as much as possible.

---

<div class="post-metadata">

**Author:** ![madhan3396](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/madhan3396/32/57318_2.png) [@madhan3396](https://discuss.elastic.co/u/madhan3396)\
**Post date:** [January 17, 2019, 1:51pm UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/16 "2019-01-17T13:51:39Z")

</div>

Cool. I understand. But some details i cannot share, that's the reason.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [January 17, 2019, 1:56pm UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/17 "2019-01-17T13:56:56Z")

</div>

Then it is virtually impossible for us to help...

---

<div class="post-metadata">

**Author:** ![madhan3396](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/madhan3396/32/57318_2.png) [@madhan3396](https://discuss.elastic.co/u/madhan3396)\
**Post date:** [January 17, 2019, 2:06pm UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/18 "2019-01-17T14:06:32Z")

</div>

Okay fine. Let me check if any other have the same problem.

---

<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 14, 2019, 2:06pm UTC](https://discuss.elastic.co/t/curl-returns-immediately-whereas-restclient-timesout/161802/19 "2019-02-14T14:06:34Z")

</div>

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