# Execution Mode with AND(TERMS, etc...) filters

**URL:** https://discuss.elastic.co/t/execution-mode-with-and-terms-etc-filters/13752
**Category:** Elasticsearch
**Created:** [September 25, 2013, 3:03pm UTC](https://discuss.elastic.co/t/execution-mode-with-and-terms-etc-filters/13752 "2013-09-25T15:03:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Matthew\_Tschiegg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_tschiegg/32/2085_2.png) [@Matthew\_Tschiegg](https://discuss.elastic.co/u/Matthew_Tschiegg)
#### Post date: [September 25, 2013, 3:03pm UTC](https://discuss.elastic.co/t/execution-mode-with-and-terms-etc-filters/13752/1 "2013-09-25T15:03:42Z")

</div>

Yesterday we had an issue where we were getting results we did not expect  
from a query that has been running for some time. The gist of the query is:

{  
"query" : {  
"filtered" : {  
"filter" : {  
"and" : [  
{  
"terms" : {  
"customer\_id" : [  
932,  
798  
]  
}  
},  
{  
"range" : {  
"event\_epoch" : {  
"to" : 13800451266,  
"from" : 0  
}  
}  
}  
]  
},  
"query" : {  
"match\_all" : {}  
}  
}  
},  
"size" : 500  
}

Upon running this query we were returning customer\_id's that were not in  
the terms list (835 to be exact). The mapping for the index is:

{  
"events\_v4" : {  
"state" : "open",  
"settings" : {  
"index.analysis.analyzer.stem.filter.1" : "lowercase",  
"index.number\_of\_replicas" : "2",  
"index.analysis.analyzer.stem.filter.2" : "stop",  
"index.analysis.analyzer.stem.filter.0" : "standard",  
"index.analysis.analyzer.stem.tokenizer" : "standard",  
"index.analysis.analyzer.stem.filter.3" : "porter\_stem",  
"index.number\_of\_shards" : "5",  
"index.version.created" : "900199"  
},  
"mappings" : {  
"_default_" : {  
"dynamic\_templates" : [  
{  
"not\_analyzed\_template" : {  
"mapping" : {  
"index" : "not\_analyzed",  
"type" : "string"  
},  
"match\_mapping\_type" : "string",  
"match" : "_\_id_"  
}  
}  
],  
"properties" : {}  
},  
"event" : {  
"dynamic\_templates" : [  
{  
"not\_analyzed\_template" : {  
"mapping" : {  
"index" : "not\_analyzed",  
"type" : "string"  
},  
"match\_mapping\_type" : "string",  
"match" : "_\_id_"  
}  
}  
],  
"properties" : {  
"resources" : {  
"index" : "not\_analyzed",  
"omit\_norms" : true,  
"store" : true,  
"index\_options" : "docs",  
"type" : "string"  
},  
"resource\_ids" : {  
"index" : "not\_analyzed",  
"omit\_norms" : true,  
"store" : true,  
"index\_options" : "docs",  
"type" : "string"  
},  
"event\_category" : {  
"index" : "not\_analyzed",  
"omit\_norms" : true,  
"store" : true,  
"index\_options" : "docs",  
"type" : "string"  
},  
"details" : {

```
      },
      "event_type" : {
        "index" : "not_analyzed",
        "omit_norms" : true,
        "store" : true,
        "index_options" : "docs",
        "type" : "string"
      },
      "event_id" : {
        "index" : "not_analyzed",
        "omit_norms" : true,
        "store" : true,
        "index_options" : "docs",
        "type" : "string"
      },
      "resource_types" : {
        "index" : "not_analyzed",
        "omit_norms" : true,
        "store" : true,
        "index_options" : "docs",
        "type" : "string"
      },
      "event_epoch" : {
        "store" : true,
        "type" : "long"
      },
      "customer_id" : {
        "store" : true,
        "type" : "integer"
      }
    }
  }
},
"aliases" : ["events"]

```

}  
}

Looking back at the problem today, we are no longer returning erroneous  
results with the same query. We noted that two fixes to the problem were  
replacing the AND filter with bool -\> must in addition to changing the  
execution mode of the terms filter to bool.

Does anyone have some insight as to why a Terms filter over an integer  
mapping with a plain execution mode wrapped in an AND filter would return  
results outside of the list of specified terms?

Thanks,

Matthew

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:14am UTC](https://discuss.elastic.co/t/execution-mode-with-and-terms-etc-filters/13752/2 "2017-07-06T02:14:43Z")

</div>


