# Unexpected behaviour using from / size

**URL:** <https://discuss.elastic.co/t/unexpected-behaviour-using-from-size/6265>\
**Category:** Elasticsearch\
**Created:** [January 2, 2012, 2:00pm UTC](https://discuss.elastic.co/t/unexpected-behaviour-using-from-size/6265 "2012-01-02T14:00:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Runar\_Myklebust\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/runar_myklebust_2/32/2047_2.png) [@Runar\_Myklebust\_2](https://discuss.elastic.co/u/Runar_Myklebust_2)\
**Post date:** [January 2, 2012, 2:00pm UTC](https://discuss.elastic.co/t/unexpected-behaviour-using-from-size/6265/1 "2012-01-02T14:00:50Z")

</div>

Im doing some unit-tests and gets some unexpected result when using the  
from and size parameters:

I add two documents to the index, with ids 1 and 2.

When querying like this:

{  
"from" : 0,  
"size" : 2,  
"query" : {  
"match\_all" : {  
}  
}  
}

I get results as expected:

searchHits.getHits().length = 2  
searchHits.getTotalHits() = 2

When I do this query instead:

{  
"from" : 1,  
"size" : 2,  
"query" : {  
"match\_all" : {  
}  
}  
}

I get this result, which for me seem to be wrong:

searchHits.getHits().length = 0  
searchHits.getTotalHits() = 2

I would have expected to get a hit?

Im using v 0.18.6

## mvh

Runar Myklebust

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [January 2, 2012, 2:04pm UTC](https://discuss.elastic.co/t/unexpected-behaviour-using-from-size/6265/2 "2012-01-02T14:04:47Z")

</div>

Which search type are you using?

On Mon, Jan 2, 2012 at 4:00 PM, Runar Myklebust [runar@myklebust.me](mailto:runar@myklebust.me) wrote:

> Im doing some unit-tests and gets some unexpected result when using the  
> from and size parameters:
> 
> I add two documents to the index, with ids 1 and 2.
> 
> When querying like this:
> 
> {  
> "from" : 0,  
> "size" : 2,  
> "query" : {  
> "match\_all" : {  
> }  
> }  
> }
> 
> I get results as expected:
> 
> searchHits.getHits().length = 2  
> searchHits.getTotalHits() = 2
> 
> When I do this query instead:
> 
> {  
> "from" : 1,  
> "size" : 2,  
> "query" : {  
> "match\_all" : {  
> }  
> }  
> }
> 
> I get this result, which for me seem to be wrong:
> 
> searchHits.getHits().length = 0  
> searchHits.getTotalHits() = 2
> 
> I would have expected to get a hit?
> 
> Im using v 0.18.6
> 
> ## mvh
> 
> Runar Myklebust

---

<div class="post-metadata">

**Author:** ![Runar\_Myklebust\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/runar_myklebust_2/32/2047_2.png) [@Runar\_Myklebust\_2](https://discuss.elastic.co/u/Runar_Myklebust_2)\
**Post date:** [January 2, 2012, 2:15pm UTC](https://discuss.elastic.co/t/unexpected-behaviour-using-from-size/6265/3 "2012-01-02T14:15:41Z")

</div>

Query And Fetch

On Mon, Jan 2, 2012 at 3:04 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> Which search type are you using?
> 
> On Mon, Jan 2, 2012 at 4:00 PM, Runar Myklebust [runar@myklebust.me](mailto:runar@myklebust.me)wrote:
> 
> > Im doing some unit-tests and gets some unexpected result when using the  
> > from and size parameters:
> > 
> > I add two documents to the index, with ids 1 and 2.
> > 
> > When querying like this:
> > 
> > {  
> > "from" : 0,  
> > "size" : 2,  
> > "query" : {  
> > "match\_all" : {  
> > }  
> > }  
> > }
> > 
> > I get results as expected:
> > 
> > searchHits.getHits().length = 2  
> > searchHits.getTotalHits() = 2
> > 
> > When I do this query instead:
> > 
> > {  
> > "from" : 1,  
> > "size" : 2,  
> > "query" : {  
> > "match\_all" : {  
> > }  
> > }  
> > }
> > 
> > I get this result, which for me seem to be wrong:
> > 
> > searchHits.getHits().length = 0  
> > searchHits.getTotalHits() = 2
> > 
> > I would have expected to get a hit?
> > 
> > Im using v 0.18.6
> > 
> > ## mvh
> > 
> > Runar Myklebust

## -- mvh

Runar Myklebust

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [January 2, 2012, 2:17pm UTC](https://discuss.elastic.co/t/unexpected-behaviour-using-from-size/6265/4 "2012-01-02T14:17:17Z")

</div>

Thats the problem, query\_and\_fetch returns size docs from each shard, and  
then the from is again shard related. Use query\_then\_fetch, which is the  
default (and the one people should use 99.999% of the time).

On Mon, Jan 2, 2012 at 4:15 PM, Runar Myklebust [runar@myklebust.me](mailto:runar@myklebust.me) wrote:

> Query And Fetch
> 
> On Mon, Jan 2, 2012 at 3:04 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > Which search type are you using?
> > 
> > On Mon, Jan 2, 2012 at 4:00 PM, Runar Myklebust [runar@myklebust.me](mailto:runar@myklebust.me)wrote:
> > 
> > > Im doing some unit-tests and gets some unexpected result when using the  
> > > from and size parameters:
> > > 
> > > I add two documents to the index, with ids 1 and 2.
> > > 
> > > When querying like this:
> > > 
> > > {  
> > > "from" : 0,  
> > > "size" : 2,  
> > > "query" : {  
> > > "match\_all" : {  
> > > }  
> > > }  
> > > }
> > > 
> > > I get results as expected:
> > > 
> > > searchHits.getHits().length = 2  
> > > searchHits.getTotalHits() = 2
> > > 
> > > When I do this query instead:
> > > 
> > > {  
> > > "from" : 1,  
> > > "size" : 2,  
> > > "query" : {  
> > > "match\_all" : {  
> > > }  
> > > }  
> > > }
> > > 
> > > I get this result, which for me seem to be wrong:
> > > 
> > > searchHits.getHits().length = 0  
> > > searchHits.getTotalHits() = 2
> > > 
> > > I would have expected to get a hit?
> > > 
> > > Im using v 0.18.6
> > > 
> > > ## mvh
> > > 
> > > Runar Myklebust
> 
> ## -- mvh
> 
> Runar Myklebust

---

<div class="post-metadata">

**Author:** ![Runar\_Myklebust\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/runar_myklebust_2/32/2047_2.png) [@Runar\_Myklebust\_2](https://discuss.elastic.co/u/Runar_Myklebust_2)\
**Post date:** [January 3, 2012, 7:00am UTC](https://discuss.elastic.co/t/unexpected-behaviour-using-from-size/6265/5 "2012-01-03T07:00:13Z")

</div>

Thanks, by mistake I thought the Query And Fetch was the default. Maybe it  
could be mentioned in the Search API - Search Type documentation?

On Mon, Jan 2, 2012 at 3:17 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> Thats the problem, query\_and\_fetch returns size docs from each shard, and  
> then the from is again shard related. Use query\_then\_fetch, which is the  
> default (and the one people should use 99.999% of the time).
> 
> On Mon, Jan 2, 2012 at 4:15 PM, Runar Myklebust [runar@myklebust.me](mailto:runar@myklebust.me)wrote:
> 
> > Query And Fetch
> > 
> > On Mon, Jan 2, 2012 at 3:04 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> > 
> > > Which search type are you using?
> > > 
> > > On Mon, Jan 2, 2012 at 4:00 PM, Runar Myklebust [runar@myklebust.me](mailto:runar@myklebust.me)wrote:
> > > 
> > > > Im doing some unit-tests and gets some unexpected result when using the  
> > > > from and size parameters:
> > > > 
> > > > I add two documents to the index, with ids 1 and 2.
> > > > 
> > > > When querying like this:
> > > > 
> > > > {  
> > > > "from" : 0,  
> > > > "size" : 2,  
> > > > "query" : {  
> > > > "match\_all" : {  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > I get results as expected:
> > > > 
> > > > searchHits.getHits().length = 2  
> > > > searchHits.getTotalHits() = 2
> > > > 
> > > > When I do this query instead:
> > > > 
> > > > {  
> > > > "from" : 1,  
> > > > "size" : 2,  
> > > > "query" : {  
> > > > "match\_all" : {  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > I get this result, which for me seem to be wrong:
> > > > 
> > > > searchHits.getHits().length = 0  
> > > > searchHits.getTotalHits() = 2
> > > > 
> > > > I would have expected to get a hit?
> > > > 
> > > > Im using v 0.18.6
> > > > 
> > > > ## mvh
> > > > 
> > > > Runar Myklebust
> > 
> > ## -- mvh
> > 
> > Runar Myklebust

## -- mvh

Runar Myklebust

---

<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, 3:44am UTC](https://discuss.elastic.co/t/unexpected-behaviour-using-from-size/6265/6 "2017-07-06T03:44:01Z")

</div>


