2

I am trying to implement email search with ElasticSearch.
Here are the example documents.

{
  ...  
  "email": "valeri@gmail.com" 
},
{
  ...
  "email": "tom@gmail.com"
}

So when I use the match query: { "match": { "email": "valeri@gmail.com" } }
I get both of "valeri@gmail.com"and "tom@gmail.com" but the result must be only "valeri@gmail.com".

I think it is because of @ character.
Any good solution to resolve this issue?

KayV
  • 12,987
  • 11
  • 98
  • 148
Valeri
  • 1,072
  • 5
  • 14
  • 31
  • This answer should help: https://stackoverflow.com/questions/35124725/emails-not-being-searched-properly-in-elasticsearch/35124883#35124883 – Val Nov 15 '17 at 05:40
  • Here is the relevant answer too https://stackoverflow.com/questions/30115867/elasticsearch-analyzer-and-tokenizer-for-emails – KayV Nov 15 '17 at 05:47

2 Answers2

1

You need to use the Email Tokenizer as specified here:

https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-uaxurlemail-tokenizer.html

KayV
  • 12,987
  • 11
  • 98
  • 148
  • How can we define the custom analyzer using javascript(Node.js elasticsearch npm module)? – Valeri Nov 15 '17 at 06:05
  • @Valeri You can define custom analyzer as client.indices.create({ index: "wcm-posts", body: { "settings": { "analysis": { "analyzer": { "my_analyzer": { "tokenizer": "my_tokenizer" } }, "tokenizer": { "my_tokenizer": { "type": "uax_url_email", "max_token_length": 5 } } } }, "mappings": { "aType": { "properties": { "email": { "type": "text", "fields": { "keyword": { "type": "keyword" }, "email": { "type": "text", "analyzer": "my_analyzer" } }, "include_in_all": True } } } } } }) – swapnil2993 Nov 15 '17 at 06:57
0

Use this to make your request

GET my_index/_search
{
    "query": {
        "match_phrase_prefix" : {
            "email": "valery@gmail.com"
        }
    }
}

You will have the expecting result

Boston Kenne
  • 778
  • 10
  • 15