# Problems with filters/facets on not\_analyzed fields

**URL:** https://discuss.elastic.co/t/problems-with-filters-facets-on-not-analyzed-fields/11388
**Category:** Elasticsearch
**Created:** [March 29, 2013, 10:37pm UTC](https://discuss.elastic.co/t/problems-with-filters-facets-on-not-analyzed-fields/11388 "2013-03-29T22:37:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![qjh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/qjh/32/2420_2.png) [@qjh](https://discuss.elastic.co/u/qjh)
#### Post date: [March 29, 2013, 10:37pm UTC](https://discuss.elastic.co/t/problems-with-filters-facets-on-not-analyzed-fields/11388/1 "2013-03-29T22:37:20Z")

</div>

Hello,

I am running into an issue with filters and facets on not\_analyzed (also  
tried keyword analyzer, same results) fields. I have tested this with ES  
0.19.3, 0.20.4, and 0.90rc1. Basically what happens is that the fields  
appear to be analyzed as the facets are the tokenized + downcased values  
and filtering on the exact term yields no results. Here is a simple test:

curl -X POST "[http://localhost:9200/testing](http://localhost:9200/testing)"

> curl -X PUT "[http://localhost:9200/testing/foo/\_mapping](http://localhost:9200/testing/foo/_mapping)" -d  
> '{"foo":{"properties":{"title":{"type":"string","analyzer":"standard"}},"tags":{"type":"string","index":"not\_analyzed"}}}}'  
> curl -X POST "[http://localhost:9200/testing/foo](http://localhost:9200/testing/foo)" -d '{"title" : "Foo",  
> "tags" : ["One"]}'  
> curl -X POST "[http://localhost:9200/testing/foo](http://localhost:9200/testing/foo)" -d '{"title" : "Foo Bar",  
> "tags" : "Two Three"}'  
> curl -X POST "[http://localhost:9200/testing/foo](http://localhost:9200/testing/foo)" -d '{"title" : "Foo Bar  
> Baz", "tags" : ["One", "Two Three", "Four::Five"]}'  
> curl -X POST "[http://localhost:9200/testing/\_refresh](http://localhost:9200/testing/_refresh)"  
> curl -X GET "[http://localhost:9200/testing/foo/\_mapping](http://localhost:9200/testing/foo/_mapping)"

Now if I check the facets for a match all query, I get the terms that  
appear to be analyzed ("Four::Five" becomes two terms, "four" and "five").

curl -X GET "[http://localhost:9200/testing/foo/\_search?pretty](http://localhost:9200/testing/foo/_search?pretty)" -d

> '{"facets":{"tagsFacet":{"terms":{"field":"tags","size":10,"all\_terms":false}}}}'  
> "facets": {  
> "tagsFacet": {  
> "\_type": "terms",  
> "missing": 0,  
> "other": 0,  
> "terms": [{  
> "count": 2,  
> "term": "two"  
> }, {  
> "count": 2,  
> "term": "three"  
> }, {  
> "count": 2,  
> "term": "one"  
> }, {  
> "count": 1,  
> "term": "four"  
> }, {  
> "count": 1,  
> "term": "five"  
> }  
> ],  
> "total": 8  
> }  
> }

This is what I would expect:

"facets": {

> "tagsFacet": {  
> "\_type": "terms",  
> "missing": 0,  
> "other": 0,  
> "terms": [{  
> "count": 2,  
> "term": "Two Three"  
> }, {  
> "count": 2,  
> "term": "One"  
> }, {  
> "count": 1,  
> "term": "Four::Five"  
> }  
> ],  
> "total": 5  
> }  
> }

Similarly, filtering on an exact term yields no results.

curl -X GET "[http://localhost:9200/testing/foo/\_search?pretty](http://localhost:9200/testing/foo/_search?pretty)" -d

> '{"filter":{"term":{"tags":"Two Three"}}}'  
> {  
> "took" : 8,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }

I would expect this to return the two documents with exactly that tag. Any  
help is greatly appreciated.

Thanks.

--  
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: ![qjh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/qjh/32/2420_2.png) [@qjh](https://discuss.elastic.co/u/qjh)
#### Post date: [March 29, 2013, 10:43pm UTC](https://discuss.elastic.co/t/problems-with-filters-facets-on-not-analyzed-fields/11388/2 "2013-03-29T22:43:19Z")

</div>

Also, it may be worth noting that this or something similar has been  
brought up a handful of times before:

> <https://github.com/elastic/elasticsearch/issues/1957>

  
[https://groups.google.com/forum/?fromgroups=#!searchin/elasticsearch/not\_analyzed$20filter/elasticsearch/aqsppkqbZro/Vi\_Sim9Cl\_wJ](https://groups.google.com/forum/?fromgroups=#!searchin/elasticsearch/not_analyzed%2420filter/elasticsearch/aqsppkqbZro/Vi_Sim9Cl_wJ)

--  
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: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [March 30, 2013, 8:45am UTC](https://discuss.elastic.co/t/problems-with-filters-facets-on-not-analyzed-fields/11388/3 "2013-03-30T08:45:28Z")

</div>

Hiya

> ```
> curl -X POST "http://localhost:9200/testing"
> curl -X PUT "http://localhost:9200/testing/foo/_mapping" -d
> '{"foo":{"properties":{"title":{"type":"string","analyzer":"standard"}},"tags":{"type":"string","index":"not_analyzed"}}}}'
> curl -X GET "http://localhost:9200/testing/foo/_mapping"
> 
> ```

Pretty printing your JSON really helps for debugging such problems.  
Also, you check the mapping in the last request above, but you don't  
mention the fact that the mapping is incorrect.

Your PUT mapping is putting this JSON: (note the bad nesting, and the  
extra } at the end):

{  
"foo" : {  
"tags" : {  
"index" : "not\_analyzed",  
"type" : "string"  
},  
"properties" : {  
"title" : {  
"type" : "string",  
"analyzer" : "standard"  
}  
}  
}  
}  
}

It should be putting this JSON:  
{  
"foo" : {  
"properties" : {  
"title" : {  
"type" : "string",  
"analyzer" : "standard"  
},  
"tags" : {  
"index" : "not\_analyzed",  
"type" : "string"  
}  
}  
}  
}

clint

--  
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: ![qjh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/qjh/32/2420_2.png) [@qjh](https://discuss.elastic.co/u/qjh)
#### Post date: [March 30, 2013, 7:33pm UTC](https://discuss.elastic.co/t/problems-with-filters-facets-on-not-analyzed-fields/11388/4 "2013-03-30T19:33:06Z")

</div>

Thanks Clint, I'll pretty print that mapping next time!

On Friday, March 29, 2013 3:37:20 PM UTC-7, qjh wrote:

> Hello,
> 
> I am running into an issue with filters and facets on not\_analyzed (also  
> tried keyword analyzer, same results) fields. I have tested this with ES  
> 0.19.3, 0.20.4, and 0.90rc1. Basically what happens is that the fields  
> appear to be analyzed as the facets are the tokenized + downcased values  
> and filtering on the exact term yields no results. Here is a simple test:
> 
> curl -X POST "[http://localhost:9200/testing](http://localhost:9200/testing)"
> 
> > curl -X PUT "[http://localhost:9200/testing/foo/\_mapping](http://localhost:9200/testing/foo/_mapping)" -d  
> > '{"foo":{"properties":{"title":{"type":"string","analyzer":"standard"}},"tags":{"type":"string","index":"not\_analyzed"}}}}'  
> > curl -X POST "[http://localhost:9200/testing/foo](http://localhost:9200/testing/foo)" -d '{"title" : "Foo",  
> > "tags" : ["One"]}'  
> > curl -X POST "[http://localhost:9200/testing/foo](http://localhost:9200/testing/foo)" -d '{"title" : "Foo  
> > Bar", "tags" : "Two Three"}'  
> > curl -X POST "[http://localhost:9200/testing/foo](http://localhost:9200/testing/foo)" -d '{"title" : "Foo Bar  
> > Baz", "tags" : ["One", "Two Three", "Four::Five"]}'  
> > curl -X POST "[http://localhost:9200/testing/\_refresh](http://localhost:9200/testing/_refresh)"  
> > curl -X GET "[http://localhost:9200/testing/foo/\_mapping](http://localhost:9200/testing/foo/_mapping)"
> 
> Now if I check the facets for a match all query, I get the terms that  
> appear to be analyzed ("Four::Five" becomes two terms, "four" and "five").
> 
> curl -X GET "[http://localhost:9200/testing/foo/\_search?pretty](http://localhost:9200/testing/foo/_search?pretty)" -d
> 
> > '{"facets":{"tagsFacet":{"terms":{"field":"tags","size":10,"all\_terms":false}}}}'  
> > "facets": {  
> > "tagsFacet": {  
> > "\_type": "terms",  
> > "missing": 0,  
> > "other": 0,  
> > "terms": [{  
> > "count": 2,  
> > "term": "two"  
> > }, {  
> > "count": 2,  
> > "term": "three"  
> > }, {  
> > "count": 2,  
> > "term": "one"  
> > }, {  
> > "count": 1,  
> > "term": "four"  
> > }, {  
> > "count": 1,  
> > "term": "five"  
> > }  
> > ],  
> > "total": 8  
> > }  
> > }
> 
> This is what I would expect:
> 
> "facets": {
> 
> > "tagsFacet": {  
> > "\_type": "terms",  
> > "missing": 0,  
> > "other": 0,  
> > "terms": [{  
> > "count": 2,  
> > "term": "Two Three"  
> > }, {  
> > "count": 2,  
> > "term": "One"  
> > }, {  
> > "count": 1,  
> > "term": "Four::Five"  
> > }  
> > ],  
> > "total": 5  
> > }  
> > }
> 
> Similarly, filtering on an exact term yields no results.
> 
> curl -X GET "[http://localhost:9200/testing/foo/\_search?pretty](http://localhost:9200/testing/foo/_search?pretty)" -d
> 
> > '{"filter":{"term":{"tags":"Two Three"}}}'  
> > {  
> > "took" : 8,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 1,  
> > "successful" : 1,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 0,  
> > "max\_score" : null,  
> > "hits" :   
> > }  
> > }
> 
> I would expect this to return the two documents with exactly that tag.  
> Any help is greatly appreciated.
> 
> Thanks.

--  
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:43am UTC](https://discuss.elastic.co/t/problems-with-filters-facets-on-not-analyzed-fields/11388/5 "2017-07-06T02:43:28Z")

</div>


