Is there a way to make elasticsearch case-insensitive without altering the existing documents?
By Default, the fields are case-insensitive because of the mapping elastic applied.
Try below:
PUT myindex/doc/1{ "name":"TEST"}GET myindex/_mapping
It should return :
{ "myindex": { "mappings": { "doc": { "properties": { "name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } } } }}
Now if you query with below, it will return a match (notice the mapping[text and keyword]):
POST myindex/_search{ "query": { "match": { "name2": "test" } }}
Now, if you explicitly specify to index the field as keyword
, then it will be case-sensitive search. Try below and see; it will not return any results.
PUT myindex/_mapping/doc{ "properties": { "name2": { "type": "keyword" } }}PUT myindex/doc/1{ "name2":"TEST"}POST myindex/_search{ "query": { "match": { "name2": "test" } }}
TLDR; Use default mapping or text
type- if you specify the field to index only keyword
type, it will be case-sensitive.