2016-06-10 35 views
0
GET candidates1/candidate/_search 
{ 
    "fields": ["contactInfo.emails.main"], 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "match": { 
      "contactInfo.emails.main": "com" 
      } 
     } 
     ] 
    } 
    } 
} 

GET candidates1/candidate/_search 
{ 
    "size": 5, 
    "fields": [ 
    "contactInfo.emails.main" 
    ], 
    "query": { 
    "match": { 
     "contactInfo.emails.main": "com" 
    } 
    } 
} 

嗨, 當我使用我得到像[「[email protected]」,'arelysf456 @ gmai1結果上面的查詢.com','[email protected]']但我沒有收到['[email protected]','[email protected]','[email protected]']鬆緊搜索郵件搜索匹配COM

但是,當我使用查詢匹配「gmail.com」,我得到的結果有gmail.com

所以我的問題是,當我在第一個查詢中使用「com」時,我期待包含gmail.com的結果作爲「com」存在於gmail.com中。但是,這並沒有發生

注意:我們有近2百萬emailid,其中大部分是gmail.com,yahoo.com或hotmail,但只有少數是其他類型。

回答

1

「contactInfo.emails.main」字段似乎是analyzed field

在elasticsearch中,所有字符串字段都使用Standard Analyzer進行分析並轉換爲令牌。您可以使用analyze api查看您的文本是如何分析的。電子郵件由您在com之前以編號結尾的Ids被分析爲nraheem,dbtech1,com。使用以下查詢來查看tokens

curl -XGET 'localhost:9200/_analyze' -d ' 
{ 
"analyzer" : "standard", 
"text" : "[email protected]" 
}' 

正如你所看到的,有一個單獨的術語com被創建。而如果你分析[email protected],你會得到tokens,如kumargmail.com。在這種情況下沒有單獨的令牌com

這是因爲Standard Analyzer在遇到一些特殊字符如@,?等或號碼時也會將其分開。您可以創建custom Analyzer以符合您的要求。

希望這有助於!