What is the best way to build a case-insensitive search?

Hi, Everyone. I’m new to this topic, so sorry, if this is a stupid question
I want to build a free text search using Atlas Search. It should look like:
i have to fields for search name, email.
And for example, if I pass mike I want to get something like mike@… mike23 23mike@…. BUT NOT mikke, miike ← I get it if using autocomplete.
What is the best way to build a case-insensitive search? using regex? if so how to do a case-insensitive search?
Thanks for helping!

If you are looking for exact matches - I’d consider one of these options in this tutorial.

If specifically, you are looking to search on emails, I’d suggest using our email tokenizer.

To test our which analyzer works best, check out this tutorial.

1 Like

Thanks a lot, but I want to have a partial match. For example
if I pass Mike Krav – I want to get → Mike Kravets MikeKravert, BUT NOT Mike Kral Mike Kraavv
For example like on the screen, I get some correct results, but also a Simon Halep - what is not good for me

Can you share the index and query you are using that is driving those results?

1 Like


"wholeName": [
          "type": "string"
          "foldDiacritics": false,
          "maxGrams": 7,
          "minGrams": 4,
          "tokenization": "nGram",
          "type": "autocomplete"


     "$search": {
        "index": "free-text",
            "autocomplete": {
                "path": "wholeName",
                "query": f"{search_value}",

Is the goal to search on names or emails or both? And if both, is there one that is higher priority to match or must it match both in order to be returned?

I’m pondering if maybe you want to use a compound query and set a minimumShouldMatch… And perhaps for your whole name field use keyword analyzer but for your email, use maybe standard analyzer with a email tokenizer?

1 Like

yes, I want to search by email fields and wholeName, I put only wholeName just for example, sorry if it was misunderstood.
So, first I would like make it works only with wholeName

For that also should work regex, isn’t it? but regex based on keywords is case-sensitive, which is not good for me. and if I tried to do regex based on simple or standard, it wasn’t work
Thank you for helping

Hi @Mike_Kravets , to clarify, are you looking for exact matching for wholeName and then partial matching/autocomplete with email?

I want to have something like a case-insensitive $regex in MongoDB. but not sure what is the best way how to do it.

{"$regex": search_field, “$options”: “i”}}