# AND filter with Size and From gives different results

**URL:** https://discuss.elastic.co/t/and-filter-with-size-and-from-gives-different-results/8655
**Category:** Elasticsearch
**Created:** [August 7, 2012, 4:58am UTC](https://discuss.elastic.co/t/and-filter-with-size-and-from-gives-different-results/8655 "2012-08-07T04:58:13Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Dusty\_Doris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dusty_doris/32/2441_2.png) [@Dusty\_Doris](https://discuss.elastic.co/u/Dusty_Doris)
#### Post date: [August 7, 2012, 4:58am UTC](https://discuss.elastic.co/t/and-filter-with-size-and-from-gives-different-results/8655/1 "2012-08-07T04:58:13Z")

</div>

I am running a filter against an index using a size and from parameter and  
getting different results on the same query. How can I make this filter  
return consistent results so I can make the size/to useful?

# all results

curl  
'[http://localhost:9200/providers/provider/\_search?pretty=true&fields=\_id](http://localhost:9200/providers/provider/_search?pretty=true&fields=_id)'  
-d   
'{"filter":{"and":[{"term":{"names.last\_name":"doris"}},{"term":{"addresses.state":"fl"}}]}}'

{  
"took" : 34,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 3,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "providers",  
"\_type" : "provider",  
"\_id" : "1013944560",  
"\_score" : 1.0  
}, {  
"\_index" : "providers",  
"\_type" : "provider",  
"\_id" : "1851535512",  
"\_score" : 1.0  
}, {  
"\_index" : "providers",  
"\_type" : "provider",  
"\_id" : "1568607125",  
"\_score" : 1.0  
} ]  
}  
}

# size=1, from=1

# running 4 times cycles through two entries

curl  
'[http://localhost:9200/providers/provider/\_search?pretty=true&size=1&from=1&fields=\_id](http://localhost:9200/providers/provider/_search?pretty=true&size=1&from=1&fields=_id)'  
-d   
'{"filter":{"and":[{"term":{"names.last\_name":"doris"}},{"term":{"addresses.state":"fl"}}]}}'

{  
"took" : 35,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 3,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "providers",  
"\_type" : "provider",  
"\_id" : "1568607125",  
"\_score" : 1.0  
} ]  
}  
}

{  
"took" : 25,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 3,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "providers",  
"\_type" : "provider",  
"\_id" : "1851535512",  
"\_score" : 1.0  
} ]  
}  
}

{  
"took" : 33,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 3,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "providers",  
"\_type" : "provider",  
"\_id" : "1568607125",  
"\_score" : 1.0  
} ]  
}  
}

{  
"took" : 25,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 3,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "providers",  
"\_type" : "provider",  
"\_id" : "1851535512",  
"\_score" : 1.0  
} ]  
}  
}

---

<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: [August 7, 2012, 6:01am UTC](https://discuss.elastic.co/t/and-filter-with-size-and-from-gives-different-results/8655/2 "2012-08-07T06:01:13Z")

</div>

Your concern is that you are doing a matchAll query.  
So scoring is always 1.  
ES sort results by score.

You can sort results by \_id.

HTH  
David

--

Le 7 août 2012 à 06:58, Dusty Doris [dusty@doris.name](mailto:dusty@doris.name) a écrit :

> I am running a filter against an index using a size and from parameter and getting different results on the same query. How can I make this filter return consistent results so I can make the size/to useful?
> 
> # all results
> 
> curl '[http://localhost:9200/providers/provider/\_search?pretty=true&fields=\_id](http://localhost:9200/providers/provider/_search?pretty=true&fields=_id)' -d   
> '{"filter":{"and":[{"term":{"names.last\_name":"doris"}},{"term":{"addresses.state":"fl"}}]}}'
> 
> {  
> "took" : 34,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 3,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "providers",  
> "\_type" : "provider",  
> "\_id" : "1013944560",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "providers",  
> "\_type" : "provider",  
> "\_id" : "1851535512",  
> "\_score" : 1.0  
> }, {  
> "\_index" : "providers",  
> "\_type" : "provider",  
> "\_id" : "1568607125",  
> "\_score" : 1.0  
> } ]  
> }  
> }
> 
> # size=1, from=1
> 
> # running 4 times cycles through two entries
> 
> curl '[http://localhost:9200/providers/provider/\_search?pretty=true&size=1&from=1&fields=\_id](http://localhost:9200/providers/provider/_search?pretty=true&size=1&from=1&fields=_id)' -d   
> '{"filter":{"and":[{"term":{"names.last\_name":"doris"}},{"term":{"addresses.state":"fl"}}]}}'
> 
> {  
> "took" : 35,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 3,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "providers",  
> "\_type" : "provider",  
> "\_id" : "1568607125",  
> "\_score" : 1.0  
> } ]  
> }  
> }
> 
> {  
> "took" : 25,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 3,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "providers",  
> "\_type" : "provider",  
> "\_id" : "1851535512",  
> "\_score" : 1.0  
> } ]  
> }  
> }
> 
> {  
> "took" : 33,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 3,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "providers",  
> "\_type" : "provider",  
> "\_id" : "1568607125",  
> "\_score" : 1.0  
> } ]  
> }  
> }
> 
> {  
> "took" : 25,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 3,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "providers",  
> "\_type" : "provider",  
> "\_id" : "1851535512",  
> "\_score" : 1.0  
> } ]  
> }  
> }

---

<div class="post-metadata">

### Author: ![Dusty\_Doris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dusty_doris/32/2441_2.png) [@Dusty\_Doris](https://discuss.elastic.co/u/Dusty_Doris)
#### Post date: [August 7, 2012, 6:09am UTC](https://discuss.elastic.co/t/and-filter-with-size-and-from-gives-different-results/8655/3 "2012-08-07T06:09:31Z")

</div>

Ok, sorting by \_id will work.

Just to clarify, in case I run into this with more advanced searches as  
well. If two entries have equal scores, the order they are returned is  
not guaranteed to be the same on subsequent searches unless a sort on  
something unique is performed?

Thanks.

On Tuesday, August 7, 2012 2:01:13 AM UTC-4, David Pilato wrote:

> Your concern is that you are doing a matchAll query.  
> So scoring is always 1.  
> ES sort results by score.
> 
> You can sort results by \_id.
> 
> HTH  
> David
> 
> --
> 
> Le 7 août 2012 à 06:58, Dusty Doris [dusty@doris.name](mailto:dusty@doris.name) a écrit :
> 
> > I am running a filter against an index using a size and from parameter  
> > and getting different results on the same query. How can I make this  
> > filter return consistent results so I can make the size/to useful?
> > 
> > # all results
> > 
> > curl '  
> > [http://localhost:9200/providers/provider/\_search?pretty=true&fields=\_id](http://localhost:9200/providers/provider/_search?pretty=true&fields=_id)'  
> > -d \
> 
> '{"filter":{"and":[{"term":{"names.last\_name":"doris"}},{"term":{"addresses.state":"fl"}}]}}'
> 
> > {  
> > "took" : 34,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 3,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "providers",  
> > "\_type" : "provider",  
> > "\_id" : "1013944560",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "providers",  
> > "\_type" : "provider",  
> > "\_id" : "1851535512",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "providers",  
> > "\_type" : "provider",  
> > "\_id" : "1568607125",  
> > "\_score" : 1.0  
> > } ]  
> > }  
> > }
> > 
> > # size=1, from=1
> > 
> > # running 4 times cycles through two entries
> > 
> > curl '  
> > [http://localhost:9200/providers/provider/\_search?pretty=true&size=1&from=1&fields=\_id](http://localhost:9200/providers/provider/_search?pretty=true&size=1&from=1&fields=_id)'  
> > -d \
> 
> '{"filter":{"and":[{"term":{"names.last\_name":"doris"}},{"term":{"addresses.state":"fl"}}]}}'
> 
> > {  
> > "took" : 35,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 3,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "providers",  
> > "\_type" : "provider",  
> > "\_id" : "1568607125",  
> > "\_score" : 1.0  
> > } ]  
> > }  
> > }
> > 
> > {  
> > "took" : 25,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 3,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "providers",  
> > "\_type" : "provider",  
> > "\_id" : "1851535512",  
> > "\_score" : 1.0  
> > } ]  
> > }  
> > }
> > 
> > {  
> > "took" : 33,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 3,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "providers",  
> > "\_type" : "provider",  
> > "\_id" : "1568607125",  
> > "\_score" : 1.0  
> > } ]  
> > }  
> > }
> > 
> > {  
> > "took" : 25,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 3,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "providers",  
> > "\_type" : "provider",  
> > "\_id" : "1851535512",  
> > "\_score" : 1.0  
> > } ]  
> > }  
> > }

---

<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: [August 7, 2012, 6:19am UTC](https://discuss.elastic.co/t/and-filter-with-size-and-from-gives-different-results/8655/4 "2012-08-07T06:19:46Z")

</div>

Yes.

You may look at Scan & Scroll feature: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/scroll.html)

It could help.  
David

--

Le 7 août 2012 à 08:09, Dusty Doris [dusty@doris.name](mailto:dusty@doris.name) a écrit :

> Ok, sorting by \_id will work.
> 
> Just to clarify, in case I run into this with more advanced searches as well. If two entries have equal scores, the order they are returned is not guaranteed to be the same on subsequent searches unless a sort on something unique is performed?
> 
> Thanks.
> 
> On Tuesday, August 7, 2012 2:01:13 AM UTC-4, David Pilato wrote:  
> Your concern is that you are doing a matchAll query.  
> So scoring is always 1.  
> ES sort results by score.
> 
> You can sort results by \_id.
> 
> HTH  
> David
> 
> --
> 
> Le 7 août 2012 à 06:58, Dusty Doris [dusty@doris.name](mailto:dusty@doris.name) a écrit :
> 
> > I am running a filter against an index using a size and from parameter and getting different results on the same query. How can I make this filter return consistent results so I can make the size/to useful?
> > 
> > # all results
> > 
> > curl '[http://localhost:9200/providers/provider/\_search?pretty=true&fields=\_id](http://localhost:9200/providers/provider/_search?pretty=true&fields=_id)' -d \   
> > '{"filter":{"and":[{"term":{"names.last\_name":"doris"}},{"term":{"addresses.state":"fl"}}]}}'
> > 
> > {  
> > "took" : 34,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 3,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "providers",  
> > "\_type" : "provider",  
> > "\_id" : "1013944560",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "providers",  
> > "\_type" : "provider",  
> > "\_id" : "1851535512",  
> > "\_score" : 1.0  
> > }, {  
> > "\_index" : "providers",  
> > "\_type" : "provider",  
> > "\_id" : "1568607125",  
> > "\_score" : 1.0  
> > } ]  
> > }  
> > }
> > 
> > # size=1, from=1
> > 
> > # running 4 times cycles through two entries
> > 
> > curl '[http://localhost:9200/providers/provider/\_search?pretty=true&size=1&from=1&fields=\_id](http://localhost:9200/providers/provider/_search?pretty=true&size=1&from=1&fields=_id)' -d \   
> > '{"filter":{"and":[{"term":{"names.last\_name":"doris"}},{"term":{"addresses.state":"fl"}}]}}'
> > 
> > {  
> > "took" : 35,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 3,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "providers",  
> > "\_type" : "provider",  
> > "\_id" : "1568607125",  
> > "\_score" : 1.0  
> > } ]  
> > }  
> > }
> > 
> > {  
> > "took" : 25,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 3,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "providers",  
> > "\_type" : "provider",  
> > "\_id" : "1851535512",  
> > "\_score" : 1.0  
> > } ]  
> > }  
> > }
> > 
> > {  
> > "took" : 33,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 3,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "providers",  
> > "\_type" : "provider",  
> > "\_id" : "1568607125",  
> > "\_score" : 1.0  
> > } ]  
> > }  
> > }
> > 
> > {  
> > "took" : 25,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 3,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "providers",  
> > "\_type" : "provider",  
> > "\_id" : "1851535512",  
> > "\_score" : 1.0  
> > } ]  
> > }  
> > }

---

<div class="post-metadata">

### Author: ![Dusty\_Doris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dusty_doris/32/2441_2.png) [@Dusty\_Doris](https://discuss.elastic.co/u/Dusty_Doris)
#### Post date: [August 7, 2012, 6:23am UTC](https://discuss.elastic.co/t/and-filter-with-size-and-from-gives-different-results/8655/5 "2012-08-07T06:23:46Z")

</div>

Thank you David.

On Tuesday, August 7, 2012 2:19:46 AM UTC-4, David Pilato wrote:

> Yes.
> 
> You may look at Scan & Scroll feature:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/scroll.html)
> 
> It could help.  
> David
> 
> --
> 
> Le 7 août 2012 à 08:09, Dusty Doris [dusty@doris.name](mailto:dusty@doris.name) a écrit :
> 
> Ok, sorting by \_id will work.
> 
> Just to clarify, in case I run into this with more advanced searches as  
> well. If two entries have equal scores, the order they are returned is  
> not guaranteed to be the same on subsequent searches unless a sort on  
> something unique is performed?
> 
> Thanks.
> 
> On Tuesday, August 7, 2012 2:01:13 AM UTC-4, David Pilato wrote:
> 
> > Your concern is that you are doing a matchAll query.  
> > So scoring is always 1.  
> > ES sort results by score.
> > 
> > You can sort results by \_id.
> > 
> > HTH  
> > David
> > 
> > --
> > 
> > Le 7 août 2012 à 06:58, Dusty Doris [dusty@doris.name](mailto:dusty@doris.name) a écrit :
> > 
> > > I am running a filter against an index using a size and from parameter  
> > > and getting different results on the same query. How can I make this  
> > > filter return consistent results so I can make the size/to useful?
> > > 
> > > # all results
> > > 
> > > curl '  
> > > [http://localhost:9200/providers/provider/\_search?pretty=true&fields=\_id](http://localhost:9200/providers/provider/_search?pretty=true&fields=_id)'  
> > > -d \
> > 
> > '{"filter":{"and":[{"term":{"names.last\_name":"doris"}},{"term":{"addresses.state":"fl"}}]}}'
> > 
> > > {  
> > > "took" : 34,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 5,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 3,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_index" : "providers",  
> > > "\_type" : "provider",  
> > > "\_id" : "1013944560",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "providers",  
> > > "\_type" : "provider",  
> > > "\_id" : "1851535512",  
> > > "\_score" : 1.0  
> > > }, {  
> > > "\_index" : "providers",  
> > > "\_type" : "provider",  
> > > "\_id" : "1568607125",  
> > > "\_score" : 1.0  
> > > } ]  
> > > }  
> > > }
> > > 
> > > # size=1, from=1
> > > 
> > > # running 4 times cycles through two entries
> > > 
> > > curl '  
> > > [http://localhost:9200/providers/provider/\_search?pretty=true&size=1&from=1&fields=\_id](http://localhost:9200/providers/provider/_search?pretty=true&size=1&from=1&fields=_id)'  
> > > -d \
> > 
> > '{"filter":{"and":[{"term":{"names.last\_name":"doris"}},{"term":{"addresses.state":"fl"}}]}}'
> > 
> > > {  
> > > "took" : 35,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 5,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 3,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_index" : "providers",  
> > > "\_type" : "provider",  
> > > "\_id" : "1568607125",  
> > > "\_score" : 1.0  
> > > } ]  
> > > }  
> > > }
> > > 
> > > {  
> > > "took" : 25,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 5,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 3,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_index" : "providers",  
> > > "\_type" : "provider",  
> > > "\_id" : "1851535512",  
> > > "\_score" : 1.0  
> > > } ]  
> > > }  
> > > }
> > > 
> > > {  
> > > "took" : 33,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 5,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 3,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_index" : "providers",  
> > > "\_type" : "provider",  
> > > "\_id" : "1568607125",  
> > > "\_score" : 1.0  
> > > } ]  
> > > }  
> > > }
> > > 
> > > {  
> > > "took" : 25,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 5,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 3,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_index" : "providers",  
> > > "\_type" : "provider",  
> > > "\_id" : "1851535512",  
> > > "\_score" : 1.0  
> > > } ]  
> > > }  
> > > }

---

<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:17am UTC](https://discuss.elastic.co/t/and-filter-with-size-and-from-gives-different-results/8655/6 "2017-07-06T03:17:32Z")

</div>


