Reputation: 8821
I want to use wildcard to search email in Elasticsearch.
For example:
{
"query": {
"wildcard": {
"email": "*yahoo*"
}
}
}
I can get all contains yahoo
emails. But if I search like this, no document return.
{
"query": {
"wildcard": {
"email": "*@yahoo*"
}
}
}
I don't understand why like this. Anyone can help me?
Thanks in advance!
Upvotes: 2
Views: 441
Reputation: 7649
Standard Analyzer is the culprit in your case.
email
field in your index seems to be analyzed
string. So when you index it it will split into somemail
, yahoo.com
and these two tokens will be saved in reverse index
. That's why you were not able to search with @yahoo
.
You can use analyze
api to see how your term is getting tokenized.
curl -XGET "http://localhost:9200/_analyze?tokenizer=standard" -d "[email protected]"
You will get following output:
{"tokens":[{"token":"test","start_offset":0,"end_offset":4,"type":"<ALPHANUM>","position":0},{"token":"yahoo.com","start_offset":5,"end_offset":13,"type":"<ALPHANUM>","position":1}]}
You can use uax_url_email if you want to search with @yahoo
Hope this helps!!
Upvotes: 3