# Case-sensitive search and custom analyzer

**URL:** <https://discuss.elastic.co/t/case-sensitive-search-and-custom-analyzer/200399>\
**Category:** Elasticsearch\
**Created:** [September 20, 2019, 10:59am UTC](https://discuss.elastic.co/t/case-sensitive-search-and-custom-analyzer/200399 "2019-09-20T10:59:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohammad.ali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mohammad.ali/32/45665_2.png) [@Mohammad.ali](https://discuss.elastic.co/u/Mohammad.ali)\
**Post date:** [September 20, 2019, 10:59am UTC](https://discuss.elastic.co/t/case-sensitive-search-and-custom-analyzer/200399/1 "2019-09-20T10:59:55Z")

</div>

Hello every one  
I have been trying to activate case sensitive search in elasticsearch and what i found is it depend on type of analyzer. so i create a custom analyzer:

PUT test\_index  
{  
"settings": {  
"analysis": {  
"analyzer": {  
"my\_custom\_analyzer": {  
"type": "custom",  
"tokenizer": "standard",  
"filter": ["stop", "porter\_stem"]

```
    }
  }
}

```

}  
}  
after that i indexed some document to my test index in field message:  
error  
[ERROR]  
ErrorSome  
SomeERROR  
what i am trying to do is to find out the document which only contain ERROR term not error or Error(exactly the word ERROR).so i wrote this query:

GET /test\_index/\_search  
{  
"query": {  
"query\_string": {  
"default\_field": "message",  
"query": "ERROR"  
}  
}  
}  
this query give me all document which contain the word error and does not care it is upper case or lower case  
what is the problem??am i looking to right direction to solve the problem??is it related to analyzer???

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 20, 2019, 11:28am UTC](https://discuss.elastic.co/t/case-sensitive-search-and-custom-analyzer/200399/2 "2019-09-20T11:28:56Z")

</div>

Is that what you are looking for?

```auto
DELETE test 
PUT test
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_custom_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "stop",
            "porter_stem"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "message": {
        "type": "text",
        "analyzer": "my_custom_analyzer"
      }
    }
  }
}
POST test/_doc
{
  "message": "error"
}
POST test/_doc
{
  "message": "[ERROR]"
}
POST test/_doc
{
  "message": "ErrorSome"
}
POST test/_doc
{
  "message": "SomeERROR"
}
GET test/_search
{
  "query": {
    "match": {
      "message": "ERROR"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Mohammad.ali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mohammad.ali/32/45665_2.png) [@Mohammad.ali](https://discuss.elastic.co/u/Mohammad.ali)\
**Post date:** [September 20, 2019, 2:05pm UTC](https://discuss.elastic.co/t/case-sensitive-search-and-custom-analyzer/200399/3 "2019-09-20T14:05:15Z")

</div>

Thanks alot.. Yes it worked.. I thought when i defined the customer analyzer then it applied as default analyzer to all field and i do not need mapping..  
If i want to consider speciall character such as [or] then i need to define another tokenizer?? Which one do you recommend??

---

<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:** [October 18, 2019, 2:05pm UTC](https://discuss.elastic.co/t/case-sensitive-search-and-custom-analyzer/200399/4 "2019-10-18T14:05:21Z")

</div>

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