# Term filters / exact match

**URL:** <https://discuss.elastic.co/t/term-filters-exact-match/4970>\
**Category:** Elasticsearch\
**Created:** [July 27, 2011, 12:31am UTC](https://discuss.elastic.co/t/term-filters-exact-match/4970 "2011-07-27T00:31:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian\_Eure](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ian_eure/32/3157_2.png) [@Ian\_Eure](https://discuss.elastic.co/u/Ian_Eure)\
**Post date:** [July 27, 2011, 12:31am UTC](https://discuss.elastic.co/t/term-filters-exact-match/4970/1 "2011-07-27T00:31:13Z")

</div>

I'm having some difficulties getting term filters to work properly. I poked around the mailing lists, and from what I can see, I'm doing the right thing, but it isn't working.

What I want to do is filter a query where a field exactly matches a string.

I have a mapping (bits elided):

{  
"geojson": {  
"properties": {  
"properties": {  
"type": "object",  
"dynamic": "true",  
"properties": {  
"categories": {  
"type": "string",  
"index": "not\_analyzed"}}}}}}

And I have a document, also with bits elided:

{'properties': {'categories': ['Food & Beverage', 'Restaurants', 'Mexican']}}}

My query looks like this:

{"query": {"filtered": {"filter": {"term": {"properties.categories": "Mexican"}}, "query": {"match\_all": {}}}}}

This matches nothing. If I lower-case "Mexican," it matches my document. If I change the term filter to "Food & Beverage", it also matches nothing, and changing the case as with the single-word filter also matches nothing.

As I understand from reading the docs & ML:

1. Term query/filter shouldn't analyze the searched/filtered value[1].
2. Fields with index not\_analyzed are stored unchanged[2].

But this doesn't seem to be the case. Perhaps also of interest, when I fetch my mapping from ES, I get this:

"categories" : {  
"type" : "string"  
}

No mention of index being analyzed or not\_analyzed. Even though the examples have it set up the same way I have, maybe that isn't working? I'm using ElasticSearch 0.17.1

[1]: [http://elasticsearch-users.115913.n3.nabble.com/Beginners-Query-Questions-tp2413095p2413372.html](http://elasticsearch-users.115913.n3.nabble.com/Beginners-Query-Questions-tp2413095p2413372.html) & [http://www.elasticsearch.org/guide/reference/query-dsl/term-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/term-query.html)  
[2]: [http://www.elasticsearch.org/guide/reference/index-modules/analysis/keyword-analyzer.html](http://www.elasticsearch.org/guide/reference/index-modules/analysis/keyword-analyzer.html)

---

<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:** [July 27, 2011, 4:24am UTC](https://discuss.elastic.co/t/term-filters-exact-match/4970/2 "2011-07-27T04:24:56Z")

</div>

I think you had something indexing into it before setting the mapping for  
the object. This works: [gist:1108666 · GitHub](https://gist.github.com/1108666) (do get mapping  
afterwards, you will see that categories are not analyzed).

On Wed, Jul 27, 2011 at 3:31 AM, Ian Eure [ian@simplegeo.com](mailto:ian@simplegeo.com) wrote:

> I'm having some difficulties getting term filters to work properly. I poked  
> around the mailing lists, and from what I can see, I'm doing the right  
> thing, but it isn't working.
> 
> What I want to do is filter a query where a field exactly matches a string.
> 
> I have a mapping (bits elided):
> 
> {  
> "geojson": {  
> "properties": {  
> "properties": {  
> "type": "object",  
> "dynamic": "true",  
> "properties": {  
> "categories": {  
> "type": "string",  
> "index": "not\_analyzed"}}}}}}
> 
> And I have a document, also with bits elided:
> 
> {'properties': {'categories': ['Food & Beverage', 'Restaurants',  
> 'Mexican']}}}
> 
> My query looks like this:
> 
> {"query": {"filtered": {"filter": {"term": {"properties.categories":  
> "Mexican"}}, "query": {"match\_all": {}}}}}
> 
> This matches nothing. If I lower-case "Mexican," it matches my document. If  
> I change the term filter to "Food & Beverage", it also matches nothing, and  
> changing the case as with the single-word filter also matches nothing.
> 
> As I understand from reading the docs & ML:
> 
> 1. Term query/filter shouldn't analyze the searched/filtered value[1](http://elasticsearch-users.115913.n3.nabble.com/Beginners-Query-Questions-tp2413095p2413372.html&).
> 2. Fields with index not\_analyzed are stored unchanged[2].
> 
> But this doesn't seem to be the case. Perhaps also of interest, when I  
> fetch my mapping from ES, I get this:
> 
> "categories" : {  
> "type" : "string"  
> }
> 
> No mention of index being analyzed or not\_analyzed. Even though the  
> examples have it set up the same way I have, maybe that isn't working? I'm  
> using Elasticsearch 0.17.1
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/term-query.html)  
> [2]:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/keyword-analyzer.html)

---

<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:59am UTC](https://discuss.elastic.co/t/term-filters-exact-match/4970/3 "2017-07-06T03:59:09Z")

</div>


