[英]ElasticSearch Rails - Setting a Custom Analyzer
我正在通过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"
}
}
}
}
}
}
这最终成为我如何创建索引的问题。 我正在尝试:
User.__elasticsearch__.client.indices.delete index: User.index_name
User.import
我希望这会删除索引,然后重新导入值。 但是我需要做:
User.__elasticsearch__.create_index! force: true
User.import
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.