# Java Transport Client slower than curl request

**URL:** <https://discuss.elastic.co/t/java-transport-client-slower-than-curl-request/62067>\
**Category:** Elasticsearch\
**Created:** [October 3, 2016, 12:56pm UTC](https://discuss.elastic.co/t/java-transport-client-slower-than-curl-request/62067 "2016-10-03T12:56:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![NRS](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@NRS](https://discuss.elastic.co/u/NRS)\
**Post date:** [October 3, 2016, 12:56pm UTC](https://discuss.elastic.co/t/java-transport-client-slower-than-curl-request/62067/1 "2016-10-03T12:56:42Z")

</div>

I am facing the same issue . When I use curl to get response , it takes around 40-50 ms . But When same query is executed using execute().actionGet() using TransportClient , it takes around 1000 ms. Trying to figure out the root cause and the solution of this problem .

```
Settings settings = Settings.builder().put("cluster.name", "elasticsearch-stage").build();
productsClient = TransportClient.builder().settings(settings).build()
    .addTransportAddress(new InetSocketTransportAddress(
	     InetAddress.getByName(conf.getString("elasticsearch.client")),conf.getInt("elasticsearch.port")));
srb = productsClient.prepareSearch();
srb.setIndices(CustomUtility.readFromConfig("elasticsearch.index.name"));
srb.setTypes(CustomUtility.readFromConfig("elasticsearch.index.type"));
srb.setQuery(orFilterCatId);
srb.setFrom((int) startFrom);
srb.setSize(perPage);
response = srb.execute().actionGet();

```

Could anybody pls help me out with this.....................

---

<div class="post-metadata">

**Author:** ![NRS](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@NRS](https://discuss.elastic.co/u/NRS)\
**Post date:** [October 3, 2016, 12:57pm UTC](https://discuss.elastic.co/t/java-transport-client-slower-than-curl-request/62067/2 "2016-10-03T12:57:25Z")

</div>

I also tried setExpalin(false)....still no improvement

---

<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:** [October 3, 2016, 5:26pm UTC](https://discuss.elastic.co/t/java-transport-client-slower-than-curl-request/62067/3 "2016-10-03T17:26:12Z")

</div>

Can you describe what you have in `orFilterCatId`, `perPage`?  
May be print with a `srb.toString()` what does the request looks like?

Also can you give the exact query you are running with `curl`?

---

<div class="post-metadata">

**Author:** ![NRS](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@NRS](https://discuss.elastic.co/u/NRS)\
**Post date:** [October 4, 2016, 6:16am UTC](https://discuss.elastic.co/t/java-transport-client-slower-than-curl-request/62067/4 "2016-10-04T06:16:55Z")

</div>

Thanks for the response .

Following is srb.toString():

> 

{  
"from" : 0,  
"size" : 60,  
"query" : {  
"bool" : {  
"must" : [ {  
"bool" : {  
"should" : {  
"term" : {  
"catid" : "100"  
}  
}  
}  
}, {  
"term" : {  
"winning\_variant" : 1  
}  
}, {  
"term" : {  
"is\_in\_stock" : 1  
}  
}, {  
"range" : {  
"qty" : {  
"from" : 0,  
"to" : null,  
"include\_lower" : false,  
"include\_upper" : true  
}  
}  
}, {  
"range" : {  
"discounted\_price" : {  
"from" : 0,  
"to" : null,  
"include\_lower" : false,  
"include\_upper" : true  
}  
}  
}, {  
"range" : {  
"price" : {  
"from" : 0,  
"to" : null,  
"include\_lower" : false,  
"include\_upper" : true  
}  
}  
} ]  
}  
},  
"explain" : false,  
"sort" : [ {  
"relevance\_score" : {  
"order" : "desc"  
}  
}, {  
"qty" : {  
"order" : "desc"  
}  
} ]  
}

and I give the same query to curl request which looks like

curl -XGET [http://localhost:9200/indexname/typename/\_search](http://localhost:9200/indexname/typename/_search) -d' '

And also hit the same query in Sense.

Sense and curl were executed in 40-60 ms and java API query took above 1000ms

---

<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:** [October 4, 2016, 6:59am UTC](https://discuss.elastic.co/t/java-transport-client-slower-than-curl-request/62067/5 "2016-10-04T06:59:56Z")

</div>

Please format your code using `</>` icon. It will make your post more readable.

Can you print the output of `response.toString()` and the curl full response please?

---

<div class="post-metadata">

**Author:** ![NRS](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@NRS](https://discuss.elastic.co/u/NRS)\
**Post date:** [October 4, 2016, 7:10am UTC](https://discuss.elastic.co/t/java-transport-client-slower-than-curl-request/62067/6 "2016-10-04T07:10:00Z")

</div>

Thanks for the response .

response.toString is as follows

> 

{  
"took" : 36,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
}

From above it is clear that it is taking 36 ms but my following lines of code

> 

long startTime = System.currentTimeMillis();  
response = srb.execute().actionGet();  
long endTime=System.currentTimeMillis();  
System.out.println(endTime-startTime);

shows 1752 ms

I am not able to understand this

---

<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:** [October 4, 2016, 7:11am UTC](https://discuss.elastic.co/t/java-transport-client-slower-than-curl-request/62067/7 "2016-10-04T07:11:27Z")

</div>

So the response here is `36ms`. Not `1s`. You have something wrong which is happening in your code **AFTER** that.

---

<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:** [October 4, 2016, 7:12am UTC](https://discuss.elastic.co/t/java-transport-client-slower-than-curl-request/62067/8 "2016-10-04T07:12:08Z")

</div>

May be a proxy?

---

<div class="post-metadata">

**Author:** ![NRS](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@NRS](https://discuss.elastic.co/u/NRS)\
**Post date:** [October 4, 2016, 7:17am UTC](https://discuss.elastic.co/t/java-transport-client-slower-than-curl-request/62067/9 "2016-10-04T07:17:13Z")

</div>

Thanks 🙂 ...will check on this.

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [October 4, 2016, 8:16pm UTC](https://discuss.elastic.co/t/java-transport-client-slower-than-curl-request/62067/10 "2016-10-04T20:16:59Z")

</div>

The curl `took` time does not take network latency into account.

You should inspect

```auto
 SearchResponse response = srb.execute().actionGet();
 response.getTookInMillis();

```

and compare it with curl's `took`.

---

<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 5, 2017, 10:14pm UTC](https://discuss.elastic.co/t/java-transport-client-slower-than-curl-request/62067/11 "2017-07-05T22:14:58Z")

</div>


