1

What is the best way to do full text search using Atlas? For example, I put mike@ and I want to see da.mike@gmail.com mike@gmail.com ... But not something like mikke@... mmike@..., such a result can show a search using autocomplete. As I understood, most likely I need to use regex

{
    "$search": {
        "index": "free-text",

        {
            "regex": {
                "path": "email",
                "query": ".*mike@.*",
            },
        },

    },
}

Before that I created search index:

"email": [{
        "tokenization": "nGram",
        "type": "autocomplete"
    },
    {
        "analyzer": "lucene.keyword",
        "type": "string"
    }
]

It works almost good, but it is a case-sensitive, and I can't find out how to send it as insensitive So, 1. Is there a better way how to build such a search?

2. if so, how to do a regex search insensitive to the case?

Thank you a lot for helping, guys!

Tru to create an index with autocomplete type, and build query as a phrase, regex, autocomplete, but the result was not good.

MORÈ
  • 2,480
  • 3
  • 16
  • 23
M Kravets
  • 51
  • 5

1 Answers1

1

For your email you can use a email-specific tokenizer: https://www.mongodb.com/docs/atlas/atlas-search/analyzers/tokenizers/#uaxurlemail

And then I'd recommend using a different analyzer instead of keyword to get case-insensitive. Check out this webtool to play around with the options (there's an email example in there)

elle
  • 46
  • 4