# Upper case and lower case string giving different results for filter

**URL:** <https://discuss.elastic.co/t/upper-case-and-lower-case-string-giving-different-results-for-filter/205260>\
**Category:** Elasticsearch\
**Created:** [October 25, 2019, 1:15pm UTC](https://discuss.elastic.co/t/upper-case-and-lower-case-string-giving-different-results-for-filter/205260 "2019-10-25T13:15:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![decodeit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/decodeit/32/46023_2.png) [@decodeit](https://discuss.elastic.co/u/decodeit)\
**Post date:** [October 25, 2019, 1:15pm UTC](https://discuss.elastic.co/t/upper-case-and-lower-case-string-giving-different-results-for-filter/205260/1 "2019-10-25T13:15:53Z")

</div>

So I have this query,  
` { "query": { "bool": { "must": [{ "match": { "title": "communication"}}], "filter": [{ "term": { "survey": "general" }}] } } }`  
Now, it gives me exactly one result. The survey field has

> General communcation Society

so if i string in my filter term to General , it does not return any hits. and also if I type in while General communication Society, it does not return any result.  
Any explanation why and how to fix it.  
Thanks

---

<div class="post-metadata">

**Author:** ![Glen\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glen_smith/32/111656_2.png) [@Glen\_Smith](https://discuss.elastic.co/u/Glen_Smith)\
**Post date:** [October 25, 2019, 10:14pm UTC](https://discuss.elastic.co/t/upper-case-and-lower-case-string-giving-different-results-for-filter/205260/2 "2019-10-25T22:14:02Z")

</div>

decodeit,

The field value in the document, "General communcation Society", gets analyzed, probably by the [default analyzer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-standard-analyzer.html) (unless you have specified otherwise in your mapping). You may note that it includes `lowercase` of all the tokens, so one of the indexed tokens for that document is "general".

Now, when using a `term` filter, the value is not analyzed, just the raw value is compared. So when you use "general" it matches, but "General" does not. When you provide a `term` search for the entire phrase, it's not even tokenized, so will only return a doc where the exact phrase has been tokenized - none, because the indexer only stored the fully analyzed tokens.

If you instead use `match`, then it will be analyzed the same way the indexed documents field was analyzed, and both of those will match.

---

<div class="post-metadata">

**Author:** ![decodeit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/decodeit/32/46023_2.png) [@decodeit](https://discuss.elastic.co/u/decodeit)\
**Post date:** [October 28, 2019, 11:58am UTC](https://discuss.elastic.co/t/upper-case-and-lower-case-string-giving-different-results-for-filter/205260/3 "2019-10-28T11:58:32Z")

</div>

I tried using like this:  
`"filter": [{ "multi_match": { "query": "General Social Survey", "fields": "survey.title.en" } }]`

is this the best approach.  
Also I am looking in to passing an array for query in filter.  
Thanks

---

<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:** [November 25, 2019, 12:10pm UTC](https://discuss.elastic.co/t/upper-case-and-lower-case-string-giving-different-results-for-filter/205260/4 "2019-11-25T12:10:52Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
