You are right that match
queries can be used for case-insensitive search as it applied the same analyzer which was used at index time but works only for text
field.
Problem here is that while indexing, as you have used keyword
field, so tokens in elasticsearch inverted index, which is used to match the tokens of search query are not lowercased
so it is not possible at all to provide case-insensitive search.
Let's understand above statement using an example:
Let's suppose you have Foo BAR
in your document, which you indexed using keyword
field. Please note the case of each character, so inverted index will have below token.
Foo BAR
, now at query time by some hook or crook, you can convert search term to either all uppercase or lowercase but in this case still it won't match the tokens, so you will still have a lot of issues in search results.
I would suggest, add a new field which uses text
and using reindex API create a fresh index and implement it in clean manner, also using reindex API, you can build a new index from old index, and its much faster to build a new index, rather than build from source of truth(SQL in most cases).