Reputation: 2811
I've a field with email ids, when I try to match the whole email id, it doesn't match the document, but when I don't include @ the document matches. I tried replacing @ with . and *, none of them helped in matching.
How do I match whole email?
Eg doc:
{
...
"email": "[email protected]"
}
Eg failure query:
{
"query": {
"query_string": {
"default_field": "email",
"query": "*[email protected]*"
}
}
}
Eg success query:
{
"query": {
"query_string": {
"default_field": "email",
"query": "*ample*"
}
}
}
Upvotes: 0
Views: 784
Reputation: 32386
As already mentioned by Richie in another post, here it wasn't matching your search query as, default analyzer in Elastic is standard
analyzer, which removes the special character from the text, during tokenization process.
You need to do below things in order to make it work.
Define custom analyzer which uses the UAX URL tokenizer
Use your custom analyzer on the fields where you want @
to be searchable. Define this in your ES schema.
http://localhost:9200/{your_index_name}/_mapping
where replace your_index_name with your index name and verify the fields now uses, custom analyzer.@
.Let me know if you face any issue implementing this.
Upvotes: 1
Reputation: 554
Yes, so from https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-uaxurlemail-tokenizer.html you can see that Standard analyzer makes
POST _analyze
{
"text": "Email me at [email protected]"
}
to
[ Email, me, at, john.smith, global, international.com ]
That uax_url_email analyzer makes
[ Email, me, at, [email protected] ]
Upvotes: 0