Elasticsearch 模糊電子郵件或電話匹配
問題:
問題:問題:
如何實現模糊使用Elasticsearch 取得電子郵件地址或電話號碼?具體來說,如何匹配以“@gmail.com”結尾的所有電子郵件或以“136”開頭的所有電話號碼?
答案:搜尋分析器:search_email_analyzer
標準分詞器
搜尋分析器:search_phphone_analyzer_phphone
僅數字過濾器PUT myindex { "settings": { "analysis": { "analyzer": { "email_url_analyzer": { "type": "custom", "tokenizer": "uax_url_email", "filter": [ "trim" ] }, "index_phone_analyzer": { "type": "custom", "char_filter": [ "digit_only" ], "tokenizer": "digit_edge_ngram_tokenizer", "filter": [ "trim" ] }, "search_phone_analyzer": { "type": "custom", "char_filter": [ "digit_only" ], "tokenizer": "keyword", "filter": [ "trim" ] }, "index_email_analyzer": { "type": "custom", "tokenizer": "standard", "filter": [ "lowercase", "name_ngram_filter", "trim" ] }, "search_email_analyzer": { "type": "custom", "tokenizer": "standard", "filter": [ "lowercase", "trim" ] } }, "char_filter": { "digit_only": { "type": "pattern_replace", "pattern": "\D+", "replacement": "" } }, "tokenizer": { "digit_edge_ngram_tokenizer": { "type": "edgeNGram", "min_gram": "1", "max_gram": "15", "token_chars": [ "digit" ] } }, "filter": { "name_ngram_filter": { "type": "ngram", "min_gram": "1", "max_gram": "20" } } } }, "mappings": { "your_type": { "properties": { "email": { "type": "string", "analyzer": "index_email_analyzer", "search_analyzer": "search_email_analyzer" }, "phone": { "type": "string", "analyzer": "index_phone_analyzer", "search_analyzer": "search_phone_analyzer" } } } } }
關鍵字標記器
POST myindex { "query": { "term": { "email": "@gmail.com" } } }
POST myindex { "query": { "term": { "phone": "136" } } }
以上是如何在 Elasticsearch 中實現電子郵件地址和電話號碼的高效模糊匹配?的詳細內容。更多資訊請關注PHP中文網其他相關文章!