# Elasticsearch 1.1.0 Java API Slower Than Curl for Certain Queries

**URL:** <https://discuss.elastic.co/t/elasticsearch-1-1-0-java-api-slower-than-curl-for-certain-queries/19369>\
**Category:** Elasticsearch\
**Created:** [August 20, 2014, 4:09pm UTC](https://discuss.elastic.co/t/elasticsearch-1-1-0-java-api-slower-than-curl-for-certain-queries/19369 "2014-08-20T16:09:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![chuck](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@chuck](https://discuss.elastic.co/u/chuck)\
**Post date:** [August 20, 2014, 4:09pm UTC](https://discuss.elastic.co/t/elasticsearch-1-1-0-java-api-slower-than-curl-for-certain-queries/19369/1 "2014-08-20T16:09:00Z")

</div>

I'm joining an existing cluster as a node via the Java API. I generate a  
relatively complicated multi-index "indices" query that combines the  
results of two different queries on two modestly sized indexes (150M  
records combined). Execution of actionGet() on this query takes  
approximately 1-2 seconds. On the other hand, if I dump the same query to  
JSON via the XContent jsonBuilder() and execute it with curl, it takes only  
14 ms. Results are identical in both cases.

Has anyone else had similar problems like this? Any thoughts on what might  
be the source of the problem? My next thought was to try connecting to the  
cluster via a TransportClient. Not sure if it will help or not...

Thanks!

- Elliott

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [August 20, 2014, 4:24pm UTC](https://discuss.elastic.co/t/elasticsearch-1-1-0-java-api-slower-than-curl-for-certain-queries/19369/2 "2014-08-20T16:24:30Z")

</div>

Hello Elliot ,

Is the sniffing enabled while creating the client.  
This means that , it will determine which all machines are enabled and does  
some load balancing.  
Which means that it needs additional time while creating the client.

Thanks  
Vineeth

On Wed, Aug 20, 2014 at 9:39 PM, Elliott Bradshaw [ebradshaw1@gmail.com](mailto:ebradshaw1@gmail.com)  
wrote:

> I'm joining an existing cluster as a node via the Java API. I generate a  
> relatively complicated multi-index "indices" query that combines the  
> results of two different queries on two modestly sized indexes (150M  
> records combined). Execution of actionGet() on this query takes  
> approximately 1-2 seconds. On the other hand, if I dump the same query to  
> JSON via the XContent jsonBuilder() and execute it with curl, it takes only  
> 14 ms. Results are identical in both cases.
> 
> Has anyone else had similar problems like this? Any thoughts on what  
> might be the source of the problem? My next thought was to try connecting  
> to the cluster via a TransportClient. Not sure if it will help or not...
> 
> Thanks!
> 
> - Elliott
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5m-8Tn\_VEGwcpUhr29r7RyL36%3DimKCEsVhvF5U3GOg5mQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5m-8Tn_VEGwcpUhr29r7RyL36%3DimKCEsVhvF5U3GOg5mQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![chuck](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@chuck](https://discuss.elastic.co/u/chuck)\
**Post date:** [August 20, 2014, 4:41pm UTC](https://discuss.elastic.co/t/elasticsearch-1-1-0-java-api-slower-than-curl-for-certain-queries/19369/3 "2014-08-20T16:41:21Z")

</div>

Vineeth,

Thanks, but according to the documentation, it looks like sniffing is only  
supported when using the TransportClient. I'm using the standard  
Node/Client configuration.

On Wednesday, August 20, 2014 12:24:45 PM UTC-4, vineeth mohan wrote:

> Hello Elliot ,
> 
> Is the sniffing enabled while creating the client.  
> This means that , it will determine which all machines are enabled and  
> does some load balancing.  
> Which means that it needs additional time while creating the client.
> 
> Thanks  
> Vineeth
> 
> On Wed, Aug 20, 2014 at 9:39 PM, Elliott Bradshaw \<[ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > I'm joining an existing cluster as a node via the Java API. I generate a  
> > relatively complicated multi-index "indices" query that combines the  
> > results of two different queries on two modestly sized indexes (150M  
> > records combined). Execution of actionGet() on this query takes  
> > approximately 1-2 seconds. On the other hand, if I dump the same query to  
> > JSON via the XContent jsonBuilder() and execute it with curl, it takes only  
> > 14 ms. Results are identical in both cases.
> > 
> > Has anyone else had similar problems like this? Any thoughts on what  
> > might be the source of the problem? My next thought was to try connecting  
> > to the cluster via a TransportClient. Not sure if it will help or not...
> > 
> > Thanks!
> > 
> > - Elliott
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [August 20, 2014, 4:46pm UTC](https://discuss.elastic.co/t/elasticsearch-1-1-0-java-api-slower-than-curl-for-certain-queries/19369/4 "2014-08-20T16:46:19Z")

</div>

Hello Eliott ,

I suspect if this has something to do with client creation.  
Can you see the time taken for the query alone and not the client creation.

Other possible reasons can be refresh flag ON.  
Please check that also.

Thanks  
Vineeth

On Wed, Aug 20, 2014 at 10:11 PM, Elliott Bradshaw [ebradshaw1@gmail.com](mailto:ebradshaw1@gmail.com)  
wrote:

> Vineeth,
> 
> Thanks, but according to the documentation, it looks like sniffing is only  
> supported when using the TransportClient. I'm using the standard  
> Node/Client configuration.
> 
> On Wednesday, August 20, 2014 12:24:45 PM UTC-4, vineeth mohan wrote:
> 
> > Hello Elliot ,
> > 
> > Is the sniffing enabled while creating the client.  
> > This means that , it will determine which all machines are enabled and  
> > does some load balancing.  
> > Which means that it needs additional time while creating the client.
> > 
> > Thanks  
> > Vineeth
> > 
> > On Wed, Aug 20, 2014 at 9:39 PM, Elliott Bradshaw [ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> > wrote:
> > 
> > > I'm joining an existing cluster as a node via the Java API. I generate  
> > > a relatively complicated multi-index "indices" query that combines the  
> > > results of two different queries on two modestly sized indexes (150M  
> > > records combined). Execution of actionGet() on this query takes  
> > > approximately 1-2 seconds. On the other hand, if I dump the same query to  
> > > JSON via the XContent jsonBuilder() and execute it with curl, it takes only  
> > > 14 ms. Results are identical in both cases.
> > > 
> > > Has anyone else had similar problems like this? Any thoughts on what  
> > > might be the source of the problem? My next thought was to try connecting  
> > > to the cluster via a TransportClient. Not sure if it will help or not...
> > > 
> > > Thanks!
> > > 
> > > - Elliott
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > 
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%  
> > > [40googlegroups.com](http://40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5m7B\_iaHJwudFcFEbwcVab3hjEo5KWWg\_3hLwmaDhuKDA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5m7B_iaHJwudFcFEbwcVab3hjEo5KWWg_3hLwmaDhuKDA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![chuck](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@chuck](https://discuss.elastic.co/u/chuck)\
**Post date:** [August 20, 2014, 6:02pm UTC](https://discuss.elastic.co/t/elasticsearch-1-1-0-java-api-slower-than-curl-for-certain-queries/19369/5 "2014-08-20T18:02:09Z")

</div>

Hi Vineeth,

The system is currently deployed on a Tomcat server and the client is  
created a single time on application start up. The time I gave of 1-2  
seconds is for the query alone, as far as I know.

Thanks,

Elliott

On Wednesday, August 20, 2014 12:46:34 PM UTC-4, vineeth mohan wrote:

> Hello Eliott ,
> 
> I suspect if this has something to do with client creation.  
> Can you see the time taken for the query alone and not the client creation.
> 
> Other possible reasons can be refresh flag ON.  
> Please check that also.
> 
> Thanks  
> Vineeth
> 
> On Wed, Aug 20, 2014 at 10:11 PM, Elliott Bradshaw \<[ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Vineeth,
> > 
> > Thanks, but according to the documentation, it looks like sniffing is  
> > only supported when using the TransportClient. I'm using the standard  
> > Node/Client configuration.
> > 
> > On Wednesday, August 20, 2014 12:24:45 PM UTC-4, vineeth mohan wrote:
> > 
> > > Hello Elliot ,
> > > 
> > > Is the sniffing enabled while creating the client.  
> > > This means that , it will determine which all machines are enabled and  
> > > does some load balancing.  
> > > Which means that it needs additional time while creating the client.
> > > 
> > > Thanks  
> > > Vineeth
> > > 
> > > On Wed, Aug 20, 2014 at 9:39 PM, Elliott Bradshaw [ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> > > wrote:
> > > 
> > > > I'm joining an existing cluster as a node via the Java API. I generate  
> > > > a relatively complicated multi-index "indices" query that combines the  
> > > > results of two different queries on two modestly sized indexes (150M  
> > > > records combined). Execution of actionGet() on this query takes  
> > > > approximately 1-2 seconds. On the other hand, if I dump the same query to  
> > > > JSON via the XContent jsonBuilder() and execute it with curl, it takes only  
> > > > 14 ms. Results are identical in both cases.
> > > > 
> > > > Has anyone else had similar problems like this? Any thoughts on what  
> > > > might be the source of the problem? My next thought was to try connecting  
> > > > to the cluster via a TransportClient. Not sure if it will help or not...
> > > > 
> > > > Thanks!
> > > > 
> > > > - Elliott
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > 
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%  
> > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [August 20, 2014, 6:55pm UTC](https://discuss.elastic.co/t/elasticsearch-1-1-0-java-api-slower-than-curl-for-certain-queries/19369/6 "2014-08-20T18:55:42Z")

</div>

Since curl requests use the Java API, it is impossible to execute this  
faster than Java API.

Can you post the Java code and curl request you use? Have you compared the  
queries sent? What does the query look like? How does the result look like?

Without this information it is very hard to discuss any issue, it will be  
just guessing.

Jörg

On Wed, Aug 20, 2014 at 8:02 PM, Elliott Bradshaw [ebradshaw1@gmail.com](mailto:ebradshaw1@gmail.com)  
wrote:

> Hi Vineeth,
> 
> The system is currently deployed on a Tomcat server and the client is  
> created a single time on application start up. The time I gave of 1-2  
> seconds is for the query alone, as far as I know.
> 
> Thanks,
> 
> Elliott
> 
> On Wednesday, August 20, 2014 12:46:34 PM UTC-4, vineeth mohan wrote:
> 
> > Hello Eliott ,
> > 
> > I suspect if this has something to do with client creation.  
> > Can you see the time taken for the query alone and not the client  
> > creation.
> > 
> > Other possible reasons can be refresh flag ON.  
> > Please check that also.
> > 
> > Thanks  
> > Vineeth
> > 
> > On Wed, Aug 20, 2014 at 10:11 PM, Elliott Bradshaw [ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> > wrote:
> > 
> > > Vineeth,
> > > 
> > > Thanks, but according to the documentation, it looks like sniffing is  
> > > only supported when using the TransportClient. I'm using the standard  
> > > Node/Client configuration.
> > > 
> > > On Wednesday, August 20, 2014 12:24:45 PM UTC-4, vineeth mohan wrote:
> > > 
> > > > Hello Elliot ,
> > > > 
> > > > Is the sniffing enabled while creating the client.  
> > > > This means that , it will determine which all machines are enabled and  
> > > > does some load balancing.  
> > > > Which means that it needs additional time while creating the client.
> > > > 
> > > > Thanks  
> > > > Vineeth
> > > > 
> > > > On Wed, Aug 20, 2014 at 9:39 PM, Elliott Bradshaw [ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> > > > wrote:
> > > > 
> > > > > I'm joining an existing cluster as a node via the Java API. I  
> > > > > generate a relatively complicated multi-index "indices" query that combines  
> > > > > the results of two different queries on two modestly sized indexes (150M  
> > > > > records combined). Execution of actionGet() on this query takes  
> > > > > approximately 1-2 seconds. On the other hand, if I dump the same query to  
> > > > > JSON via the XContent jsonBuilder() and execute it with curl, it takes only  
> > > > > 14 ms. Results are identical in both cases.
> > > > > 
> > > > > Has anyone else had similar problems like this? Any thoughts on what  
> > > > > might be the source of the problem? My next thought was to try connecting  
> > > > > to the cluster via a TransportClient. Not sure if it will help or not...
> > > > > 
> > > > > Thanks!
> > > > > 
> > > > > - Elliott
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > 
> > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40goo  
> > > > > [glegroups.com](http://glegroups.com)  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > .  
> > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%  
> > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .
> > > 
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHuXWpN2RU1SdDJzQsAy9xxf39cdSSmRD1nPs4\_i8PMGQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHuXWpN2RU1SdDJzQsAy9xxf39cdSSmRD1nPs4_i8PMGQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![chuck](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@chuck](https://discuss.elastic.co/u/chuck)\
**Post date:** [August 21, 2014, 2:16am UTC](https://discuss.elastic.co/t/elasticsearch-1-1-0-java-api-slower-than-curl-for-certain-queries/19369/7 "2014-08-21T02:16:42Z")

</div>

Jorg,

Thanks for the response. I understand that curl hits the Java API, that's  
why the issue is so strange.

I will try to make some more tweaks tomorrow, and I can send the query as  
well. I can't post the java code as it's extensive and spans several  
classes (the resultant query is relatively complex). However, I log the  
JSON dump of the final QueryBuilder object and use that in my curl request.

- Elliott

On Wednesday, August 20, 2014 2:55:50 PM UTC-4, Jörg Prante wrote:

> Since curl requests use the Java API, it is impossible to execute this  
> faster than Java API.
> 
> Can you post the Java code and curl request you use? Have you compared the  
> queries sent? What does the query look like? How does the result look like?
> 
> Without this information it is very hard to discuss any issue, it will be  
> just guessing.
> 
> Jörg
> 
> On Wed, Aug 20, 2014 at 8:02 PM, Elliott Bradshaw \<[ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hi Vineeth,
> > 
> > The system is currently deployed on a Tomcat server and the client is  
> > created a single time on application start up. The time I gave of 1-2  
> > seconds is for the query alone, as far as I know.
> > 
> > Thanks,
> > 
> > Elliott
> > 
> > On Wednesday, August 20, 2014 12:46:34 PM UTC-4, vineeth mohan wrote:
> > 
> > > Hello Eliott ,
> > > 
> > > I suspect if this has something to do with client creation.  
> > > Can you see the time taken for the query alone and not the client  
> > > creation.
> > > 
> > > Other possible reasons can be refresh flag ON.  
> > > Please check that also.
> > > 
> > > Thanks  
> > > Vineeth
> > > 
> > > On Wed, Aug 20, 2014 at 10:11 PM, Elliott Bradshaw [ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> > > wrote:
> > > 
> > > > Vineeth,
> > > > 
> > > > Thanks, but according to the documentation, it looks like sniffing is  
> > > > only supported when using the TransportClient. I'm using the standard  
> > > > Node/Client configuration.
> > > > 
> > > > On Wednesday, August 20, 2014 12:24:45 PM UTC-4, vineeth mohan wrote:
> > > > 
> > > > > Hello Elliot ,
> > > > > 
> > > > > Is the sniffing enabled while creating the client.  
> > > > > This means that , it will determine which all machines are enabled and  
> > > > > does some load balancing.  
> > > > > Which means that it needs additional time while creating the client.
> > > > > 
> > > > > Thanks  
> > > > > Vineeth
> > > > > 
> > > > > On Wed, Aug 20, 2014 at 9:39 PM, Elliott Bradshaw [ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> > > > > wrote:
> > > > > 
> > > > > > I'm joining an existing cluster as a node via the Java API. I  
> > > > > > generate a relatively complicated multi-index "indices" query that combines  
> > > > > > the results of two different queries on two modestly sized indexes (150M  
> > > > > > records combined). Execution of actionGet() on this query takes  
> > > > > > approximately 1-2 seconds. On the other hand, if I dump the same query to  
> > > > > > JSON via the XContent jsonBuilder() and execute it with curl, it takes only  
> > > > > > 14 ms. Results are identical in both cases.
> > > > > > 
> > > > > > Has anyone else had similar problems like this? Any thoughts on what  
> > > > > > might be the source of the problem? My next thought was to try connecting  
> > > > > > to the cluster via a TransportClient. Not sure if it will help or not...
> > > > > > 
> > > > > > Thanks!
> > > > > > 
> > > > > > - Elliott
> > > > > > 
> > > > > > --  
> > > > > > You received this message because you are subscribed to the Google  
> > > > > > Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > > 
> > > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > > msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40goo  
> > > > > > [glegroups.com](http://glegroups.com)  
> > > > > > [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > > .  
> > > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%  
> > > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > .
> > > > 
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/cb19a3a8-c8dc-48c8-aa44-ebd718667be3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cb19a3a8-c8dc-48c8-aa44-ebd718667be3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [August 21, 2014, 2:23am UTC](https://discuss.elastic.co/t/elasticsearch-1-1-0-java-api-slower-than-curl-for-certain-queries/19369/8 "2014-08-21T02:23:35Z")

</div>

Hello Elliott ,

There could be many other variables here.  
One is that the first time when you run the query , it would be slow and  
the second time when you run it , then it is fast.  
You might have always executed the java code first and then tried the  
normal curl.

Please reproduce the issue in a java code with just the query and paste  
here.  
That might help us better debug the issue.

Thanks  
Vineeth

On Thu, Aug 21, 2014 at 7:46 AM, Elliott Bradshaw [ebradshaw1@gmail.com](mailto:ebradshaw1@gmail.com)  
wrote:

> Jorg,
> 
> Thanks for the response. I understand that curl hits the Java API, that's  
> why the issue is so strange.
> 
> I will try to make some more tweaks tomorrow, and I can send the query as  
> well. I can't post the java code as it's extensive and spans several  
> classes (the resultant query is relatively complex). However, I log the  
> JSON dump of the final QueryBuilder object and use that in my curl request.
> 
> - Elliott
> 
> On Wednesday, August 20, 2014 2:55:50 PM UTC-4, Jörg Prante wrote:
> 
> > Since curl requests use the Java API, it is impossible to execute this  
> > faster than Java API.
> > 
> > Can you post the Java code and curl request you use? Have you compared  
> > the queries sent? What does the query look like? How does the result look  
> > like?
> > 
> > Without this information it is very hard to discuss any issue, it will be  
> > just guessing.
> > 
> > Jörg
> > 
> > On Wed, Aug 20, 2014 at 8:02 PM, Elliott Bradshaw [ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> > wrote:
> > 
> > > Hi Vineeth,
> > > 
> > > The system is currently deployed on a Tomcat server and the client is  
> > > created a single time on application start up. The time I gave of 1-2  
> > > seconds is for the query alone, as far as I know.
> > > 
> > > Thanks,
> > > 
> > > Elliott
> > > 
> > > On Wednesday, August 20, 2014 12:46:34 PM UTC-4, vineeth mohan wrote:
> > > 
> > > > Hello Eliott ,
> > > > 
> > > > I suspect if this has something to do with client creation.  
> > > > Can you see the time taken for the query alone and not the client  
> > > > creation.
> > > > 
> > > > Other possible reasons can be refresh flag ON.  
> > > > Please check that also.
> > > > 
> > > > Thanks  
> > > > Vineeth
> > > > 
> > > > On Wed, Aug 20, 2014 at 10:11 PM, Elliott Bradshaw [ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> > > > wrote:
> > > > 
> > > > > Vineeth,
> > > > > 
> > > > > Thanks, but according to the documentation, it looks like sniffing is  
> > > > > only supported when using the TransportClient. I'm using the standard  
> > > > > Node/Client configuration.
> > > > > 
> > > > > On Wednesday, August 20, 2014 12:24:45 PM UTC-4, vineeth mohan wrote:
> > > > > 
> > > > > > Hello Elliot ,
> > > > > > 
> > > > > > Is the sniffing enabled while creating the client.  
> > > > > > This means that , it will determine which all machines are enabled  
> > > > > > and does some load balancing.  
> > > > > > Which means that it needs additional time while creating the client.
> > > > > > 
> > > > > > Thanks  
> > > > > > Vineeth
> > > > > > 
> > > > > > On Wed, Aug 20, 2014 at 9:39 PM, Elliott Bradshaw \<[ebrad...@gmail.com](mailto:ebrad...@gmail.com)
> > > > > > 
> > > > > > > wrote:
> > > > > > 
> > > > > > > I'm joining an existing cluster as a node via the Java API. I  
> > > > > > > generate a relatively complicated multi-index "indices" query that combines  
> > > > > > > the results of two different queries on two modestly sized indexes (150M  
> > > > > > > records combined). Execution of actionGet() on this query takes  
> > > > > > > approximately 1-2 seconds. On the other hand, if I dump the same query to  
> > > > > > > JSON via the XContent jsonBuilder() and execute it with curl, it takes only  
> > > > > > > 14 ms. Results are identical in both cases.
> > > > > > > 
> > > > > > > Has anyone else had similar problems like this? Any thoughts on  
> > > > > > > what might be the source of the problem? My next thought was to try  
> > > > > > > connecting to the cluster via a TransportClient. Not sure if it will help  
> > > > > > > or not...
> > > > > > > 
> > > > > > > Thanks!
> > > > > > > 
> > > > > > > - Elliott
> > > > > > > 
> > > > > > > --  
> > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > Groups "elasticsearch" group.  
> > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > > > 
> > > > > > > To view this discussion on the web visit  
> > > > > > > [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3be](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3be)  
> > > > > > > b-4e80-8672-1981bcb8c35c%[40googlegroups.com](http://40googlegroups.com)  
> > > > > > > [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > > > .  
> > > > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > > > 
> > > > > > --  
> > > > > > You received this message because you are subscribed to the Google  
> > > > > > Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > > msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40goo  
> > > > > > [glegroups.com](http://glegroups.com)  
> > > > > > [https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > > .
> > > > > 
> > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%  
> > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .
> > > 
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/cb19a3a8-c8dc-48c8-aa44-ebd718667be3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cb19a3a8-c8dc-48c8-aa44-ebd718667be3%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/cb19a3a8-c8dc-48c8-aa44-ebd718667be3%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/cb19a3a8-c8dc-48c8-aa44-ebd718667be3%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5mFpcEj7hURgUqqaA6y0ZrVSwTnb-J335QhSdnru0eFug%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5mFpcEj7hURgUqqaA6y0ZrVSwTnb-J335QhSdnru0eFug%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![chuck](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@chuck](https://discuss.elastic.co/u/chuck)\
**Post date:** [August 21, 2014, 3:06pm UTC](https://discuss.elastic.co/t/elasticsearch-1-1-0-java-api-slower-than-curl-for-certain-queries/19369/9 "2014-08-21T15:06:32Z")

</div>

Hi guys,

Thanks for getting back to me.

Here's the JSON for the query:

{ "bool" : {  
"must" : [ {  
"indices" : {  
"indices" : "index1",  
"query" : {  
"filtered" : {  
"query" : {  
"function\_score" : {  
"query" : {  
"multi\_match" : {  
"query" : "this is my query string",  
"fields" : [ "field1^1.2",  
"field2", "field3", "field4", "field5" ],  
"type" : "cross\_fields",  
"operator" : "AND",  
"boost" : 1.2,  
"fuzziness" : "AUTO", //does not  
work unfortunately on cross\_fields ☹ ...  
"minimum\_should\_match" : "75%",  
"tie\_breaker" : 0.1  
}  
},  
"gauss" : {  
"fields6" : {  
"origin" : 1,  
"scale" : 25  
}  
}  
}  
},  
"filter" : {  
"and" : {  
"filters" :   
}  
}  
}  
}  
}  
},  
{  
"indices" : {  
"indices" : "index2",  
"query" : {  
"filtered" : {  
"query" : {  
"multi\_match" : {  
"query" : "this is my query string",  
"fields" : [ "field7^1.2", "field6",  
"field9", "field10", "field11" ],  
"type" : "cross\_fields",  
"operator" : "AND",  
"boost" : 1.2,  
"fuzziness" : "AUTO", //does not work  
unfortunately on cross\_fields ☹ ...  
"minimum\_should\_match" : "75%",  
"tie\_breaker" : 0.1  
}  
},  
"filter" : {  
"and" : {  
"filters" :   
}  
}  
}  
}  
}  
}  
]  
}

This JSON is output to a log by the following Java code:

QueryBuilder query = getQuery();

String json = query.toXContent(jsonBuilder(), null).string();  
logger.debug(json); //Outputs JSON that I copy into my curl body  
(displayed above)

I then execute the query:

logger.debug("Search request beginning");

SearchResponse response = client  
.prepareSearch()  
.setQuery(query)  
.setExplain(false)  
.setSize(10)  
.execute().actionGet();

logger.debug("Search request complete");

The time between the two debug statements is always between 1-2 seconds.  
This is after running many queries via a webservice. The curl request  
always runs in 10-30 ms.

Any other thoughts?

On Wednesday, August 20, 2014 10:23:49 PM UTC-4, vineeth mohan wrote:

> Hello Elliott ,
> 
> There could be many other variables here.  
> One is that the first time when you run the query , it would be slow and  
> the second time when you run it , then it is fast.  
> You might have always executed the java code first and then tried the  
> normal curl.
> 
> Please reproduce the issue in a java code with just the query and paste  
> here.  
> That might help us better debug the issue.
> 
> Thanks  
> Vineeth
> 
> On Thu, Aug 21, 2014 at 7:46 AM, Elliott Bradshaw \<[ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Jorg,
> > 
> > Thanks for the response. I understand that curl hits the Java API,  
> > that's why the issue is so strange.
> > 
> > I will try to make some more tweaks tomorrow, and I can send the query as  
> > well. I can't post the java code as it's extensive and spans several  
> > classes (the resultant query is relatively complex). However, I log the  
> > JSON dump of the final QueryBuilder object and use that in my curl request.
> > 
> > - Elliott
> > 
> > On Wednesday, August 20, 2014 2:55:50 PM UTC-4, Jörg Prante wrote:
> > 
> > > Since curl requests use the Java API, it is impossible to execute this  
> > > faster than Java API.
> > > 
> > > Can you post the Java code and curl request you use? Have you compared  
> > > the queries sent? What does the query look like? How does the result look  
> > > like?
> > > 
> > > Without this information it is very hard to discuss any issue, it will  
> > > be just guessing.
> > > 
> > > Jörg
> > > 
> > > On Wed, Aug 20, 2014 at 8:02 PM, Elliott Bradshaw [ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> > > wrote:
> > > 
> > > > Hi Vineeth,
> > > > 
> > > > The system is currently deployed on a Tomcat server and the client is  
> > > > created a single time on application start up. The time I gave of 1-2  
> > > > seconds is for the query alone, as far as I know.
> > > > 
> > > > Thanks,
> > > > 
> > > > Elliott
> > > > 
> > > > On Wednesday, August 20, 2014 12:46:34 PM UTC-4, vineeth mohan wrote:
> > > > 
> > > > > Hello Eliott ,
> > > > > 
> > > > > I suspect if this has something to do with client creation.  
> > > > > Can you see the time taken for the query alone and not the client  
> > > > > creation.
> > > > > 
> > > > > Other possible reasons can be refresh flag ON.  
> > > > > Please check that also.
> > > > > 
> > > > > Thanks  
> > > > > Vineeth
> > > > > 
> > > > > On Wed, Aug 20, 2014 at 10:11 PM, Elliott Bradshaw \<[ebrad...@gmail.com](mailto:ebrad...@gmail.com)
> > > > > 
> > > > > > wrote:
> > > > > 
> > > > > > Vineeth,
> > > > > > 
> > > > > > Thanks, but according to the documentation, it looks like sniffing is  
> > > > > > only supported when using the TransportClient. I'm using the standard  
> > > > > > Node/Client configuration.
> > > > > > 
> > > > > > On Wednesday, August 20, 2014 12:24:45 PM UTC-4, vineeth mohan wrote:
> > > > > > 
> > > > > > > Hello Elliot ,
> > > > > > > 
> > > > > > > Is the sniffing enabled while creating the client.  
> > > > > > > This means that , it will determine which all machines are enabled  
> > > > > > > and does some load balancing.  
> > > > > > > Which means that it needs additional time while creating the client.
> > > > > > > 
> > > > > > > Thanks  
> > > > > > > Vineeth
> > > > > > > 
> > > > > > > On Wed, Aug 20, 2014 at 9:39 PM, Elliott Bradshaw \<  
> > > > > > > [ebrad...@gmail.com](mailto:ebrad...@gmail.com)\> wrote:
> > > > > > > 
> > > > > > > > I'm joining an existing cluster as a node via the Java API. I  
> > > > > > > > generate a relatively complicated multi-index "indices" query that combines  
> > > > > > > > the results of two different queries on two modestly sized indexes (150M  
> > > > > > > > records combined). Execution of actionGet() on this query takes  
> > > > > > > > approximately 1-2 seconds. On the other hand, if I dump the same query to  
> > > > > > > > JSON via the XContent jsonBuilder() and execute it with curl, it takes only  
> > > > > > > > 14 ms. Results are identical in both cases.
> > > > > > > > 
> > > > > > > > Has anyone else had similar problems like this? Any thoughts on  
> > > > > > > > what might be the source of the problem? My next thought was to try  
> > > > > > > > connecting to the cluster via a TransportClient. Not sure if it will help  
> > > > > > > > or not...
> > > > > > > > 
> > > > > > > > Thanks!
> > > > > > > > 
> > > > > > > > - Elliott
> > > > > > > > 
> > > > > > > > --  
> > > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > > Groups "elasticsearch" group.  
> > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > > > > 
> > > > > > > > To view this discussion on the web visit  
> > > > > > > > [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3be](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3be)  
> > > > > > > > b-4e80-8672-1981bcb8c35c%[40googlegroups.com](http://40googlegroups.com)  
> > > > > > > > [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > > > > .  
> > > > > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > > > > 
> > > > > > > --  
> > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > Groups "elasticsearch" group.  
> > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > > > msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40goo  
> > > > > > > [glegroups.com](http://glegroups.com)  
> > > > > > > [https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > > > .
> > > > > > 
> > > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%  
> > > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > .
> > > > 
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/cb19a3a8-c8dc-48c8-aa44-ebd718667be3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cb19a3a8-c8dc-48c8-aa44-ebd718667be3%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/cb19a3a8-c8dc-48c8-aa44-ebd718667be3%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/cb19a3a8-c8dc-48c8-aa44-ebd718667be3%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/81f86a13-eea0-4b86-8e56-981eb2045d5e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/81f86a13-eea0-4b86-8e56-981eb2045d5e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![chuck](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@chuck](https://discuss.elastic.co/u/chuck)\
**Post date:** [August 21, 2014, 4:00pm UTC](https://discuss.elastic.co/t/elasticsearch-1-1-0-java-api-slower-than-curl-for-certain-queries/19369/10 "2014-08-21T16:00:42Z")

</div>

Hey I think I got it!

So in my curl request, I was specifying the two indexes in the rest  
endpoint, but I did not specify them in my java search request. My only  
other index is a suggest index, and I would think that it would be ignored  
when I ran the query, but I guess not.

Thanks a lot for your time. This was definitely one of those bang your  
head against the wall issues.

On Thursday, August 21, 2014 11:06:32 AM UTC-4, Elliott Bradshaw wrote:

> Hi guys,
> 
> Thanks for getting back to me.
> 
> Here's the JSON for the query:
> 
> { "bool" : {  
> "must" : [ {  
> "indices" : {  
> "indices" : "index1",  
> "query" : {  
> "filtered" : {  
> "query" : {  
> "function\_score" : {  
> "query" : {  
> "multi\_match" : {  
> "query" : "this is my query  
> string",  
> "fields" : [ "field1^1.2",  
> "field2", "field3", "field4", "field5" ],  
> "type" : "cross\_fields",  
> "operator" : "AND",  
> "boost" : 1.2,  
> "fuzziness" : "AUTO", //does not  
> work unfortunately on cross\_fields ☹ ...  
> "minimum\_should\_match" : "75%",  
> "tie\_breaker" : 0.1  
> }  
> },  
> "gauss" : {  
> "fields6" : {  
> "origin" : 1,  
> "scale" : 25  
> }  
> }  
> }  
> },  
> "filter" : {  
> "and" : {  
> "filters" :   
> }  
> }  
> }  
> }  
> }  
> },  
> {  
> "indices" : {  
> "indices" : "index2",  
> "query" : {  
> "filtered" : {  
> "query" : {  
> "multi\_match" : {  
> "query" : "this is my query string",  
> "fields" : [ "field7^1.2", "field6",  
> "field9", "field10", "field11" ],  
> "type" : "cross\_fields",  
> "operator" : "AND",  
> "boost" : 1.2,  
> "fuzziness" : "AUTO", //does not work  
> unfortunately on cross\_fields ☹ ...  
> "minimum\_should\_match" : "75%",  
> "tie\_breaker" : 0.1  
> }  
> },  
> "filter" : {  
> "and" : {  
> "filters" :   
> }  
> }  
> }  
> }  
> }  
> }  
> ]  
> }
> 
> This JSON is output to a log by the following Java code:
> 
> QueryBuilder query = getQuery();
> 
> String json = query.toXContent(jsonBuilder(), null).string();  
> logger.debug(json); //Outputs JSON that I copy into my curl body  
> (displayed above)
> 
> I then execute the query:
> 
> logger.debug("Search request beginning");
> 
> SearchResponse response = client  
> .prepareSearch()  
> .setQuery(query)  
> .setExplain(false)  
> .setSize(10)  
> .execute().actionGet();
> 
> logger.debug("Search request complete");
> 
> The time between the two debug statements is always between 1-2 seconds.  
> This is after running many queries via a webservice. The curl request  
> always runs in 10-30 ms.
> 
> Any other thoughts?
> 
> On Wednesday, August 20, 2014 10:23:49 PM UTC-4, vineeth mohan wrote:
> 
> > Hello Elliott ,
> > 
> > There could be many other variables here.  
> > One is that the first time when you run the query , it would be slow and  
> > the second time when you run it , then it is fast.  
> > You might have always executed the java code first and then tried the  
> > normal curl.
> > 
> > Please reproduce the issue in a java code with just the query and paste  
> > here.  
> > That might help us better debug the issue.
> > 
> > Thanks  
> > Vineeth
> > 
> > On Thu, Aug 21, 2014 at 7:46 AM, Elliott Bradshaw [ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> > wrote:
> > 
> > > Jorg,
> > > 
> > > Thanks for the response. I understand that curl hits the Java API,  
> > > that's why the issue is so strange.
> > > 
> > > I will try to make some more tweaks tomorrow, and I can send the query  
> > > as well. I can't post the java code as it's extensive and spans several  
> > > classes (the resultant query is relatively complex). However, I log the  
> > > JSON dump of the final QueryBuilder object and use that in my curl request.
> > > 
> > > - Elliott
> > > 
> > > On Wednesday, August 20, 2014 2:55:50 PM UTC-4, Jörg Prante wrote:
> > > 
> > > > Since curl requests use the Java API, it is impossible to execute this  
> > > > faster than Java API.
> > > > 
> > > > Can you post the Java code and curl request you use? Have you compared  
> > > > the queries sent? What does the query look like? How does the result look  
> > > > like?
> > > > 
> > > > Without this information it is very hard to discuss any issue, it will  
> > > > be just guessing.
> > > > 
> > > > Jörg
> > > > 
> > > > On Wed, Aug 20, 2014 at 8:02 PM, Elliott Bradshaw [ebrad...@gmail.com](mailto:ebrad...@gmail.com)  
> > > > wrote:
> > > > 
> > > > > Hi Vineeth,
> > > > > 
> > > > > The system is currently deployed on a Tomcat server and the client is  
> > > > > created a single time on application start up. The time I gave of 1-2  
> > > > > seconds is for the query alone, as far as I know.
> > > > > 
> > > > > Thanks,
> > > > > 
> > > > > Elliott
> > > > > 
> > > > > On Wednesday, August 20, 2014 12:46:34 PM UTC-4, vineeth mohan wrote:
> > > > > 
> > > > > > Hello Eliott ,
> > > > > > 
> > > > > > I suspect if this has something to do with client creation.  
> > > > > > Can you see the time taken for the query alone and not the client  
> > > > > > creation.
> > > > > > 
> > > > > > Other possible reasons can be refresh flag ON.  
> > > > > > Please check that also.
> > > > > > 
> > > > > > Thanks  
> > > > > > Vineeth
> > > > > > 
> > > > > > On Wed, Aug 20, 2014 at 10:11 PM, Elliott Bradshaw \<  
> > > > > > [ebrad...@gmail.com](mailto:ebrad...@gmail.com)\> wrote:
> > > > > > 
> > > > > > > Vineeth,
> > > > > > > 
> > > > > > > Thanks, but according to the documentation, it looks like sniffing  
> > > > > > > is only supported when using the TransportClient. I'm using the standard  
> > > > > > > Node/Client configuration.
> > > > > > > 
> > > > > > > On Wednesday, August 20, 2014 12:24:45 PM UTC-4, vineeth mohan wrote:
> > > > > > > 
> > > > > > > > Hello Elliot ,
> > > > > > > > 
> > > > > > > > Is the sniffing enabled while creating the client.  
> > > > > > > > This means that , it will determine which all machines are enabled  
> > > > > > > > and does some load balancing.  
> > > > > > > > Which means that it needs additional time while creating the client.
> > > > > > > > 
> > > > > > > > Thanks  
> > > > > > > > Vineeth
> > > > > > > > 
> > > > > > > > On Wed, Aug 20, 2014 at 9:39 PM, Elliott Bradshaw \<  
> > > > > > > > [ebrad...@gmail.com](mailto:ebrad...@gmail.com)\> wrote:
> > > > > > > > 
> > > > > > > > > I'm joining an existing cluster as a node via the Java API. I  
> > > > > > > > > generate a relatively complicated multi-index "indices" query that combines  
> > > > > > > > > the results of two different queries on two modestly sized indexes (150M  
> > > > > > > > > records combined). Execution of actionGet() on this query takes  
> > > > > > > > > approximately 1-2 seconds. On the other hand, if I dump the same query to  
> > > > > > > > > JSON via the XContent jsonBuilder() and execute it with curl, it takes only  
> > > > > > > > > 14 ms. Results are identical in both cases.
> > > > > > > > > 
> > > > > > > > > Has anyone else had similar problems like this? Any thoughts on  
> > > > > > > > > what might be the source of the problem? My next thought was to try  
> > > > > > > > > connecting to the cluster via a TransportClient. Not sure if it will help  
> > > > > > > > > or not...
> > > > > > > > > 
> > > > > > > > > Thanks!
> > > > > > > > > 
> > > > > > > > > - Elliott
> > > > > > > > > 
> > > > > > > > > --  
> > > > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > > > Groups "elasticsearch" group.  
> > > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).
> > > > > > > > > 
> > > > > > > > > To view this discussion on the web visit  
> > > > > > > > > [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3be](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3be)  
> > > > > > > > > b-4e80-8672-1981bcb8c35c%[40googlegroups.com](http://40googlegroups.com)  
> > > > > > > > > [https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fa4fb57e-3beb-4e80-8672-1981bcb8c35c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > > > > > .  
> > > > > > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > > > > > 
> > > > > > > > --  
> > > > > > > > You received this message because you are subscribed to the Google  
> > > > > > > > Groups "elasticsearch" group.  
> > > > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > > > send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > > > To view this discussion on the web visit  
> > > > > > > > [https://groups.google.com/d/msgid/elasticsearch/bfae9628-021](https://groups.google.com/d/msgid/elasticsearch/bfae9628-021)  
> > > > > > > > 2-4b03-8f76-4fb85aab23e9%[40googlegroups.com](http://40googlegroups.com)  
> > > > > > > > [https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/bfae9628-0212-4b03-8f76-4fb85aab23e9%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > > > > .
> > > > > > > 
> > > > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > > > 
> > > > > > --  
> > > > > > You received this message because you are subscribed to the Google  
> > > > > > Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > > msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%  
> > > > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > > > [https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/16c49c37-4c0c-4b37-85a5-2969aa6c5ee4%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > > .
> > > > > 
> > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/cb19a3a8-c8dc-48c8-aa44-ebd718667be3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cb19a3a8-c8dc-48c8-aa44-ebd718667be3%40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/cb19a3a8-c8dc-48c8-aa44-ebd718667be3%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/cb19a3a8-c8dc-48c8-aa44-ebd718667be3%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .
> > > 
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/b7b073db-eef5-4680-9d4e-05a261ffd0b3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b7b073db-eef5-4680-9d4e-05a261ffd0b3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:07am UTC](https://discuss.elastic.co/t/elasticsearch-1-1-0-java-api-slower-than-curl-for-certain-queries/19369/11 "2017-07-06T01:07:09Z")

</div>


