Case-sensitive search and custom analyzer

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???

Is that what you are looking for?

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"
    }
  }
}
1 Like

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??