Case insensitive search on not analyzed fields

Hi,

I googled about case sensitivity of ES searches and got this:

  1. "You'll need to analyze a field to search case-insensitive."
  2. "If you want to make a case insensitive search you should use match query"

Are 1 and 2 correct?

and moreover my question

  1. Is there a way to make case INsensitive search on not analyzed string fields? Or do I've do use an analyzer with lowercase tokenizer (simple for example)?

Thanks for your help!

1 Like

You'd use the keyword tokenizer with a lowercase token filter and a match query, yes.

You could also lowercase the field on the way in, maybe with an ingest pipeline (whenever 5.0 is ready) and then use a match query with an analyzer that uses the keyword tokenizer and the lowercase token filter. The advantage of this way is that you can still use field data with the field. Though, early in 5.0 (like 5.1 or 5.2), keyword fields will be able to use field data anyway so it might be moot.

There are other much less efficient, much more labor intensive ways to do it like making a plugin that turns one query into the union of a zillion (2^length) queries which permute the case. Or something in between.

There are always tradeoffs and the standard way of doing things with Elasticsearch almost always goes with the "use more time and space for indexing to make searching faster".

Thanks a lot for the answer!

So match query does not guarantees case INsensitivity on its own. I have to set an analyzer on the field that I want to match as case-insensitive. Am I right?