我已成立的指數是這樣的:Elasticsearch的關鍵詞分詞和搜索電子郵件並未真正發揮作用
POST /testindex/ -d '
{
"settings": {
"analysis": {
"analyzer": {
"analyzer_keyword": {
"tokenizer": "keyword"
}
}
}
},
"mappings": {
"users": {
"properties": {
"email": {
"analyzer": "analyzer_keyword",
"type": "string"
}
}
}
}
}'
現在我而用戶包含電子郵件地址添加了一些users
文件testindex
。如果我想通過指定類似下面的電子郵件地址搜索用戶文件,它並沒有真正按預期工作:
GET /testindex/users/_search
{
"query" : {
"term" : { "email" : "[email protected]" }
}
}
該查詢返回0的結果。但如果我說"email": "hello"
或"email": "host.com"
它返回確切的文檔。但是@
有什麼問題?如何通過完整的電子郵件地址進行搜索?
elasticsearch documentation說: A tokenizer of type keyword that emits the entire input as a single input.
整個輸入是[email protected]
。我也試過uax_url_email
tokenizer。也不起作用。
看起來很奇怪,我可以使用你的映射和查詢沒有任何問題,它會爲[email protected]返回正確的數據。我正在使用ES 0.90.5。您可以安裝插件:https://github.com/jotitan/elasticsearch-inquisitor,並檢查您的情況('hello','host.com'或'hello @ host.com')的實際索引。 –
對不起@Duc。 Duong在提交我的答案時沒有看到您的評論。但是,我同意你的看法 - 它應該起作用。 – imotov