我通过 elasticsearch-rails ( https://github.com/elasticsearch/elasticsearch-rails )在 Rails 4 中使用 ElasticSearch
我有一个带有电子邮件属性的用户模型。
我正在尝试使用文档中描述的“uax_url_email”标记器:
class User < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
settings analysis: { analyzer: { whole_email: { tokenizer: 'uax_url_email' } } } do
mappings dynamic: 'false' do
indexes :email, analyzer: 'whole_email'
end
end
end
我遵循了 wiki ( https://github.com/elasticsearch/elasticsearch-rails/wiki ) 和 elasticsearch-model 文档 ( https://github.com/elasticsearch/elasticsearch-rails/wiki ) 中的示例来达到这个目的.
它不起作用。如果我直接查询elasticsearch:
curl -XGET 'localhost:9200/users/_mapping
它返回:
{
"users": {
"mappings": {
"user": {
"properties": {
"birthdate": {
"type": "date",
"format": "dateOptionalTime"
},
"created_at": {
"type": "date",
"format": "dateOptionalTime"
},
"email": {
"type": "string"
},
"first_name": {
"type": "string"
},
"gender": {
"type": "string"
},
"id": {
"type": "long"
},
"last_name": {
"type": "string"
},
"name": {
"type": "string"
},
"role": {
"type": "string"
},
"updated_at": {
"type": "date",
"format": "dateOptionalTime"
}
}
}
}
}
}