# Execution of term query in filter context

**URL:** https://discuss.elastic.co/t/execution-of-term-query-in-filter-context/45325
**Category:** Elasticsearch
**Created:** [March 24, 2016, 9:44am UTC](https://discuss.elastic.co/t/execution-of-term-query-in-filter-context/45325 "2016-03-24T09:44:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Anirudh\_Modi](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@Anirudh\_Modi](https://discuss.elastic.co/u/Anirudh_Modi)
#### Post date: [March 24, 2016, 9:44am UTC](https://discuss.elastic.co/t/execution-of-term-query-in-filter-context/45325/1 "2016-03-24T09:44:49Z")

</div>

Prior to elastic 2.0 there was term filter and term query., where the term query use to work on analyzed field and the term filter use to work on the non-analyzed field.

Now, elasticsearch 2.x we are supposed to use term query in filter context to get the desired effect, however I am confused about the fact that with new changes will the term filter work on both analyzed and non-analyzed or just on non-analyzed field?

---

<div class="post-metadata">

### Author: ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)
#### Post date: [March 24, 2016, 10:58am UTC](https://discuss.elastic.co/t/execution-of-term-query-in-filter-context/45325/2 "2016-03-24T10:58:25Z")

</div>

Analyzed/non-analyzed is not related to query or filter context. You can address the field as you like.

Example for searching a term in query context

`termQuery("foo1", "bar1")`

Example for searching a term in filter context

`boolQuery().must(matchAllQuery()).filter(termQuery("foo2", "bar2"))`

---

<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 5, 2017, 11:05pm UTC](https://discuss.elastic.co/t/execution-of-term-query-in-filter-context/45325/3 "2017-07-05T23:05:32Z")

</div>


