# Wrong paging with embedded es instance

**URL:** https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955
**Category:** Elasticsearch
**Created:** [June 6, 2014, 2:47pm UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955 "2014-06-06T14:47:57Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![dkiselev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkiselev/32/1511_2.png) [@dkiselev](https://discuss.elastic.co/u/dkiselev)
#### Post date: [June 6, 2014, 2:47pm UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955/1 "2014-06-06T14:47:57Z")

</div>

Hi everyone.

I use embedded ES node as part of java application.

Node node = nodeBuilder().clusterName("OSM-Gazetteer").node();  
Client client = node.client();

I try to fetch some data paged.

SearchRequestBuilder searchQ = client.prepareSearch("gazetteer")  
.setSearchType(SearchType.QUERY\_AND\_FETCH)  
.setNoFields()  
.setQuery(QueryBuilders.matchAllQuery())  
.setExplain(false);

```
    searchQ.setSize(PAGE_SIZE); //PAGE_SIZE=5;        
    searchQ.setFrom(page * PAGE_SIZE); //page=0;

```

Here is the querry what I've got generated by client:

{ "from" : 0, "size" : 5, "query" : { "match\_all" : { } },  
"explain" : false, "fields" : [] }

curl version returns 5 hits, as expected, but java returns 20 hits:

searchQ.get().getHits().getHits().length; //=\>20

Index setting are default. Hits do not have duplicates.

Is there some workaround or something?

--  
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/647bddb1-636f-4670-9f9a-b0767001fdd8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/647bddb1-636f-4670-9f9a-b0767001fdd8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [June 6, 2014, 3:38pm UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955/2 "2014-06-06T15:38:09Z")

</div>

Could you print your searchQ object?

May be using a toString()

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

> Le 6 juin 2014 à 16:47, Дмитрий Киселев [dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com) a écrit :
> 
> Hi everyone.
> 
> I use embedded ES node as part of java application.
> 
> Node node = nodeBuilder().clusterName("OSM-Gazetteer").node();  
> Client client = node.client();
> 
> I try to fetch some data paged.
> 
> SearchRequestBuilder searchQ = client.prepareSearch("gazetteer")  
> .setSearchType(SearchType.QUERY\_AND\_FETCH)  
> .setNoFields()  
> .setQuery(QueryBuilders.matchAllQuery())  
> .setExplain(false);
> 
> ```
> searchQ.setSize(PAGE_SIZE); //PAGE_SIZE=5;        
> searchQ.setFrom(page * PAGE_SIZE); //page=0;
> 
> ```
> 
> Here is the querry what I've got generated by client:
> 
> { "from" : 0, "size" : 5, "query" : { "match\_all" : { } }, "explain" : false, "fields" : }
> 
> curl version returns 5 hits, as expected, but java returns 20 hits:
> 
> searchQ.get().getHits().getHits().length; //=\>20
> 
> Index setting are default. Hits do not have duplicates.
> 
> ## Is there some workaround or something?
> 
> 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/647bddb1-636f-4670-9f9a-b0767001fdd8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/647bddb1-636f-4670-9f9a-b0767001fdd8%40googlegroups.com).  
> 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/BEFCD925-5450-4DAC-A121-EAC6EB928371%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/BEFCD925-5450-4DAC-A121-EAC6EB928371%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![dkiselev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkiselev/32/1511_2.png) [@dkiselev](https://discuss.elastic.co/u/dkiselev)
#### Post date: [June 6, 2014, 5:23pm UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955/3 "2014-06-06T17:23:41Z")

</div>

Yep.

System.out.println(searchQ.toString());

{  
"from" : 0,  
"size" : 5,  
"query" : {  
"match\_all" : { }  
},  
"explain" : false,  
"fields" : []  
}

Also, I think it's might be connected with sharding.  
I've tried to change number\_of\_shards to 1 and paging starts act as I  
expect.

Set number\_of\_shards to 5 and get 25 hits.  
Set number\_of\_shards to 4 and get 20 hits.

It's seems like from and size applied to every shard separately in my case.

--  
Thank you for your time. Best regards.  
Dmitry.

--  
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/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [June 6, 2014, 5:40pm UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955/4 "2014-06-06T17:40:19Z")

</div>

Can you print also the full response object (toString()) as well?

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

Le 6 juin 2014 à 19:24:00, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com)) a écrit:

Yep.

System.out.println(searchQ.toString());

{  
"from" : 0,  
"size" : 5,  
"query" : {  
"match\_all" : { }  
},  
"explain" : false,  
"fields" : []  
}

Also, I think it's might be connected with sharding.  
I've tried to change number\_of\_shards to 1 and paging starts act as I expect.

Set number\_of\_shards to 5 and get 25 hits.  
Set number\_of\_shards to 4 and get 20 hits.

It's seems like from and size applied to every shard separately in my case.

## -- Thank you for your time. Best regards. Dmitry.

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/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com).  
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/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![dkiselev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkiselev/32/1511_2.png) [@dkiselev](https://discuss.elastic.co/u/dkiselev)
#### Post date: [June 6, 2014, 5:49pm UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955/5 "2014-06-06T17:49:27Z")

</div>

This is with 5 shards.  
{  
"took" : 81,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 3879,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0016087997-w162848733-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0088827105-n2270743905-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0097856729-n2270743903-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0145983393-w154644839-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0209772668-n1884206099-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0015203925-w147150792-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0017569140-n2495059507-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0071389729-w147150672-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0130455978-w145925771-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0139624280-w147150701-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0079711118-w194531715-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0096243499-w194531714-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0162691059-w164700540-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0202220208-w164698447-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0287053820-n2270743890-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0013765594-w145949343-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0026389358-w147150656-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0093401200-w162848869-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0203517601-n2270743895-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0217217459-n2270743898-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0004074128-w145925740-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0007815983-w175372179-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0039697750-w164700428-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0053473990-w271448695-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0129549665-w162848862-regular",  
"\_score" : 1.0  
} ]  
}  
}

And this is with one shard  
{  
"took" : 123,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 656523,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0675290941-w116699544-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0675314442-n1557245109-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0675335611-w210502362-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0675352866-w245359553-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0675354643-w235622232-regular",  
"\_score" : 1.0  
} ]  
}  
}

2014-06-06 19:40 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):

> Can you print also the full response object (toString()) as well?
> 
> --  
> _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)
> 
> Le 6 juin 2014 à 19:24:00, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com)) a  
> écrit:
> 
> Yep.
> 
> System.out.println(searchQ.toString());
> 
> {  
> "from" : 0,  
> "size" : 5,  
> "query" : {  
> "match\_all" : { }  
> },  
> "explain" : false,  
> "fields" :   
> }
> 
> Also, I think it's might be connected with sharding.  
> I've tried to change number\_of\_shards to 1 and paging starts act as I  
> expect.
> 
> Set number\_of\_shards to 5 and get 25 hits.  
> Set number\_of\_shards to 4 and get 20 hits.
> 
> It's seems like from and size applied to every shard separately in my case.
> 
> ## -- Thank you for your time. Best regards. Dmitry.
> 
> 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/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.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 a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> To unsubscribe from this group and all its topics, 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/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local)  
> [https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Thank you for your time. Best regards.  
Dmitry.

--  
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/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [June 6, 2014, 5:54pm UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955/6 "2014-06-06T17:54:54Z")

</div>

The total hit number is really inconsistent:

With one shard you get: 656523  
With 5 shards you get: 3879

I think you are doing something wrong but I can't tell more without looking at the full source code.  
Could you share how you actually execute the query?

Are you sure your Java client is connected to the right instance/cluster?

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

Le 6 juin 2014 à 19:49:47, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com)) a écrit:

This is with 5 shards.  
{  
"took" : 81,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 3879,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0016087997-w162848733-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0088827105-n2270743905-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0097856729-n2270743903-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0145983393-w154644839-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0209772668-n1884206099-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0015203925-w147150792-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0017569140-n2495059507-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0071389729-w147150672-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0130455978-w145925771-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0139624280-w147150701-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0079711118-w194531715-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0096243499-w194531714-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0162691059-w164700540-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0202220208-w164698447-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0287053820-n2270743890-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0013765594-w145949343-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0026389358-w147150656-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0093401200-w162848869-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0203517601-n2270743895-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0217217459-n2270743898-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0004074128-w145925740-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0007815983-w175372179-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0039697750-w164700428-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0053473990-w271448695-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0129549665-w162848862-regular",  
"\_score" : 1.0  
} ]  
}  
}

And this is with one shard  
{  
"took" : 123,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 656523,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0675290941-w116699544-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0675314442-n1557245109-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0675335611-w210502362-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0675352866-w245359553-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0675354643-w235622232-regular",  
"\_score" : 1.0  
} ]  
}  
}

2014-06-06 19:40 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):  
Can you print also the full response object (toString()) as well?

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

Le 6 juin 2014 à 19:24:00, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com)) a écrit:

Yep.

System.out.println(searchQ.toString());

{  
"from" : 0,  
"size" : 5,  
"query" : {  
"match\_all" : { }  
},  
"explain" : false,  
"fields" : []  
}

Also, I think it's might be connected with sharding.  
I've tried to change number\_of\_shards to 1 and paging starts act as I expect.

Set number\_of\_shards to 5 and get 25 hits.  
Set number\_of\_shards to 4 and get 20 hits.

It's seems like from and size applied to every shard separately in my case.

## -- Thank you for your time. Best regards. Dmitry.

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/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com).

## 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 a topic in the Google Groups "elasticsearch" group.  
To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
To unsubscribe from this group and all its topics, 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/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local).

For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

## -- Thank you for your time. Best regards. Dmitry.

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/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com).  
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/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![dkiselev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkiselev/32/1511_2.png) [@dkiselev](https://discuss.elastic.co/u/dkiselev)
#### Post date: [June 6, 2014, 6:02pm UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955/7 "2014-06-06T18:02:14Z")

</div>

Sorry, there littlebit different dataset.  
Here is answer with same data and 1 shard  
{  
"took" : 63,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 3879,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0004074128-w145925740-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0007815983-w175372179-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0013765594-w145949343-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0015203925-w147150792-regular",  
"\_score" : 1.0  
}, {  
"\_index" : "gazetteer",  
"\_type" : "location",  
"\_id" : "adrpnt-0016087997-w162848733-regular",  
"\_score" : 1.0  
} ]  
}  
}

2014-06-06 19:54 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):

> The total hit number is really inconsistent:
> 
> With one shard you get: 656523  
> With 5 shards you get: 3879
> 
> I think you are doing something wrong but I can't tell more without  
> looking at the full source code.  
> Could you share how you actually execute the query?
> 
> Are you sure your Java client is connected to the right instance/cluster?
> 
> --  
> _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)
> 
> Le 6 juin 2014 à 19:49:47, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com)) a  
> écrit:
> 
> This is with 5 shards.  
> {  
> "took" : 81,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 3879,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0016087997-w162848733-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0088827105-n2270743905-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0097856729-n2270743903-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0145983393-w154644839-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0209772668-n1884206099-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0015203925-w147150792-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0017569140-n2495059507-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0071389729-w147150672-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0130455978-w145925771-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0139624280-w147150701-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0079711118-w194531715-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0096243499-w194531714-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0162691059-w164700540-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0202220208-w164698447-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0287053820-n2270743890-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0013765594-w145949343-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0026389358-w147150656-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0093401200-w162848869-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0203517601-n2270743895-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0217217459-n2270743898-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0004074128-w145925740-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0007815983-w175372179-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0039697750-w164700428-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0053473990-w271448695-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0129549665-w162848862-regular",  
> "\_score" : 1.0  
> } ]  
> }  
> }
> 
> And this is with one shard  
> {  
> "took" : 123,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 656523,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0675290941-w116699544-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0675314442-n1557245109-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0675335611-w210502362-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0675352866-w245359553-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0675354643-w235622232-regular",  
> "\_score" : 1.0  
> } ]  
> }  
> }
> 
> 2014-06-06 19:40 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> 
> > Can you print also the full response object (toString()) as well?
> > 
> > ```
> > --
> > 
> > ```
> > 
> > _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)
> > 
> > Le 6 juin 2014 à 19:24:00, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com))  
> > a écrit:
> > 
> > Yep.
> > 
> > System.out.println(searchQ.toString());
> > 
> > {  
> > "from" : 0,  
> > "size" : 5,  
> > "query" : {  
> > "match\_all" : { }  
> > },  
> > "explain" : false,  
> > "fields" :   
> > }
> > 
> > Also, I think it's might be connected with sharding.  
> > I've tried to change number\_of\_shards to 1 and paging starts act as I  
> > expect.
> > 
> > Set number\_of\_shards to 5 and get 25 hits.  
> > Set number\_of\_shards to 4 and get 20 hits.
> > 
> > It's seems like from and size applied to every shard separately in my  
> > case.
> > 
> > ## -- Thank you for your time. Best regards. Dmitry.
> > 
> > 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/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.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 a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local)  
> > [https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer).
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> ## -- Thank you for your time. Best regards. Dmitry.
> 
> 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/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.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 a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> To unsubscribe from this group and all its topics, 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/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local)  
> [https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Thank you for your time. Best regards.  
Dmitry.

--  
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/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa\_UG3qQEH5CH1A0gDg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa_UG3qQEH5CH1A0gDg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [June 6, 2014, 6:20pm UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955/8 "2014-06-06T18:20:05Z")

</div>

So? What's wrong here?

You asked for 5 docs and you get 5.

I'm missing something I guess.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

> Le 6 juin 2014 à 20:02, Дмитрий Киселев [dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com) a écrit :
> 
> Sorry, there littlebit different dataset.  
> Here is answer with same data and 1 shard  
> {  
> "took" : 63,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 3879,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0004074128-w145925740-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0007815983-w175372179-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0013765594-w145949343-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0015203925-w147150792-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0016087997-w162848733-regular",  
> "\_score" : 1.0  
> } ]  
> }  
> }
> 
> 2014-06-06 19:54 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> 
> > The total hit number is really inconsistent:
> > 
> > With one shard you get: 656523  
> > With 5 shards you get: 3879
> > 
> > I think you are doing something wrong but I can't tell more without looking at the full source code.  
> > Could you share how you actually execute the query?
> > 
> > Are you sure your Java client is connected to the right instance/cluster?
> > 
> > --  
> > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > @dadoonet | @elasticsearchfr
> > 
> > > Le 6 juin 2014 à 19:49:47, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com)) a écrit:
> > > 
> > > This is with 5 shards.  
> > > {  
> > > "took" : 81,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 5,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 3879,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0016087997-w162848733-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0088827105-n2270743905-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0097856729-n2270743903-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0145983393-w154644839-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0209772668-n1884206099-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0015203925-w147150792-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0017569140-n2495059507-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0071389729-w147150672-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0130455978-w145925771-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0139624280-w147150701-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0079711118-w194531715-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0096243499-w194531714-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0162691059-w164700540-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0202220208-w164698447-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0287053820-n2270743890-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0013765594-w145949343-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0026389358-w147150656-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0093401200-w162848869-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0203517601-n2270743895-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0217217459-n2270743898-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0004074128-w145925740-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0007815983-w175372179-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0039697750-w164700428-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0053473990-w271448695-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0129549665-w162848862-regular",  
> > > "\_score" : 1.0  
> > > } ]  
> > > }  
> > > }
> > > 
> > > And this is with one shard  
> > > {  
> > > "took" : 123,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 1,  
> > > "successful" : 1,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 656523,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0675290941-w116699544-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0675314442-n1557245109-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0675335611-w210502362-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0675352866-w245359553-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0675354643-w235622232-regular",  
> > > "\_score" : 1.0  
> > > } ]  
> > > }  
> > > }
> > > 
> > > 2014-06-06 19:40 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> > > 
> > > > Can you print also the full response object (toString()) as well?
> > > > 
> > > > --  
> > > > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > > > @dadoonet | @elasticsearchfr
> > > > 
> > > > > Le 6 juin 2014 à 19:24:00, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com)) a écrit:
> > > > > 
> > > > > Yep.
> > > > > 
> > > > > System.out.println(searchQ.toString());
> > > > > 
> > > > > {  
> > > > > "from" : 0,  
> > > > > "size" : 5,  
> > > > > "query" : {  
> > > > > "match\_all" : { }  
> > > > > },  
> > > > > "explain" : false,  
> > > > > "fields" :   
> > > > > }
> > > > > 
> > > > > Also, I think it's might be connected with sharding.  
> > > > > I've tried to change number\_of\_shards to 1 and paging starts act as I expect.
> > > > > 
> > > > > Set number\_of\_shards to 5 and get 25 hits.  
> > > > > Set number\_of\_shards to 4 and get 20 hits.
> > > > > 
> > > > > It's seems like from and size applied to every shard separately in my case.
> > > > > 
> > > > > ## -- Thank you for your time. Best regards. Dmitry.
> > > > > 
> > > > > 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/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com).
> > > > > 
> > > > > 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 a topic in the Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> > > > To unsubscribe from this group and all its topics, 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/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local).
> > > > 
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > ## -- Thank you for your time. Best regards. Dmitry.
> > > 
> > > 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/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com).
> > > 
> > > 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 a topic in the Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local).
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> ## -- Thank you for your time. Best regards. Dmitry.
> 
> 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/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa\_UG3qQEH5CH1A0gDg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa_UG3qQEH5CH1A0gDg%40mail.gmail.com).  
> 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/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![dkiselev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkiselev/32/1511_2.png) [@dkiselev](https://discuss.elastic.co/u/dkiselev)
#### Post date: [June 6, 2014, 6:26pm UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955/9 "2014-06-06T18:26:10Z")

</div>

I asked for 5 docs.

With 1 shard - I got 5 docs.  
With 5 shards - I got 25 docs.  
With 5 shards, using curl instead of embedded java client - I got 5 docs.

2014-06-06 20:20 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):

> So? What's wrong here?
> 
> You asked for 5 docs and you get 5.
> 
> I'm missing something I guess.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 6 juin 2014 à 20:02, Дмитрий Киселев [dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com) a  
> écrit :
> 
> Sorry, there littlebit different dataset.  
> Here is answer with same data and 1 shard  
> {  
> "took" : 63,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 3879,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0004074128-w145925740-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0007815983-w175372179-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0013765594-w145949343-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0015203925-w147150792-regular",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "gazetteer",  
> "\_type" : "location",  
> "\_id" : "adrpnt-0016087997-w162848733-regular",  
> "\_score" : 1.0  
> } ]  
> }  
> }
> 
> 2014-06-06 19:54 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> 
> > The total hit number is really inconsistent:
> > 
> > With one shard you get: 656523  
> > With 5 shards you get: 3879
> > 
> > I think you are doing something wrong but I can't tell more without  
> > looking at the full source code.  
> > Could you share how you actually execute the query?
> > 
> > Are you sure your Java client is connected to the right instance/cluster?
> > 
> > --  
> > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> > [http://Elasticsearch.com](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > 
> > Le 6 juin 2014 à 19:49:47, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com))  
> > a écrit:
> > 
> > This is with 5 shards.  
> > {  
> > "took" : 81,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 3879,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0016087997-w162848733-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0088827105-n2270743905-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0097856729-n2270743903-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0145983393-w154644839-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0209772668-n1884206099-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0015203925-w147150792-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0017569140-n2495059507-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0071389729-w147150672-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0130455978-w145925771-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0139624280-w147150701-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0079711118-w194531715-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0096243499-w194531714-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0162691059-w164700540-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0202220208-w164698447-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0287053820-n2270743890-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0013765594-w145949343-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0026389358-w147150656-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0093401200-w162848869-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0203517601-n2270743895-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0217217459-n2270743898-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0004074128-w145925740-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0007815983-w175372179-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0039697750-w164700428-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0053473990-w271448695-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0129549665-w162848862-regular",  
> > "\_score" : 1.0  
> > } ]  
> > }  
> > }
> > 
> > And this is with one shard  
> > {  
> > "took" : 123,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 1,  
> > "successful" : 1,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 656523,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0675290941-w116699544-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0675314442-n1557245109-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0675335611-w210502362-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0675352866-w245359553-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0675354643-w235622232-regular",  
> > "\_score" : 1.0  
> > } ]  
> > }  
> > }
> > 
> > 2014-06-06 19:40 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> > 
> > > Can you print also the full response object (toString()) as well?
> > > 
> > > ```
> > > --
> > > 
> > > ```
> > > 
> > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> > > [http://Elasticsearch.com](http://Elasticsearch.com)_  
> > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > 
> > > Le 6 juin 2014 à 19:24:00, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com))  
> > > a écrit:
> > > 
> > > Yep.
> > > 
> > > System.out.println(searchQ.toString());
> > > 
> > > {  
> > > "from" : 0,  
> > > "size" : 5,  
> > > "query" : {  
> > > "match\_all" : { }  
> > > },  
> > > "explain" : false,  
> > > "fields" :   
> > > }
> > > 
> > > Also, I think it's might be connected with sharding.  
> > > I've tried to change number\_of\_shards to 1 and paging starts act as I  
> > > expect.
> > > 
> > > Set number\_of\_shards to 5 and get 25 hits.  
> > > Set number\_of\_shards to 4 and get 20 hits.
> > > 
> > > It's seems like from and size applied to every shard separately in my  
> > > case.
> > > 
> > > ## -- Thank you for your time. Best regards. Dmitry.
> > > 
> > > 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/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.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 a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> > > To unsubscribe from this group and all its topics, 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/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local)  
> > > [https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer).
> > > 
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > ## -- Thank you for your time. Best regards. Dmitry.
> > 
> > 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/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.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 a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local)  
> > [https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer)  
> > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Thank you for your time. Best regards.  
> Dmitry.
> 
> --  
> 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/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa\_UG3qQEH5CH1A0gDg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa_UG3qQEH5CH1A0gDg%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa\_UG3qQEH5CH1A0gDg%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa_UG3qQEH5CH1A0gDg%40mail.gmail.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 a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> To unsubscribe from this group and all its topics, 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/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr)  
> [https://groups.google.com/d/msgid/elasticsearch/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Thank you for your time. Best regards.  
Dmitry.

--  
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/CAA9QNxP\_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxP_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [June 6, 2014, 6:53pm UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955/10 "2014-06-06T18:53:20Z")

</div>

Any chance you could share your code. In particular, i'd like to see how you run the query.

If you could reproduce it with a test case that would be awesome.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

> Le 6 juin 2014 à 20:26, Дмитрий Киселев [dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com) a écrit :
> 
> I asked for 5 docs.
> 
> With 1 shard - I got 5 docs.  
> With 5 shards - I got 25 docs.  
> With 5 shards, using curl instead of embedded java client - I got 5 docs.
> 
> 2014-06-06 20:20 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> 
> > So? What's wrong here?
> > 
> > You asked for 5 docs and you get 5.
> > 
> > I'm missing something I guess.
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > > Le 6 juin 2014 à 20:02, Дмитрий Киселев [dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com) a écrit :
> > > 
> > > Sorry, there littlebit different dataset.  
> > > Here is answer with same data and 1 shard  
> > > {  
> > > "took" : 63,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 1,  
> > > "successful" : 1,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 3879,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0004074128-w145925740-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0007815983-w175372179-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0013765594-w145949343-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0015203925-w147150792-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0016087997-w162848733-regular",  
> > > "\_score" : 1.0  
> > > } ]  
> > > }  
> > > }
> > > 
> > > 2014-06-06 19:54 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> > > 
> > > > The total hit number is really inconsistent:
> > > > 
> > > > With one shard you get: 656523  
> > > > With 5 shards you get: 3879
> > > > 
> > > > I think you are doing something wrong but I can't tell more without looking at the full source code.  
> > > > Could you share how you actually execute the query?
> > > > 
> > > > Are you sure your Java client is connected to the right instance/cluster?
> > > > 
> > > > --  
> > > > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > > > @dadoonet | @elasticsearchfr
> > > > 
> > > > > Le 6 juin 2014 à 19:49:47, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com)) a écrit:
> > > > > 
> > > > > This is with 5 shards.  
> > > > > {  
> > > > > "took" : 81,  
> > > > > "timed\_out" : false,  
> > > > > "\_shards" : {  
> > > > > "total" : 5,  
> > > > > "successful" : 5,  
> > > > > "failed" : 0  
> > > > > },  
> > > > > "hits" : {  
> > > > > "total" : 3879,  
> > > > > "max\_score" : 1.0,  
> > > > > "hits" : [ {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0016087997-w162848733-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0088827105-n2270743905-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0097856729-n2270743903-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0145983393-w154644839-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0209772668-n1884206099-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0015203925-w147150792-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0017569140-n2495059507-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0071389729-w147150672-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0130455978-w145925771-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0139624280-w147150701-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0079711118-w194531715-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0096243499-w194531714-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0162691059-w164700540-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0202220208-w164698447-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0287053820-n2270743890-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0013765594-w145949343-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0026389358-w147150656-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0093401200-w162848869-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0203517601-n2270743895-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0217217459-n2270743898-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0004074128-w145925740-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0007815983-w175372179-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0039697750-w164700428-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0053473990-w271448695-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0129549665-w162848862-regular",  
> > > > > "\_score" : 1.0  
> > > > > } ]  
> > > > > }  
> > > > > }
> > > > > 
> > > > > And this is with one shard  
> > > > > {  
> > > > > "took" : 123,  
> > > > > "timed\_out" : false,  
> > > > > "\_shards" : {  
> > > > > "total" : 1,  
> > > > > "successful" : 1,  
> > > > > "failed" : 0  
> > > > > },  
> > > > > "hits" : {  
> > > > > "total" : 656523,  
> > > > > "max\_score" : 1.0,  
> > > > > "hits" : [ {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0675290941-w116699544-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0675314442-n1557245109-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0675335611-w210502362-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0675352866-w245359553-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0675354643-w235622232-regular",  
> > > > > "\_score" : 1.0  
> > > > > } ]  
> > > > > }  
> > > > > }
> > > > > 
> > > > > 2014-06-06 19:40 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> > > > > 
> > > > > > Can you print also the full response object (toString()) as well?
> > > > > > 
> > > > > > --  
> > > > > > David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> > > > > > @dadoonet | @elasticsearchfr
> > > > > > 
> > > > > > > Le 6 juin 2014 à 19:24:00, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com)) a écrit:
> > > > > > > 
> > > > > > > Yep.
> > > > > > > 
> > > > > > > System.out.println(searchQ.toString());
> > > > > > > 
> > > > > > > {  
> > > > > > > "from" : 0,  
> > > > > > > "size" : 5,  
> > > > > > > "query" : {  
> > > > > > > "match\_all" : { }  
> > > > > > > },  
> > > > > > > "explain" : false,  
> > > > > > > "fields" :   
> > > > > > > }
> > > > > > > 
> > > > > > > Also, I think it's might be connected with sharding.  
> > > > > > > I've tried to change number\_of\_shards to 1 and paging starts act as I expect.
> > > > > > > 
> > > > > > > Set number\_of\_shards to 5 and get 25 hits.  
> > > > > > > Set number\_of\_shards to 4 and get 20 hits.
> > > > > > > 
> > > > > > > It's seems like from and size applied to every shard separately in my case.
> > > > > > > 
> > > > > > > ## -- Thank you for your time. Best regards. Dmitry.
> > > > > > > 
> > > > > > > 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/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com).
> > > > > > > 
> > > > > > > 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 a topic in the Google Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> > > > > > To unsubscribe from this group and all its topics, 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/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local).
> > > > > > 
> > > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > > 
> > > > > ## -- Thank you for your time. Best regards. Dmitry.
> > > > > 
> > > > > 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/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com).
> > > > > 
> > > > > 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 a topic in the Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> > > > To unsubscribe from this group and all its topics, 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/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local).
> > > > 
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > ## -- Thank you for your time. Best regards. Dmitry.
> > > 
> > > 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/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa\_UG3qQEH5CH1A0gDg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa_UG3qQEH5CH1A0gDg%40mail.gmail.com).
> > > 
> > > 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 a topic in the Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr).
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> ## -- Thank you for your time. Best regards. Dmitry.
> 
> 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/CAA9QNxP\_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxP_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.com).  
> 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/885EB070-FAAE-408E-BC1D-2BDF7A6DEECF%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/885EB070-FAAE-408E-BC1D-2BDF7A6DEECF%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![dkiselev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkiselev/32/1511_2.png) [@dkiselev](https://discuss.elastic.co/u/dkiselev)
#### Post date: [June 6, 2014, 9:22pm UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955/11 "2014-06-06T21:22:14Z")

</div>

I've made a snippet.

Code

> <https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java>

Test results

> <https://github.com/kiselev-dv/es-test/blob/master/test.log>

First test 1 shard (test.log line 27) - everything ok  
Second test 5 shards (test.log line 86) - error

Search and paging generation

> <https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java#L73>

One more strange thing, search wasn't find anything until I have add small  
delay

> <https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java#L89>

2014-06-06 20:53 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):

> Any chance you could share your code. In particular, i'd like to see how  
> you run the query.
> 
> If you could reproduce it with a test case that would be awesome.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 6 juin 2014 à 20:26, Дмитрий Киселев [dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com) a  
> écrit :
> 
> I asked for 5 docs.
> 
> With 1 shard - I got 5 docs.  
> With 5 shards - I got 25 docs.  
> With 5 shards, using curl instead of embedded java client - I got 5 docs.
> 
> 2014-06-06 20:20 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> 
> > So? What's wrong here?
> > 
> > You asked for 5 docs and you get 5.
> > 
> > I'm missing something I guess.
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 6 juin 2014 à 20:02, Дмитрий Киселев [dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com) a  
> > écrit :
> > 
> > Sorry, there littlebit different dataset.  
> > Here is answer with same data and 1 shard  
> > {  
> > "took" : 63,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 1,  
> > "successful" : 1,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 3879,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0004074128-w145925740-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0007815983-w175372179-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0013765594-w145949343-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0015203925-w147150792-regular",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "gazetteer",  
> > "\_type" : "location",  
> > "\_id" : "adrpnt-0016087997-w162848733-regular",  
> > "\_score" : 1.0  
> > } ]  
> > }  
> > }
> > 
> > 2014-06-06 19:54 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> > 
> > > The total hit number is really inconsistent:
> > > 
> > > With one shard you get: 656523  
> > > With 5 shards you get: 3879
> > > 
> > > I think you are doing something wrong but I can't tell more without  
> > > looking at the full source code.  
> > > Could you share how you actually execute the query?
> > > 
> > > Are you sure your Java client is connected to the right instance/cluster?
> > > 
> > > --  
> > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> > > [http://Elasticsearch.com](http://Elasticsearch.com)_  
> > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > 
> > > Le 6 juin 2014 à 19:49:47, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com))  
> > > a écrit:
> > > 
> > > This is with 5 shards.  
> > > {  
> > > "took" : 81,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 5,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 3879,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0016087997-w162848733-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0088827105-n2270743905-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0097856729-n2270743903-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0145983393-w154644839-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0209772668-n1884206099-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0015203925-w147150792-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0017569140-n2495059507-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0071389729-w147150672-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0130455978-w145925771-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0139624280-w147150701-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0079711118-w194531715-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0096243499-w194531714-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0162691059-w164700540-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0202220208-w164698447-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0287053820-n2270743890-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0013765594-w145949343-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0026389358-w147150656-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0093401200-w162848869-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0203517601-n2270743895-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0217217459-n2270743898-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0004074128-w145925740-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0007815983-w175372179-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0039697750-w164700428-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0053473990-w271448695-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0129549665-w162848862-regular",  
> > > "\_score" : 1.0  
> > > } ]  
> > > }  
> > > }
> > > 
> > > And this is with one shard  
> > > {  
> > > "took" : 123,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 1,  
> > > "successful" : 1,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 656523,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0675290941-w116699544-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0675314442-n1557245109-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0675335611-w210502362-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0675352866-w245359553-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0675354643-w235622232-regular",  
> > > "\_score" : 1.0  
> > > } ]  
> > > }  
> > > }
> > > 
> > > 2014-06-06 19:40 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> > > 
> > > > Can you print also the full response object (toString()) as well?
> > > > 
> > > > ```
> > > > --
> > > > 
> > > > ```
> > > > 
> > > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> > > > [http://Elasticsearch.com](http://Elasticsearch.com)_  
> > > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > > 
> > > > Le 6 juin 2014 à 19:24:00, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com))  
> > > > a écrit:
> > > > 
> > > > Yep.
> > > > 
> > > > System.out.println(searchQ.toString());
> > > > 
> > > > {  
> > > > "from" : 0,  
> > > > "size" : 5,  
> > > > "query" : {  
> > > > "match\_all" : { }  
> > > > },  
> > > > "explain" : false,  
> > > > "fields" :   
> > > > }
> > > > 
> > > > Also, I think it's might be connected with sharding.  
> > > > I've tried to change number\_of\_shards to 1 and paging starts act as I  
> > > > expect.
> > > > 
> > > > Set number\_of\_shards to 5 and get 25 hits.  
> > > > Set number\_of\_shards to 4 and get 20 hits.
> > > > 
> > > > It's seems like from and size applied to every shard separately in my  
> > > > case.
> > > > 
> > > > ## -- Thank you for your time. Best regards. Dmitry.
> > > > 
> > > > 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/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.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 a topic in the  
> > > > Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this topic, visit  
> > > > [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe)  
> > > > .  
> > > > To unsubscribe from this group and all its topics, 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/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer).
> > > > 
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > ## -- Thank you for your time. Best regards. Dmitry.
> > > 
> > > 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/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.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 a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> > > To unsubscribe from this group and all its topics, 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/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local)  
> > > [https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer)  
> > > .
> > > 
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > Thank you for your time. Best regards.  
> > Dmitry.
> > 
> > --  
> > 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/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa\_UG3qQEH5CH1A0gDg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa_UG3qQEH5CH1A0gDg%40mail.gmail.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa\_UG3qQEH5CH1A0gDg%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa_UG3qQEH5CH1A0gDg%40mail.gmail.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 a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr)  
> > [https://groups.google.com/d/msgid/elasticsearch/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr?utm_medium=email&utm_source=footer)  
> > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Thank you for your time. Best regards.  
> Dmitry.
> 
> --  
> 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/CAA9QNxP\_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxP_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxP\_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxP_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.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 a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> To unsubscribe from this group and all its topics, 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/885EB070-FAAE-408E-BC1D-2BDF7A6DEECF%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/885EB070-FAAE-408E-BC1D-2BDF7A6DEECF%40pilato.fr)  
> [https://groups.google.com/d/msgid/elasticsearch/885EB070-FAAE-408E-BC1D-2BDF7A6DEECF%40pilato.fr?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/885EB070-FAAE-408E-BC1D-2BDF7A6DEECF%40pilato.fr?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Thank you for your time. Best regards.  
Dmitry.

--  
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/CAA9QNxPBU2dH1aci6TFLQXRLo0DdcLX%3DtzOW\_uXtKeS3U5UUZw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxPBU2dH1aci6TFLQXRLo0DdcLX%3DtzOW_uXtKeS3U5UUZw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [June 6, 2014, 9:27pm UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955/12 "2014-06-06T21:27:04Z")

</div>

The Java code uses the query\_and\_fetch search type (which is not the  
default), which "returns size times number of shards results back to the  
caller."

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

query\_and\_fetch is somewhat specialized and shouldn't be used in most  
cases. I think there is an option issue to remove it.

--  
Ivan

On Fri, Jun 6, 2014 at 2:22 PM, Дмитрий Киселев [dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com)  
wrote:

> I've made a snippet.
> 
> Code
> 
> [https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java](https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java)
> 
> Test results  
> [https://github.com/kiselev-dv/es-test/blob/master/test.log](https://github.com/kiselev-dv/es-test/blob/master/test.log)  
> First test 1 shard (test.log line 27) - everything ok  
> Second test 5 shards (test.log line 86) - error
> 
> Search and paging generation
> 
> [https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java#L73](https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java#L73)
> 
> One more strange thing, search wasn't find anything until I have add small  
> delay
> 
> [https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java#L89](https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java#L89)
> 
> 2014-06-06 20:53 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> 
> > Any chance you could share your code. In particular, i'd like to see how  
> > you run the query.
> > 
> > If you could reproduce it with a test case that would be awesome.
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 6 juin 2014 à 20:26, Дмитрий Киселев [dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com) a  
> > écrit :
> > 
> > I asked for 5 docs.
> > 
> > With 1 shard - I got 5 docs.  
> > With 5 shards - I got 25 docs.  
> > With 5 shards, using curl instead of embedded java client - I got 5 docs.
> > 
> > 2014-06-06 20:20 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> > 
> > > So? What's wrong here?
> > > 
> > > You asked for 5 docs and you get 5.
> > > 
> > > I'm missing something I guess.
> > > 
> > > --  
> > > David 😉  
> > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > 
> > > Le 6 juin 2014 à 20:02, Дмитрий Киселев [dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com) a  
> > > écrit :
> > > 
> > > Sorry, there littlebit different dataset.  
> > > Here is answer with same data and 1 shard  
> > > {  
> > > "took" : 63,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 1,  
> > > "successful" : 1,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 3879,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0004074128-w145925740-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0007815983-w175372179-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0013765594-w145949343-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0015203925-w147150792-regular",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "gazetteer",  
> > > "\_type" : "location",  
> > > "\_id" : "adrpnt-0016087997-w162848733-regular",  
> > > "\_score" : 1.0  
> > > } ]  
> > > }  
> > > }
> > > 
> > > 2014-06-06 19:54 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> > > 
> > > > The total hit number is really inconsistent:
> > > > 
> > > > With one shard you get: 656523  
> > > > With 5 shards you get: 3879
> > > > 
> > > > I think you are doing something wrong but I can't tell more without  
> > > > looking at the full source code.  
> > > > Could you share how you actually execute the query?
> > > > 
> > > > Are you sure your Java client is connected to the right  
> > > > instance/cluster?
> > > > 
> > > > --  
> > > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> > > > [http://Elasticsearch.com](http://Elasticsearch.com)_  
> > > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > > 
> > > > Le 6 juin 2014 à 19:49:47, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com))  
> > > > a écrit:
> > > > 
> > > > This is with 5 shards.  
> > > > {  
> > > > "took" : 81,  
> > > > "timed\_out" : false,  
> > > > "\_shards" : {  
> > > > "total" : 5,  
> > > > "successful" : 5,  
> > > > "failed" : 0  
> > > > },  
> > > > "hits" : {  
> > > > "total" : 3879,  
> > > > "max\_score" : 1.0,  
> > > > "hits" : [ {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0016087997-w162848733-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0088827105-n2270743905-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0097856729-n2270743903-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0145983393-w154644839-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0209772668-n1884206099-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0015203925-w147150792-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0017569140-n2495059507-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0071389729-w147150672-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0130455978-w145925771-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0139624280-w147150701-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0079711118-w194531715-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0096243499-w194531714-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0162691059-w164700540-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0202220208-w164698447-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0287053820-n2270743890-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0013765594-w145949343-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0026389358-w147150656-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0093401200-w162848869-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0203517601-n2270743895-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0217217459-n2270743898-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0004074128-w145925740-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0007815983-w175372179-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0039697750-w164700428-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0053473990-w271448695-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0129549665-w162848862-regular",  
> > > > "\_score" : 1.0  
> > > > } ]  
> > > > }  
> > > > }
> > > > 
> > > > And this is with one shard  
> > > > {  
> > > > "took" : 123,  
> > > > "timed\_out" : false,  
> > > > "\_shards" : {  
> > > > "total" : 1,  
> > > > "successful" : 1,  
> > > > "failed" : 0  
> > > > },  
> > > > "hits" : {  
> > > > "total" : 656523,  
> > > > "max\_score" : 1.0,  
> > > > "hits" : [ {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0675290941-w116699544-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0675314442-n1557245109-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0675335611-w210502362-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0675352866-w245359553-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0675354643-w235622232-regular",  
> > > > "\_score" : 1.0  
> > > > } ]  
> > > > }  
> > > > }
> > > > 
> > > > 2014-06-06 19:40 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> > > > 
> > > > > Can you print also the full response object (toString()) as well?
> > > > > 
> > > > > ```
> > > > > --
> > > > > 
> > > > > ```
> > > > > 
> > > > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> > > > > [http://Elasticsearch.com](http://Elasticsearch.com)_  
> > > > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > > > 
> > > > > Le 6 juin 2014 à 19:24:00, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com))  
> > > > > a écrit:
> > > > > 
> > > > > Yep.
> > > > > 
> > > > > System.out.println(searchQ.toString());
> > > > > 
> > > > > {  
> > > > > "from" : 0,  
> > > > > "size" : 5,  
> > > > > "query" : {  
> > > > > "match\_all" : { }  
> > > > > },  
> > > > > "explain" : false,  
> > > > > "fields" :   
> > > > > }
> > > > > 
> > > > > Also, I think it's might be connected with sharding.  
> > > > > I've tried to change number\_of\_shards to 1 and paging starts act as I  
> > > > > expect.
> > > > > 
> > > > > Set number\_of\_shards to 5 and get 25 hits.  
> > > > > Set number\_of\_shards to 4 and get 20 hits.
> > > > > 
> > > > > It's seems like from and size applied to every shard separately in my  
> > > > > case.
> > > > > 
> > > > > ## -- Thank you for your time. Best regards. Dmitry.
> > > > > 
> > > > > 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/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com)  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.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 a topic in the  
> > > > > Google Groups "elasticsearch" group.  
> > > > > To unsubscribe from this topic, visit  
> > > > > [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe)  
> > > > > .  
> > > > > To unsubscribe from this group and all its topics, 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/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local)  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer).
> > > > > 
> > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > 
> > > > ## -- Thank you for your time. Best regards. Dmitry.
> > > > 
> > > > 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/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.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 a topic in the  
> > > > Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this topic, visit  
> > > > [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe)  
> > > > .  
> > > > To unsubscribe from this group and all its topics, 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/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer)  
> > > > .
> > > > 
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > Thank you for your time. Best regards.  
> > > Dmitry.
> > > 
> > > --  
> > > 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/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa\_UG3qQEH5CH1A0gDg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa_UG3qQEH5CH1A0gDg%40mail.gmail.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa\_UG3qQEH5CH1A0gDg%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa_UG3qQEH5CH1A0gDg%40mail.gmail.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 a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> > > To unsubscribe from this group and all its topics, 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/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr)  
> > > [https://groups.google.com/d/msgid/elasticsearch/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr?utm_medium=email&utm_source=footer)  
> > > .
> > > 
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > Thank you for your time. Best regards.  
> > Dmitry.
> > 
> > --  
> > 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/CAA9QNxP\_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxP_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxP\_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxP_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.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 a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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/885EB070-FAAE-408E-BC1D-2BDF7A6DEECF%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/885EB070-FAAE-408E-BC1D-2BDF7A6DEECF%40pilato.fr)  
> > [https://groups.google.com/d/msgid/elasticsearch/885EB070-FAAE-408E-BC1D-2BDF7A6DEECF%40pilato.fr?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/885EB070-FAAE-408E-BC1D-2BDF7A6DEECF%40pilato.fr?utm_medium=email&utm_source=footer)  
> > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Thank you for your time. Best regards.  
> Dmitry.
> 
> --  
> 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/CAA9QNxPBU2dH1aci6TFLQXRLo0DdcLX%3DtzOW\_uXtKeS3U5UUZw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxPBU2dH1aci6TFLQXRLo0DdcLX%3DtzOW_uXtKeS3U5UUZw%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxPBU2dH1aci6TFLQXRLo0DdcLX%3DtzOW\_uXtKeS3U5UUZw%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxPBU2dH1aci6TFLQXRLo0DdcLX%3DtzOW_uXtKeS3U5UUZw%40mail.gmail.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/CALY%3DcQCEN%3DqTTnGKucHPQONnV8qp%2BXKukWCvqutsH-Jv5\_18%3Dg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCEN%3DqTTnGKucHPQONnV8qp%2BXKukWCvqutsH-Jv5_18%3Dg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![dkiselev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dkiselev/32/1511_2.png) [@dkiselev](https://discuss.elastic.co/u/dkiselev)
#### Post date: [June 6, 2014, 9:34pm UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955/13 "2014-06-06T21:34:53Z")

</div>

Thank you David, thank you Ivan

My stupid copy & pase from web examples.

2014-06-06 23:27 GMT+02:00 Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com):

> The Java code uses the query\_and\_fetch search type (which is not the  
> default), which "returns size times number of shards results back to the  
> caller."
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-search-type.html#query-and-fetch)
> 
> query\_and\_fetch is somewhat specialized and shouldn't be used in most  
> cases. I think there is an option issue to remove it.
> 
> --  
> Ivan
> 
> On Fri, Jun 6, 2014 at 2:22 PM, Дмитрий Киселев \<  
> [dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com)\> wrote:
> 
> > I've made a snippet.
> > 
> > Code
> > 
> > [https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java](https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java)
> > 
> > Test results  
> > [https://github.com/kiselev-dv/es-test/blob/master/test.log](https://github.com/kiselev-dv/es-test/blob/master/test.log)  
> > First test 1 shard (test.log line 27) - everything ok  
> > Second test 5 shards (test.log line 86) - error
> > 
> > Search and paging generation
> > 
> > [https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java#L73](https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java#L73)
> > 
> > One more strange thing, search wasn't find anything until I have add  
> > small delay
> > 
> > [https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java#L89](https://github.com/kiselev-dv/es-test/blob/master/ESPagingTest/src/main/java/test/ESTest.java#L89)
> > 
> > 2014-06-06 20:53 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> > 
> > > Any chance you could share your code. In particular, i'd like to see how  
> > > you run the query.
> > > 
> > > If you could reproduce it with a test case that would be awesome.
> > > 
> > > --  
> > > David 😉  
> > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > 
> > > Le 6 juin 2014 à 20:26, Дмитрий Киселев [dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com) a  
> > > écrit :
> > > 
> > > I asked for 5 docs.
> > > 
> > > With 1 shard - I got 5 docs.  
> > > With 5 shards - I got 25 docs.  
> > > With 5 shards, using curl instead of embedded java client - I got 5 docs.
> > > 
> > > 2014-06-06 20:20 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> > > 
> > > > So? What's wrong here?
> > > > 
> > > > You asked for 5 docs and you get 5.
> > > > 
> > > > I'm missing something I guess.
> > > > 
> > > > --  
> > > > David 😉  
> > > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > > 
> > > > Le 6 juin 2014 à 20:02, Дмитрий Киселев [dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com) a  
> > > > écrit :
> > > > 
> > > > Sorry, there littlebit different dataset.  
> > > > Here is answer with same data and 1 shard  
> > > > {  
> > > > "took" : 63,  
> > > > "timed\_out" : false,  
> > > > "\_shards" : {  
> > > > "total" : 1,  
> > > > "successful" : 1,  
> > > > "failed" : 0  
> > > > },  
> > > > "hits" : {  
> > > > "total" : 3879,  
> > > > "max\_score" : 1.0,  
> > > > "hits" : [ {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0004074128-w145925740-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0007815983-w175372179-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0013765594-w145949343-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0015203925-w147150792-regular",  
> > > > "\_score" : 1.0  
> > > > }, {  
> > > > "\_index" : "gazetteer",  
> > > > "\_type" : "location",  
> > > > "\_id" : "adrpnt-0016087997-w162848733-regular",  
> > > > "\_score" : 1.0  
> > > > } ]  
> > > > }  
> > > > }
> > > > 
> > > > 2014-06-06 19:54 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> > > > 
> > > > > The total hit number is really inconsistent:
> > > > > 
> > > > > With one shard you get: 656523  
> > > > > With 5 shards you get: 3879
> > > > > 
> > > > > I think you are doing something wrong but I can't tell more without  
> > > > > looking at the full source code.  
> > > > > Could you share how you actually execute the query?
> > > > > 
> > > > > Are you sure your Java client is connected to the right  
> > > > > instance/cluster?
> > > > > 
> > > > > --  
> > > > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> > > > > [http://Elasticsearch.com](http://Elasticsearch.com)_  
> > > > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > > > 
> > > > > Le 6 juin 2014 à 19:49:47, Дмитрий Киселев ([dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com))  
> > > > > a écrit:
> > > > > 
> > > > > This is with 5 shards.  
> > > > > {  
> > > > > "took" : 81,  
> > > > > "timed\_out" : false,  
> > > > > "\_shards" : {  
> > > > > "total" : 5,  
> > > > > "successful" : 5,  
> > > > > "failed" : 0  
> > > > > },  
> > > > > "hits" : {  
> > > > > "total" : 3879,  
> > > > > "max\_score" : 1.0,  
> > > > > "hits" : [ {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0016087997-w162848733-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0088827105-n2270743905-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0097856729-n2270743903-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0145983393-w154644839-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0209772668-n1884206099-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0015203925-w147150792-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0017569140-n2495059507-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0071389729-w147150672-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0130455978-w145925771-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0139624280-w147150701-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0079711118-w194531715-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0096243499-w194531714-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0162691059-w164700540-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0202220208-w164698447-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0287053820-n2270743890-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0013765594-w145949343-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0026389358-w147150656-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0093401200-w162848869-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0203517601-n2270743895-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0217217459-n2270743898-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0004074128-w145925740-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0007815983-w175372179-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0039697750-w164700428-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0053473990-w271448695-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0129549665-w162848862-regular",  
> > > > > "\_score" : 1.0  
> > > > > } ]  
> > > > > }  
> > > > > }
> > > > > 
> > > > > And this is with one shard  
> > > > > {  
> > > > > "took" : 123,  
> > > > > "timed\_out" : false,  
> > > > > "\_shards" : {  
> > > > > "total" : 1,  
> > > > > "successful" : 1,  
> > > > > "failed" : 0  
> > > > > },  
> > > > > "hits" : {  
> > > > > "total" : 656523,  
> > > > > "max\_score" : 1.0,  
> > > > > "hits" : [ {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0675290941-w116699544-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0675314442-n1557245109-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0675335611-w210502362-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0675352866-w245359553-regular",  
> > > > > "\_score" : 1.0  
> > > > > }, {  
> > > > > "\_index" : "gazetteer",  
> > > > > "\_type" : "location",  
> > > > > "\_id" : "adrpnt-0675354643-w235622232-regular",  
> > > > > "\_score" : 1.0  
> > > > > } ]  
> > > > > }  
> > > > > }
> > > > > 
> > > > > 2014-06-06 19:40 GMT+02:00 David Pilato [david@pilato.fr](mailto:david@pilato.fr):
> > > > > 
> > > > > > Can you print also the full response object (toString()) as well?
> > > > > > 
> > > > > > ```
> > > > > > --
> > > > > > 
> > > > > > ```
> > > > > > 
> > > > > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> > > > > > [http://Elasticsearch.com](http://Elasticsearch.com)_  
> > > > > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> > > > > > [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > > > > > 
> > > > > > Le 6 juin 2014 à 19:24:00, Дмитрий Киселев (  
> > > > > > [dmitry.v.kiselev@gmail.com](mailto:dmitry.v.kiselev@gmail.com)) a écrit:
> > > > > > 
> > > > > > Yep.
> > > > > > 
> > > > > > System.out.println(searchQ.toString());
> > > > > > 
> > > > > > {  
> > > > > > "from" : 0,  
> > > > > > "size" : 5,  
> > > > > > "query" : {  
> > > > > > "match\_all" : { }  
> > > > > > },  
> > > > > > "explain" : false,  
> > > > > > "fields" :   
> > > > > > }
> > > > > > 
> > > > > > Also, I think it's might be connected with sharding.  
> > > > > > I've tried to change number\_of\_shards to 1 and paging starts act as I  
> > > > > > expect.
> > > > > > 
> > > > > > Set number\_of\_shards to 5 and get 25 hits.  
> > > > > > Set number\_of\_shards to 4 and get 20 hits.
> > > > > > 
> > > > > > It's seems like from and size applied to every shard separately in my  
> > > > > > case.
> > > > > > 
> > > > > > ## -- Thank you for your time. Best regards. Dmitry.
> > > > > > 
> > > > > > 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/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com)  
> > > > > > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris\_4uZ8\_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxOjT5wGmris_4uZ8_33uF6d51hzZ3Z%3DUvBKGbRV-YuR2Q%40mail.gmail.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 a topic in  
> > > > > > the Google Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this topic, visit  
> > > > > > [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe)  
> > > > > > .  
> > > > > > To unsubscribe from this group and all its topics, 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/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local)  
> > > > > > [https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.5391fd20.12200854.12ee%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer).
> > > > > > 
> > > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > > 
> > > > > ## -- Thank you for your time. Best regards. Dmitry.
> > > > > 
> > > > > 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/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com)  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxMC59nEgggzTA5eR83ibdCQiV5URr4CkynDH%2B2%2BKY4z7w%40mail.gmail.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 a topic in the  
> > > > > Google Groups "elasticsearch" group.  
> > > > > To unsubscribe from this topic, visit  
> > > > > [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe)  
> > > > > .  
> > > > > To unsubscribe from this group and all its topics, 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/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local)  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.5392006e.4e6afb66.12ee%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer)  
> > > > > .
> > > > > 
> > > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > > 
> > > > --  
> > > > Thank you for your time. Best regards.  
> > > > Dmitry.
> > > > 
> > > > --  
> > > > 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/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa\_UG3qQEH5CH1A0gDg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa_UG3qQEH5CH1A0gDg%40mail.gmail.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa\_UG3qQEH5CH1A0gDg%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxM7zdsbSqz6B%3DkB1m0JzDJDXSQUa_UG3qQEH5CH1A0gDg%40mail.gmail.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 a topic in the  
> > > > Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this topic, visit  
> > > > [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe)  
> > > > .  
> > > > To unsubscribe from this group and all its topics, 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/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/DB3A3263-2C87-42CA-981D-3DF747144A95%40pilato.fr?utm_medium=email&utm_source=footer)  
> > > > .
> > > > 
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > Thank you for your time. Best regards.  
> > > Dmitry.
> > > 
> > > --  
> > > 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/CAA9QNxP\_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxP_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxP\_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxP_GEgJH5m5aOF85VpyDx1aLKL2gzfUVice0A%2BxDQn7KA%40mail.gmail.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 a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> > > To unsubscribe from this group and all its topics, 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/885EB070-FAAE-408E-BC1D-2BDF7A6DEECF%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/885EB070-FAAE-408E-BC1D-2BDF7A6DEECF%40pilato.fr)  
> > > [https://groups.google.com/d/msgid/elasticsearch/885EB070-FAAE-408E-BC1D-2BDF7A6DEECF%40pilato.fr?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/885EB070-FAAE-408E-BC1D-2BDF7A6DEECF%40pilato.fr?utm_medium=email&utm_source=footer)  
> > > .
> > > 
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > Thank you for your time. Best regards.  
> > Dmitry.
> > 
> > --  
> > 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/CAA9QNxPBU2dH1aci6TFLQXRLo0DdcLX%3DtzOW\_uXtKeS3U5UUZw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxPBU2dH1aci6TFLQXRLo0DdcLX%3DtzOW_uXtKeS3U5UUZw%40mail.gmail.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/CAA9QNxPBU2dH1aci6TFLQXRLo0DdcLX%3DtzOW\_uXtKeS3U5UUZw%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxPBU2dH1aci6TFLQXRLo0DdcLX%3DtzOW_uXtKeS3U5UUZw%40mail.gmail.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 a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe](https://groups.google.com/d/topic/elasticsearch/p8RWVdqLcoI/unsubscribe).  
> To unsubscribe from this group and all its topics, 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/CALY%3DcQCEN%3DqTTnGKucHPQONnV8qp%2BXKukWCvqutsH-Jv5\_18%3Dg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCEN%3DqTTnGKucHPQONnV8qp%2BXKukWCvqutsH-Jv5_18%3Dg%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCEN%3DqTTnGKucHPQONnV8qp%2BXKukWCvqutsH-Jv5\_18%3Dg%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCEN%3DqTTnGKucHPQONnV8qp%2BXKukWCvqutsH-Jv5_18%3Dg%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Thank you for your time. Best regards.  
Dmitry.

--  
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/CAA9QNxONS6QYy%2BEjDJxMAeKLy80fLrdBPfrSnrWAgVSO74\_EPg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAA9QNxONS6QYy%2BEjDJxMAeKLy80fLrdBPfrSnrWAgVSO74_EPg%40mail.gmail.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:24am UTC](https://discuss.elastic.co/t/wrong-paging-with-embedded-es-instance/17955/14 "2017-07-06T01:24:04Z")

</div>


