# Size in filtered query

**URL:** https://discuss.elastic.co/t/size-in-filtered-query/3866
**Category:** Elasticsearch
**Created:** [February 2, 2011, 4:50pm UTC](https://discuss.elastic.co/t/size-in-filtered-query/3866 "2011-02-02T16:50:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Sky\_Stebnicki1](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Sky\_Stebnicki1](https://discuss.elastic.co/u/Sky_Stebnicki1)
#### Post date: [February 2, 2011, 4:50pm UTC](https://discuss.elastic.co/t/size-in-filtered-query/3866/1 "2011-02-02T16:50:38Z")

</div>

Hi,

I am very new to ElasticSearch but just ran into something interesting  
and wanted to check and see if the behavior is expected.

When I do a filtered query like the one below:

{  
"query" :  
{  
"filtered" : {  
"query" : {  
"term" : { "tag" : "wow" }  
},  
"filter" : {  
"range" : {  
"age" : { "from" : 10, "to" : 20 }  
}  
}  
}  
},  
"from" : 0, "size" : 100,  
}

it ignores "from" and "size" but if I move them to the top:

{  
"from" : 0, "size" : 100,  
"query" :  
{  
"filtered" : {  
"query" : {  
"term" : { "tag" : "wow" }  
},  
"filter" : {  
"range" : {  
"age" : { "from" : 10, "to" : 20 }  
}  
}  
}  
}  
}

it works great. The interesting thing is that if I just do a filter  
then putting size and from after the filter works fine:

{  
"query" :  
{  
"filter" : {  
"range" : {  
"age" : { "from" : 10, "to" : 20 }  
}  
}  
}  
"from" : 0, "size" : 100  
}

100 results starting from 0 are returned as expected.

Anyway, it is easy enough to modify the php class to make sure from  
and size always come first in the array, but I figured I would share  
my findings.

---

<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: [February 2, 2011, 6:16pm UTC](https://discuss.elastic.co/t/size-in-filtered-query/3866/2 "2011-02-02T18:16:56Z")

</div>

Hard to tell based on what you posted since it looses the formatting, but just double checked with 0.14.x and master and this ones works well: [gist:808101 · GitHub](https://gist.github.com/808101).  
On Wednesday, February 2, 2011 at 6:50 PM, SkyStebnicki wrote:

> Hi,
> 
> I am very new to Elasticsearch but just ran into something interesting  
> and wanted to check and see if the behavior is expected.
> 
> When I do a filtered query like the one below:
> 
> {  
> "query" :  
> {  
> "filtered" : {  
> "query" : {  
> "term" : { "tag" : "wow" }  
> },  
> "filter" : {  
> "range" : {  
> "age" : { "from" : 10, "to" : 20 }  
> }  
> }  
> }  
> },  
> "from" : 0, "size" : 100,  
> }
> 
> it ignores "from" and "size" but if I move them to the top:
> 
> {  
> "from" : 0, "size" : 100,  
> "query" :  
> {  
> "filtered" : {  
> "query" : {  
> "term" : { "tag" : "wow" }  
> },  
> "filter" : {  
> "range" : {  
> "age" : { "from" : 10, "to" : 20 }  
> }  
> }  
> }  
> }  
> }
> 
> it works great. The interesting thing is that if I just do a filter  
> then putting size and from after the filter works fine:
> 
> {  
> "query" :  
> {  
> "filter" : {  
> "range" : {  
> "age" : { "from" : 10, "to" : 20 }  
> }  
> }  
> }  
> "from" : 0, "size" : 100  
> }
> 
> 100 results starting from 0 are returned as expected.
> 
> Anyway, it is easy enough to modify the php class to make sure from  
> and size always come first in the array, but I figured I would share  
> my findings.

---

<div class="post-metadata">

### Author: ![sky\_stebnicki](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sky_stebnicki/32/3277_2.png) [@sky\_stebnicki](https://discuss.elastic.co/u/sky_stebnicki)
#### Post date: [February 2, 2011, 8:55pm UTC](https://discuss.elastic.co/t/size-in-filtered-query/3866/3 "2011-02-02T20:55:00Z")

</div>

Interesting... I wonder if it is something local in my environment: freebsd 8.

Anyway, it was easy enough to reorder to array to put size and from at the top so it's not a problem for us.

I am the founder of a software company (Aereus) specializing in SaaS solutions in the area of CRM, GroupWare, Project Manager and more for small businesses. For the last 6 months we have been testing indexing solutions because the SQL database is getting way too big to query. ElasticSearch is by far the most impressive product I have worked with so far. Great job!

Sky

---

<div class="post-metadata">

### Author: ![Sky\_Stebnicki1](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Sky\_Stebnicki1](https://discuss.elastic.co/u/Sky_Stebnicki1)
#### Post date: [February 4, 2011, 6:32am UTC](https://discuss.elastic.co/t/size-in-filtered-query/3866/4 "2011-02-04T06:32:05Z")

</div>

Interesting... I wonder if it is something local in my environment:  
freebsd 8 and ES 0.14.

Anyway, it was easy enough to reorder to array to put size and from at  
the top so it's not a problem for us.

I am the founder of a software company (Aereus) specializing in SaaS  
solutions in the area of CRM, GroupWare, Project Manager and more for  
small businesses. For the last 6 months we have been testing indexing  
solutions because the SQL database is getting way too big to query.  
Elasticsearch is by far the most impressive product I have worked with  
so far. Great job!

Sky

On Feb 2, 10:16 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Hard to tell based on what you posted since it looses the formatting, but just double checked with 0.14.x and master and this ones works well:[gist:808101 · GitHub](https://gist.github.com/808101).
> 
> On Wednesday, February 2, 2011 at 6:50 PM, SkyStebnicki wrote:
> 
> > Hi,
> 
> > I am very new to Elasticsearch but just ran into something interesting  
> > and wanted to check and see if the behavior is expected.
> 
> > When I do a filtered query like the one below:
> 
> > {  
> > "query" :  
> > {  
> > "filtered" : {  
> > "query" : {  
> > "term" : { "tag" : "wow" }  
> > },  
> > "filter" : {  
> > "range" : {  
> > "age" : { "from" : 10, "to" : 20 }  
> > }  
> > }  
> > }  
> > },  
> > "from" : 0, "size" : 100,  
> > }
> 
> > it ignores "from" and "size" but if I move them to the top:
> 
> > {  
> > "from" : 0, "size" : 100,  
> > "query" :  
> > {  
> > "filtered" : {  
> > "query" : {  
> > "term" : { "tag" : "wow" }  
> > },  
> > "filter" : {  
> > "range" : {  
> > "age" : { "from" : 10, "to" : 20 }  
> > }  
> > }  
> > }  
> > }  
> > }
> 
> > it works great. The interesting thing is that if I just do a filter  
> > then putting size and from after the filter works fine:
> 
> > {  
> > "query" :  
> > {  
> > "filter" : {  
> > "range" : {  
> > "age" : { "from" : 10, "to" : 20 }  
> > }  
> > }  
> > }  
> > "from" : 0, "size" : 100  
> > }
> 
> > 100 results starting from 0 are returned as expected.
> 
> > Anyway, it is easy enough to modify the php class to make sure from  
> > and size always come first in the array, but I figured I would share  
> > my findings.

---

<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, 4:12am UTC](https://discuss.elastic.co/t/size-in-filtered-query/3866/5 "2017-07-06T04:12:37Z")

</div>


