# Running the same ES query through the Java API and the ES console gives different number of results

**URL:** <https://discuss.elastic.co/t/running-the-same-es-query-through-the-java-api-and-the-es-console-gives-different-number-of-results/10827>\
**Category:** Elasticsearch\
**Created:** [February 20, 2013, 10:39pm UTC](https://discuss.elastic.co/t/running-the-same-es-query-through-the-java-api-and-the-es-console-gives-different-number-of-results/10827 "2013-02-20T22:39:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)\
**Post date:** [February 20, 2013, 10:39pm UTC](https://discuss.elastic.co/t/running-the-same-es-query-through-the-java-api-and-the-es-console-gives-different-number-of-results/10827/1 "2013-02-20T22:39:29Z")

</div>

Hi,

When i run the below query through the Java API i get a certain number of  
results but when i run the same query through the elastic search console i  
get fewer records. The Elastic search version is 0.19.2 and same is the  
version of the Jar being used. Has anyone faced this situation before?

{  
"from" : 0,  
"size" : 2,  
"query" : {  
"filtered" : {  
"query" : {"match\_all" : {}}  
,"filter" : {  
"and" : {  
"filters" :  
[ {  
"exists" : {"field" : "id"}}  
, {"range" : {"startDate" : {"from" : null,"to" :  
"2013-02-20","include\_lower" : true,"include\_upper" : true}}}  
, {"term" : {"completed" : "true"}}, {"term" : {"active" :  
"true"}}, {"term" : {"traded" : "false"}}, {"term" : {"working" :  
"false"}}, {"term" : {"secondhand" : "false"}  
} ]  
}  
}  
}  
},  
"fields" : ["name", "price", "marketprice", "id"],  
"sort" : [{"id" : {"order" : "asc"}}]  
}

Thanks,  
John

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)\
**Post date:** [February 20, 2013, 11:06pm UTC](https://discuss.elastic.co/t/running-the-same-es-query-through-the-java-api-and-the-es-console-gives-different-number-of-results/10827/2 "2013-02-20T23:06:34Z")

</div>

I think i should make my post more precise.  
When i run this query from the Elastic Search head/console, it returns the  
same number of records as requested but running it through the Java API  
returns more, almost double.

On Wednesday, 20 February 2013 16:39:29 UTC-6, john wrote:

> Hi,
> 
> When i run the below query through the Java API i get a certain number of  
> results but when i run the same query through the Elasticsearch console i  
> get fewer records. The Elastic search version is 0.19.2 and same is the  
> version of the Jar being used. Has anyone faced this situation before?
> 
> {  
> "from" : 0,  
> "size" : 2,  
> "query" : {  
> "filtered" : {  
> "query" : {"match\_all" : {}}  
> ,"filter" : {  
> "and" : {  
> "filters" :  
> [ {  
> "exists" : {"field" : "id"}}  
> , {"range" : {"startDate" : {"from" : null,"to" :  
> "2013-02-20","include\_lower" : true,"include\_upper" : true}}}  
> , {"term" : {"completed" : "true"}}, {"term" : {"active" :  
> "true"}}, {"term" : {"traded" : "false"}}, {"term" : {"working" :  
> "false"}}, {"term" : {"secondhand" : "false"}  
> } ]  
> }  
> }  
> }  
> },  
> "fields" : ["name", "price", "marketprice", "id"],  
> "sort" : [{"id" : {"order" : "asc"}}]  
> }
> 
> Thanks,  
> John

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [February 20, 2013, 11:16pm UTC](https://discuss.elastic.co/t/running-the-same-es-query-through-the-java-api-and-the-es-console-gives-different-number-of-results/10827/3 "2013-02-20T23:16:36Z")

</div>

Can you gist your Java code somewhere (or post it)?

Jörg

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)\
**Post date:** [February 21, 2013, 4:14pm UTC](https://discuss.elastic.co/t/running-the-same-es-query-through-the-java-api-and-the-es-console-gives-different-number-of-results/10827/4 "2013-02-21T16:14:02Z")

</div>

This is essentially how i'm writing that code to run the Java API Query.

Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name",  
"XXXXXXXX").put("client.transport.sniff", true).put("node.client", true)  
.put("client.transport.ping\_timeout","10s").build();  
Client client = new TransportClient(settings).addTransportAddress(new  
InetSocketTransportAddress("10.16.150.100", 9300));  
QueryBuilder queryBuilderObj = boolQuery().must(termQuery("XXXX", "YYYY"));  
SearchRequestBuilder srb = client.prepareSearch("XXXXX")  
.setSearchType(DFS\_QUERY\_THEN\_FETCH).setQuery(queryBuilderObj)  
.addField("price").addField("id").setFrom(0).setSize(3).setExplain(true);  
SearchResponse response = srb.execute().actionGet();

On Wednesday, 20 February 2013 17:16:36 UTC-6, Jörg Prante wrote:

> Can you gist your Java code somewhere (or post it)?
> 
> Jörg

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [February 21, 2013, 4:20pm UTC](https://discuss.elastic.co/t/running-the-same-es-query-through-the-java-api-and-the-es-console-gives-different-number-of-results/10827/5 "2013-02-21T16:20:32Z")

</div>

This is not the same query at all.  
What could be nice is to sysout your query using srb.string() or toString() and run exactly this query with curl.

You should have same results.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 21 févr. 2013 à 17:14, john [john2roll2@gmail.com](mailto:john2roll2@gmail.com) a écrit :

> This is essentially how i'm writing that code to run the Java API Query.
> 
> Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "XXXXXXXX").put("client.transport.sniff", true).put("node.client", true).put("client.transport.ping\_timeout","10s").build();  
> Client client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("10.16.150.100", 9300));  
> QueryBuilder queryBuilderObj = boolQuery().must(termQuery("XXXX", "YYYY"));  
> SearchRequestBuilder srb = client.prepareSearch("XXXXX").setSearchType(DFS\_QUERY\_THEN\_FETCH).setQuery(queryBuilderObj) .addField("price").addField("id").setFrom(0).setSize(3).setExplain(true);  
> SearchResponse response = srb.execute().actionGet();
> 
> On Wednesday, 20 February 2013 17:16:36 UTC-6, Jörg Prante wrote:  
> Can you gist your Java code somewhere (or post it)?
> 
> Jörg
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)\
**Post date:** [February 21, 2013, 4:34pm UTC](https://discuss.elastic.co/t/running-the-same-es-query-through-the-java-api-and-the-es-console-gives-different-number-of-results/10827/6 "2013-02-21T16:34:43Z")

</div>

David,

i did not provide the exact query building code as i thought probably Jörg  
wanted to know how i'm running the query. The query that initally posted  
was taken after a toString() on the searchRequestBuilder.  
Will try to run the same query using curl.

On Thursday, 21 February 2013 10:20:32 UTC-6, David Pilato wrote:

> This is not the same query at all.  
> What could be nice is to sysout your query using srb.string() or  
> toString() and run exactly this query with curl.
> 
> You should have same results.
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 21 févr. 2013 à 17:14, john \<[john2...@gmail.com](mailto:john2...@gmail.com) \<javascript:\>\> a écrit  
> :
> 
> This is essentially how i'm writing that code to run the Java API Query.
> 
> Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name",  
> "XXXXXXXX").put("client.transport.sniff", true).put("node.client", true)  
> .put("client.transport.ping\_timeout","10s").build();  
> Client client = new TransportClient(settings).addTransportAddress(new  
> InetSocketTransportAddress("10.16.150.100", 9300));  
> QueryBuilder queryBuilderObj = boolQuery().must(termQuery("XXXX", "YYYY"));  
> SearchRequestBuilder srb = client.prepareSearch("XXXXX")  
> .setSearchType(DFS\_QUERY\_THEN\_FETCH).setQuery(queryBuilderObj)  
> .addField("price").addField("id").setFrom(0).setSize(3).setExplain(true);  
> SearchResponse response = srb.execute().actionGet();
> 
> On Wednesday, 20 February 2013 17:16:36 UTC-6, Jörg Prante wrote:
> 
> > Can you gist your Java code somewhere (or post it)?
> > 
> > Jörg
> 
> --  
> 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:\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)\
**Post date:** [February 21, 2013, 7:42pm UTC](https://discuss.elastic.co/t/running-the-same-es-query-through-the-java-api-and-the-es-console-gives-different-number-of-results/10827/7 "2013-02-21T19:42:59Z")

</div>

I tried running the same query using curl (on the elastic Search) and got  
the same number of records as requested.

On Thursday, 21 February 2013 10:34:43 UTC-6, john wrote:

> David,
> 
> i did not provide the exact query building code as i thought probably Jörg  
> wanted to know how i'm running the query. The query that initally posted  
> was taken after a toString() on the searchRequestBuilder.  
> Will try to run the same query using curl.
> 
> On Thursday, 21 February 2013 10:20:32 UTC-6, David Pilato wrote:
> 
> > This is not the same query at all.  
> > What could be nice is to sysout your query using srb.string() or  
> > toString() and run exactly this query with curl.
> > 
> > You should have same results.
> > 
> > --  
> > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > 
> > Le 21 févr. 2013 à 17:14, john [john2...@gmail.com](mailto:john2...@gmail.com) a écrit :
> > 
> > This is essentially how i'm writing that code to run the Java API Query.
> > 
> > Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name",  
> > "XXXXXXXX").put("client.transport.sniff", true).put("node.client", true)  
> > .put("client.transport.ping\_timeout","10s").build();  
> > Client client = new TransportClient(settings).addTransportAddress(new  
> > InetSocketTransportAddress("10.16.150.100", 9300));  
> > QueryBuilder queryBuilderObj = boolQuery().must(termQuery("XXXX",  
> > "YYYY"));  
> > SearchRequestBuilder srb = client.prepareSearch("XXXXX")  
> > .setSearchType(DFS\_QUERY\_THEN\_FETCH).setQuery(queryBuilderObj)  
> > .addField("price").addField("id").setFrom(0).setSize(3).setExplain(true);  
> > SearchResponse response = srb.execute().actionGet();
> > 
> > On Wednesday, 20 February 2013 17:16:36 UTC-6, Jörg Prante wrote:
> > 
> > > Can you gist your Java code somewhere (or post it)?
> > > 
> > > Jörg
> > 
> > --  
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)\
**Post date:** [February 22, 2013, 6:54pm UTC](https://discuss.elastic.co/t/running-the-same-es-query-through-the-java-api-and-the-es-console-gives-different-number-of-results/10827/8 "2013-02-22T18:54:36Z")

</div>

So both the Elasticsearch console and curl are returning me the same  
number of records as requested, but the java API returns me almost double  
the requested number

On Thursday, 21 February 2013 13:42:59 UTC-6, john wrote:

> I tried running the same query using curl (on the elastic Search) and got  
> the same number of records as requested.
> 
> On Thursday, 21 February 2013 10:34:43 UTC-6, john wrote:
> 
> > David,
> > 
> > i did not provide the exact query building code as i thought  
> > probably Jörg wanted to know how i'm running the query. The query that  
> > initally posted was taken after a toString() on the searchRequestBuilder.  
> > Will try to run the same query using curl.
> > 
> > On Thursday, 21 February 2013 10:20:32 UTC-6, David Pilato wrote:
> > 
> > > This is not the same query at all.  
> > > What could be nice is to sysout your query using srb.string() or  
> > > toString() and run exactly this query with curl.
> > > 
> > > You should have same results.
> > > 
> > > --  
> > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > > 
> > > Le 21 févr. 2013 à 17:14, john [john2...@gmail.com](mailto:john2...@gmail.com) a écrit :
> > > 
> > > This is essentially how i'm writing that code to run the Java API Query.
> > > 
> > > Settings settings = ImmutableSettings.settingsBuilder().put("  
> > > cluster.name", "XXXXXXXX").put("client.transport.sniff", true).put("node.client",  
> > > true).put("client.transport.ping\_timeout","10s").build();  
> > > Client client = new TransportClient(settings).addTransportAddress(new  
> > > InetSocketTransportAddress("10.16.150.100", 9300));  
> > > QueryBuilder queryBuilderObj = boolQuery().must(termQuery("XXXX",  
> > > "YYYY"));  
> > > SearchRequestBuilder srb = client.prepareSearch("XXXXX")  
> > > .setSearchType(DFS\_QUERY\_THEN\_FETCH).setQuery(queryBuilderObj)  
> > > .addField("price").addField("id")  
> > > .setFrom(0).setSize(3).setExplain(true);  
> > > SearchResponse response = srb.execute().actionGet();
> > > 
> > > On Wednesday, 20 February 2013 17:16:36 UTC-6, Jörg Prante wrote:
> > > 
> > > > Can you gist your Java code somewhere (or post it)?
> > > > 
> > > > Jörg
> > > 
> > > --  
> > > 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).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)\
**Post date:** [February 22, 2013, 7:25pm UTC](https://discuss.elastic.co/t/running-the-same-es-query-through-the-java-api-and-the-es-console-gives-different-number-of-results/10827/9 "2013-02-22T19:25:04Z")

</div>

So i figured out whats causing those extra number of records. The query is  
run on all the shards and the users get to see the records returned from  
each of those shards hence those extra set of records.  
Now i'm trying to figure out whats the cause for that.

On Friday, 22 February 2013 12:54:36 UTC-6, john wrote:

> So both the Elasticsearch console and curl are returning me the same  
> number of records as requested, but the java API returns me almost double  
> the requested number
> 
> On Thursday, 21 February 2013 13:42:59 UTC-6, john wrote:
> 
> > I tried running the same query using curl (on the elastic Search) and got  
> > the same number of records as requested.
> > 
> > On Thursday, 21 February 2013 10:34:43 UTC-6, john wrote:
> > 
> > > David,
> > > 
> > > i did not provide the exact query building code as i thought  
> > > probably Jörg wanted to know how i'm running the query. The query that  
> > > initally posted was taken after a toString() on the searchRequestBuilder.  
> > > Will try to run the same query using curl.
> > > 
> > > On Thursday, 21 February 2013 10:20:32 UTC-6, David Pilato wrote:
> > > 
> > > > This is not the same query at all.  
> > > > What could be nice is to sysout your query using srb.string() or  
> > > > toString() and run exactly this query with curl.
> > > > 
> > > > You should have same results.
> > > > 
> > > > --  
> > > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > > > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > > > 
> > > > Le 21 févr. 2013 à 17:14, john [john2...@gmail.com](mailto:john2...@gmail.com) a écrit :
> > > > 
> > > > This is essentially how i'm writing that code to run the Java API Query.
> > > > 
> > > > Settings settings = ImmutableSettings.settingsBuilder().put("  
> > > > cluster.name", "XXXXXXXX").put("client.transport.sniff", true).put("node.client",  
> > > > true).put("client.transport.ping\_timeout","10s").build();  
> > > > Client client = new TransportClient(settings).addTransportAddress(new  
> > > > InetSocketTransportAddress("10.16.150.100", 9300));  
> > > > QueryBuilder queryBuilderObj = boolQuery().must(termQuery("XXXX",  
> > > > "YYYY"));  
> > > > SearchRequestBuilder srb = client.prepareSearch("XXXXX")  
> > > > .setSearchType(DFS\_QUERY\_THEN\_FETCH).setQuery(queryBuilderObj)  
> > > > .addField("price").addField("id")  
> > > > .setFrom(0).setSize(3).setExplain(true);  
> > > > SearchResponse response = srb.execute().actionGet();
> > > > 
> > > > On Wednesday, 20 February 2013 17:16:36 UTC-6, Jörg Prante wrote:
> > > > 
> > > > > Can you gist your Java code somewhere (or post it)?
> > > > > 
> > > > > Jörg
> > > > 
> > > > --  
> > > > 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).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)\
**Post date:** [February 22, 2013, 8:27pm UTC](https://discuss.elastic.co/t/running-the-same-es-query-through-the-java-api-and-the-es-console-gives-different-number-of-results/10827/10 "2013-02-22T20:27:53Z")

</div>

This issue was resolved in this below post

[https://groups.google.com/d/topic/elasticsearch/rZdPLltx-Sg/discussion](https://groups.google.com/d/topic/elasticsearch/rZdPLltx-Sg/discussion)

thanks,  
john

On Friday, 22 February 2013 13:25:04 UTC-6, john wrote:

> So i figured out whats causing those extra number of records. The query is  
> run on all the shards and the users get to see the records returned from  
> each of those shards hence those extra set of records.  
> Now i'm trying to figure out whats the cause for that.
> 
> On Friday, 22 February 2013 12:54:36 UTC-6, john wrote:
> 
> > So both the Elasticsearch console and curl are returning me the same  
> > number of records as requested, but the java API returns me almost double  
> > the requested number
> > 
> > On Thursday, 21 February 2013 13:42:59 UTC-6, john wrote:
> > 
> > > I tried running the same query using curl (on the elastic Search) and  
> > > got the same number of records as requested.
> > > 
> > > On Thursday, 21 February 2013 10:34:43 UTC-6, john wrote:
> > > 
> > > > David,
> > > > 
> > > > i did not provide the exact query building code as i thought  
> > > > probably Jörg wanted to know how i'm running the query. The query that  
> > > > initally posted was taken after a toString() on the searchRequestBuilder.  
> > > > Will try to run the same query using curl.
> > > > 
> > > > On Thursday, 21 February 2013 10:20:32 UTC-6, David Pilato wrote:
> > > > 
> > > > > This is not the same query at all.  
> > > > > What could be nice is to sysout your query using srb.string() or  
> > > > > toString() and run exactly this query with curl.
> > > > > 
> > > > > You should have same results.
> > > > > 
> > > > > --  
> > > > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > > > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > > > > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > > > > 
> > > > > Le 21 févr. 2013 à 17:14, john [john2...@gmail.com](mailto:john2...@gmail.com) a écrit :
> > > > > 
> > > > > This is essentially how i'm writing that code to run the Java API  
> > > > > Query.
> > > > > 
> > > > > Settings settings = ImmutableSettings.settingsBuilder().put("  
> > > > > cluster.name", "XXXXXXXX").put("client.transport.sniff", true).put("node.client",  
> > > > > true).put("client.transport.ping\_timeout","10s").build();  
> > > > > Client client = new TransportClient(settings).addTransportAddress(new  
> > > > > InetSocketTransportAddress("10.16.150.100", 9300));  
> > > > > QueryBuilder queryBuilderObj = boolQuery().must(termQuery("XXXX",  
> > > > > "YYYY"));  
> > > > > SearchRequestBuilder srb = client.prepareSearch("XXXXX")  
> > > > > .setSearchType(DFS\_QUERY\_THEN\_FETCH).setQuery(queryBuilderObj)  
> > > > > .addField("price").addField("id")  
> > > > > .setFrom(0).setSize(3).setExplain(true);  
> > > > > SearchResponse response = srb.execute().actionGet();
> > > > > 
> > > > > On Wednesday, 20 February 2013 17:16:36 UTC-6, Jörg Prante wrote:
> > > > > 
> > > > > > Can you gist your Java code somewhere (or post it)?
> > > > > > 
> > > > > > Jörg
> > > > > 
> > > > > --  
> > > > > 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).  
> > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:49am UTC](https://discuss.elastic.co/t/running-the-same-es-query-through-the-java-api-and-the-es-console-gives-different-number-of-results/10827/11 "2017-07-06T02:49:57Z")

</div>


