2013-12-12 14 views
0

我已成立的指數是這樣的: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。也不起作用。

+1

看起來很奇怪,我可以使用你的映射和查詢沒有任何問題,它會爲[email protected]返回正確的數據。我正在使用ES 0.90.5。您可以安裝插件:https://github.com/jotitan/elasticsearch-inquisitor,並檢查您的情況('hello','host.com'或'hello @ host.com')的實際索引。 –

+0

對不起@Duc。 Duong在提交我的答案時沒有看到您的評論。但是,我同意你的看法 - 它應該起作用。 – imotov

回答

2

看起來工作得很好對我說:

curl -XDELETE "localhost:9200/testindex?pretty" 
curl -XPOST "localhost:9200/testindex?pretty" -d ' 
{ 
    "settings": { 
     "analysis": { 
      "analyzer": { 
       "analyzer_keyword": { 
        "tokenizer": "keyword" 
       } 
      } 
     } 
    }, 
    "mappings": { 
     "users": { 
      "properties": { 
       "email": { 
        "analyzer": "analyzer_keyword", 
        "type": "string" 
       } 
      } 
     } 
    } 
}' 
curl -XPOST "localhost:9200/testindex/users?pretty&refresh" -d '{"email": "[email protected]"}' 
curl -XGET "localhost:9200/testindex/users/_search?pretty" -d '{ 
    "query" : { 
     "term" : { "email" : "[email protected]" } 
    } 
}' 

返回:

{ 
    "error" : "IndexMissingException[[testindex] missing]", 
    "status" : 404 
} 
{ 
    "ok" : true, 
    "acknowledged" : true 
} 
{ 
    "ok" : true, 
    "_index" : "testindex", 
    "_type" : "users", 
    "_id" : "GkPG9l83RGyeMyGM9x6ecQ", 
    "_version" : 1 
} 
{ 
    "took" : 62, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 5, 
    "successful" : 5, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 1, 
    "max_score" : 0.30685282, 
    "hits" : [ { 
     "_index" : "testindex", 
     "_type" : "users", 
     "_id" : "GkPG9l83RGyeMyGM9x6ecQ", 
     "_score" : 0.30685282, "_source" : {"email": "[email protected]"} 
    } ] 
    } 
} 
兩個0.90.7和當前主

。您是否嘗試在更改映射之前刪除索引?

+0

mh ..看起來很奇怪,現在它適用於你的例子。謝謝! – tester

+0

在谷歌Chrome的插件Sense中,它工作正常。但是如果我使用像https://github.com/guzzle/guzzle這樣的php客戶端,我會得到不止一個結果,如果我有'hello @ host.com'和'hi @ host.com' – tester

+1

GET或POST方法搜索guzzle?如果您正在使用GET,請嘗試使用POST來查看它是否解決了問題。 – imotov