在SQL中,我可以使用SQL LIKE很好地搜索电子邮件地址。
使用电子邮件“stack@domain.com”,搜索“堆叠”,“@ domain.com”,“domain.com”或“域名”会让我找回所需的电子邮件地址。
如何使用ElasticSearch获得相同的结果?
我玩过nGram,edgeNGram,uax_url_email等,搜索结果非常糟糕。如果我错了,请纠正我,听起来我必须做以下事情:
一个实验代码
tire.settings :number_of_shards => 1,
:number_of_replicas => 1,
:analysis => {
:filter => {
:db_ngram => {
"type" => "nGram",
"max_gram" => 255,
"min_gram" => 3 }
},
:analyzer => {
:string_analyzer => {
"tokenizer" => "standard",
"filter" => ["standard", "lowercase", "asciifolding", "db_ngram"],
"type" => "custom" },
:index_name_analyzer => {
"tokenizer" => "standard",
"filter" => ["standard", "lowercase", "asciifolding"],
"type" => "custom" },
:search_name_analyzer => {
"tokenizer" => "whitespace",
"filter" => ["lowercase", "db_ngram"],
"type" => "custom" },
:index_email_analyzer => {
"tokenizer" => "whitespace",
"filter" => ["lowercase"],
"type" => "custom" }
}
} do
mapping do
indexes :id, :index => :not_analyzed
indexes :name, :index_analyzer => 'index_name_analyzer', :search_analyzer => 'search_name_analyzer'
indexes :email, :index_analyzer => 'index_email_analyzer', :search_analyzer => 'search_email_analyzer'
end
end
不能正常运作的特定情况:
假设我有“aaa@email.com”,“aaa_0 @email.com”和“aaa-0@email.com,搜索”aaa“给我”aaa@a.com“”aaa-0 @ email.com。搜索“aaa *”给了我一切,但“aaa- *”没有给我任何东西。那么,我该怎么做完全匹配通配符查询?对于这些类型的查询,我得到了与不同的tokenizer / analyzer相同的结果。
我在每次映射更改后执行以下操作: Model.tire.index.delete Model.tire.create_elasticsearch_index Model.tire.index.import Model.all
参考文献: