Elasticsearch case insensitive to not_analyzed index

Hi,

I am using not_analyzed index for performing exact word search but not_analyzed index make search case sensitive. I also tried analyzer setting:

"settings" : {
"index" : {
"creation_date" : "1466062045942",
"analysis" : {
"analyzer" : {
"analyzer_keyword" : {
"filter" : [ "lowercase" ],
"type" : "custom",
"tokenizer" : "keyword"
}
}
},
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "kx7We-gRSGCXU1u6PZF5xQ",
"version" : {
"created" : "2030199"
}
}

But it doesn't work.
Please help me to make search exact word and case-insensitive.

Thanks
Tarlok

Hey,

please create full reproduction of the steps that you did. The above snippet does have any information where you used that analyzer in your mapping, as you need to conifgure it for the field you want to use it for.

--Alex

Hi Alexander,

I have mapped fields to not_analyzed index as I want exact word search. Below is mapping :

"mappings" : {
"tweet" : {
"properties" : {
"Message" : {
"type" : "string"
"index" : "not_analyzed"
},
"User" : {
"type" : "string"
"index" : "not_analyzed"
}
}
}
}

Analyzer setting is:

"settings" : {
"index" : {
"creation_date" : "1466062045942",
"analysis" : {
"analyzer" : {
"analyzer_keyword" : {
"filter" : [ "lowercase" ],
"type" : "custom",
"tokenizer" : "keyword"
}
}
},
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "kx7We-gRSGCXU1u6PZF5xQ",
"version" : {
"created" : "2030199"
}
}

Then I am making query to get exact word search:

"filter": { "or": [ { "term": { "User": "Test" } },{ "term": { "Message": "Test" } } ] }

It is working fine but when I am trying with "test" the it is returning 0 result. So basically case-insensitive search is not working for exact word.

Please let me know if there is a way to achieve this.

Thanks
Tarlok

Hi @tarlok,

somebody asked the exact same question just two days ago. Please check the related thread.

Daniel

Hi Daniel,

Thanks for your suggestion. Performance is very important in our application. We are changing from solr to elastic because of performance. So I don't want to slow down performance. Please let me know if there is any other solution for this.

Thanks
Tarlok

Hi @tarlok,

the suggested approach is to use multiple fields as I suggested in my first answer in that post. Queries will be fast then but of course the additional field will require additional disk space in the index.

Daniel

Hey,

you are not using the defined analyzer_keyword in your mapping for any of the fields, so it never gets applied. See the analyzer documentation

--Alex

Hi Daniel/Alexander,

Thanks for your help. It is working fine now :smile: .

My setting is:
"settings" : {
"index" : {
"creation_date" : "1466141139185",
"analysis" : {
"analyzer" : {
"case_insensitive" : {
"filter" : [ "lowercase" ],
"type" : "custom",
"tokenizer" : "keyword"
}
}
},
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "htjDOddeTTO2JC33BZ6fmQ",
"version" : {
"created" : "2030199"
}
}
}

My mapping is:
"mappings" : {
"tweet" : {
"dynamic" : "false",
"_all" : {
"enabled" : false
},
"properties" : {
"Message" : {
"type" : "string",
"analyzer" : "case_insensitive"
},
"User" : {
"type" : "string",
"analyzer" : "case_insensitive"
}
}
}
}

I am just converting user input to lower-case. Below is my query:
"filter": { "or": [ { "term": { "User": "test" } },{ "term": { "Message": "test" } } ] }

This query shows exact word result with case-insensitivity.

Thanks
Tarlok