# Understanding AND evaluation

**URL:** https://discuss.elastic.co/t/understanding-and-evaluation/18834
**Category:** Elasticsearch
**Created:** [July 23, 2014, 4:31pm UTC](https://discuss.elastic.co/t/understanding-and-evaluation/18834 "2014-07-23T16:31:07Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Neil\_Avery](https://avatars.discourse-cdn.com/v4/letter/n/df788c/32.png) [@Neil\_Avery](https://discuss.elastic.co/u/Neil_Avery)
#### Post date: [July 23, 2014, 4:31pm UTC](https://discuss.elastic.co/t/understanding-and-evaluation/18834/1 "2014-07-23T16:31:07Z")

</div>

All,  
After searching the docs and scouring the web Im hoping someone can help me  
understand the evaluation of 'and' filters.

Conventionally, the short-circuit rules apply....i.e. fail on first clause  
and go no further..

Can anyone confirm is this is the case?

I'd like to run the following however my native script is always executed  
against data the fails the first clause. i.e. its hitting data where the  
\_host field is BBBB.local.

Regards,  
Neil.

{  
"query" : {  
"filtered" : {  
"query" : {  
"match\_all" : { }  
},  
"filter" : {  
"and" : {  
"filters" : [ {  
"term" : {  
"\_host" : "AAAA.local"  
}  
}, {  
"script" : {  
"script" : "ls-script",  
"params" : {  
"startMs" : 1406131440000,  
"endMs" : 1406133300001  
},  
"lang" : "native"  
}  
} ]  
}  
}  
}  
}  
}

--  
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/454e92b6-ff8f-4f99-b452-87ccd676337f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/454e92b6-ff8f-4f99-b452-87ccd676337f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [July 24, 2014, 8:18am UTC](https://discuss.elastic.co/t/understanding-and-evaluation/18834/2 "2014-07-24T08:18:21Z")

</div>

Indeed the short-circuit rule applies. I tried to reproduce the issue  
locally on master but didn't manage to.

How do you check that the native script is executed against data that fails  
the first clause? Can you provide us with a curl recreation of the issue?

On Wed, Jul 23, 2014 at 6:31 PM, Neil Avery [neil.avery@liquidlabs.co.uk](mailto:neil.avery@liquidlabs.co.uk)  
wrote:

> All,  
> After searching the docs and scouring the web Im hoping someone can help  
> me understand the evaluation of 'and' filters.
> 
> Conventionally, the short-circuit rules apply....i.e. fail on first clause  
> and go no further..
> 
> Can anyone confirm is this is the case?
> 
> I'd like to run the following however my native script is always executed  
> against data the fails the first clause. i.e. its hitting data where the  
> \_host field is BBBB.local.
> 
> Regards,  
> Neil.
> 
> {  
> "query" : {  
> "filtered" : {  
> "query" : {  
> "match\_all" : { }  
> },  
> "filter" : {  
> "and" : {  
> "filters" : [ {  
> "term" : {  
> "\_host" : "AAAA.local"  
> }  
> }, {  
> "script" : {  
> "script" : "ls-script",  
> "params" : {  
> "startMs" : 1406131440000,  
> "endMs" : 1406133300001  
> },  
> "lang" : "native"  
> }  
> } ]  
> }  
> }  
> }  
> }  
> }
> 
> --  
> 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/454e92b6-ff8f-4f99-b452-87ccd676337f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/454e92b6-ff8f-4f99-b452-87ccd676337f%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/454e92b6-ff8f-4f99-b452-87ccd676337f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/454e92b6-ff8f-4f99-b452-87ccd676337f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
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/CAL6Z4j7bfZqHU-qpOx3ng374WC6GtL6VLe2WZ\_SJ7H9SE4neFA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7bfZqHU-qpOx3ng374WC6GtL6VLe2WZ_SJ7H9SE4neFA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Neil\_Avery](https://avatars.discourse-cdn.com/v4/letter/n/df788c/32.png) [@Neil\_Avery](https://discuss.elastic.co/u/Neil_Avery)
#### Post date: [July 24, 2014, 10:49am UTC](https://discuss.elastic.co/t/understanding-and-evaluation/18834/3 "2014-07-24T10:49:09Z")

</div>

Thanks the reply Adrien.  
I've taken another look and confirm that it was an error on my part (sorry)!

It is behaving as expected - my error was the term based filter was working  
correctly and when changing it to a non-matching term it filtered out  
everything as is expected.

Thanks again,  
Neil.

On Thursday, July 24, 2014 9:18:31 AM UTC+1, Adrien Grand wrote:

> Indeed the short-circuit rule applies. I tried to reproduce the issue  
> locally on master but didn't manage to.
> 
> How do you check that the native script is executed against data that  
> fails the first clause? Can you provide us with a curl recreation of the  
> issue?
> 
> On Wed, Jul 23, 2014 at 6:31 PM, Neil Avery \<[neil....@liquidlabs.co.uk](mailto:neil....@liquidlabs.co.uk)  
> \<javascript:\>\> wrote:
> 
> > All,  
> > After searching the docs and scouring the web Im hoping someone can help  
> > me understand the evaluation of 'and' filters.
> > 
> > Conventionally, the short-circuit rules apply....i.e. fail on first  
> > clause and go no further..
> > 
> > Can anyone confirm is this is the case?
> > 
> > I'd like to run the following however my native script is always executed  
> > against data the fails the first clause. i.e. its hitting data where the  
> > \_host field is BBBB.local.
> > 
> > Regards,  
> > Neil.
> > 
> > {  
> > "query" : {  
> > "filtered" : {  
> > "query" : {  
> > "match\_all" : { }  
> > },  
> > "filter" : {  
> > "and" : {  
> > "filters" : [ {  
> > "term" : {  
> > "\_host" : "AAAA.local"  
> > }  
> > }, {  
> > "script" : {  
> > "script" : "ls-script",  
> > "params" : {  
> > "startMs" : 1406131440000,  
> > "endMs" : 1406133300001  
> > },  
> > "lang" : "native"  
> > }  
> > } ]  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/454e92b6-ff8f-4f99-b452-87ccd676337f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/454e92b6-ff8f-4f99-b452-87ccd676337f%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/454e92b6-ff8f-4f99-b452-87ccd676337f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/454e92b6-ff8f-4f99-b452-87ccd676337f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Adrien Grand

--  
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/01e18637-8ccd-42c5-9f2d-8c556a4f2130%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/01e18637-8ccd-42c5-9f2d-8c556a4f2130%40googlegroups.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:13am UTC](https://discuss.elastic.co/t/understanding-and-evaluation/18834/4 "2017-07-06T01:13:31Z")

</div>


