Hi @Wilfredo_Gomez - Welcome to the community 
When querying it, it seems to only return results if you query for the exact/entire email address. With emails of form “first.last+textDigit@company.com”, how can I query just parts of the email? Like “first”, “last” or even the text and digit parts.
One possible way to achieve this is using the following index definition below should be able to get you the email based off a partial match (small tweak to the index definition you have provided):
{
"analyzer": "emailUrlExtractor",
"searchAnalyzer": "emailUrlExtractor",
"mappings": {
"fields": {
"email": {
"type": "string"
}
}
},
"analyzers": [
{
"charFilters": [],
"name": "emailUrlExtractor",
"tokenFilters": [
{
"type": "lowercase"
},
{
"maxGram": 10,
"minGram": 2,
"type": "nGram"
}
],
"tokenizer": {
"type": "uaxUrlEmail"
}
}
]
}
Note: The index definition I have provided uses a field "email"
compared to the "user_email"
field you have specified. Adjust and test accordingly.
Output when searching for "first"
based off my test environment:
email> db.collection.aggregate
({
'$search': { index: 'email', text: { path: 'email', query: 'first' } }
})
[
{
_id: ObjectId("638ea1744d4a7d082dc9b8dd"),
email: 'first+last@email.com'
},
{
_id: ObjectId("638ea18b4d4a7d082dc9b8de"),
email: 'first.last+textDigit@company.com'
},
{
_id: ObjectId("6396aaf20333165f1d593199"),
email: 'FIRST.NAME.LAST.NAME@email.com'
}
]
You can alter the index definition accordingly based off your use case(s). I would recommend to test this thoroughly against a test environment if you believe it may be able to achieve what you are after and also to ensure it does meet all your requirements.
You may wish to also check the following Multi Analyzer documentation as you can use the multi
object in your index definition to specify alternate analyzers with which to also index the field.
Hope this helps.
Regards,
Jason