How to search by Email on Atlas Search

Hi all! Im having an issue that I cant find by email using Atlas Search.
This is what I built at the moment:

const suggestedFriends = await this.usersModel
      .aggregate<SuggestedFriends>()
      .search(
         {
           index: 'default',
           wildcard: {
             query: `${friendsQuery.q}*`,
             path: 'email',
             allowAnalyzedField: true,
           },
         }
      )

What im sending on the variable friendsQuery.q is “tomas@gmail.com” but not found nothing. I tried to use another collection that I have names and works properly, I mean the search index its working but not works on strings of emails :/. Someone faced this thing too?

Thank you so much!

Can you share your index definition?

We have an email tokenizer, which helps with this.

3 Likes

Thanks for quickly response here its my index definition

@tomas_ruffa That analyzer won’t work because the lucene.simple analyzer will strip the @ symbol and the . from the email.

In the visual editor, we do not support the custom analyzer you should build to support this use case.

It would look something like this:

{
  "analyzer": "lucene.simple",
  "mappings": {
    "dynamic": true,
    "fields": {
      "email": {
        "analyzer": "emailUrlExtractor",
        "searchAnalyzer": "emailUrlExtractor",
        "type": "string"
      }
    }
  },
  "analyzers": [
    {
      "charFilters": [],
      "name": "emailUrlExtractor",
      "tokenFilters": [
        {
          "type": "lowercase"
        }
      ],
      "tokenizer": {
        "maxTokenLength": 200,
        "type": "uaxUrlEmail"
      }
    }
  ]
}
2 Likes

Thank you so much Marcus I did this and added new refactors to that query by the Atlas UI and now works. Thanks @Elle_Shwer too for the help, both are the solution that I need :slight_smile:

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.