Searching not analyzed term name and value in case insensitive manner

@danielmitterdorfer By applying the keyword tokenizer, are we still guaranteed an exact match in the search result?

Hi @charyorde,

I am not sure what you mean by that. Can you please provide a concrete example?

Daniel

@danielmitterdorfer . Thanks for writing. I want to achieve exact match in search as well as maintain case insensitivity. So I'm wondering whether this makes sense.
{ "settings": { "analysis": { "analyzer": { "case_insensitive": { "tokenizer": "keyword", "filter": [ "lowercase" ] } } } }, "mappings" : { "pages" : { "properties" : { "firstname" : { "type" : "string", "index": "not_analyzed", "analyzer": "case_insensitive" } } } } }

If I remove "index": "not_analyzed", am I still guaranteed an exact match in the search result?

Hi @charyorde,

you are adding an analyzer to a not_analyzed field. This cannot work. I checked the behavior of Elasticsearch 2.4.4 and it happily accepts these settings in the create index request. However, it simply ignores your analyzer and treats the field as not_analyzed. Just try this:

PUT /my_index
{
   "settings": {
      "analysis": {
         "analyzer": {
            "case_insensitive": {
               "tokenizer": "keyword",
               "filter": [
                  "lowercase"
               ]
            }
         }
      }
   },
   "mappings": {
      "my_type": {
         "properties": {
            "name": {
               "type": "string",
               "index": "not_analyzed", 
               "analyzer": "case_insensitive"
            }
         }
      }
   }
}

Then do GET /my_index/_mapping and you'll see that Elasticsearch simply ignores your analyzer:

{
   "my_index": {
      "mappings": {
         "my_type": {
            "properties": {
               "name": {
                  "type": "string",
                  "index": "not_analyzed"
               }
            }
         }
      }
   }
}

I suggest you play around with the example that I've provided in my initial response, go through the thread and decide what fits your use-case best (I have a feeling that the mapping that I've provided in my initial response fits your use-case).

Daniel

Got it. Thanks