Cam*_*tin 9 ruby ruby-on-rails elasticsearch ruby-on-rails-4 elasticsearch-plugin
我在Rails 4中通过elasticsearch-rails使用ElasticSearch(https://github.com/elasticsearch/elasticsearch-rails)
我有一个用户模型,带有电子邮件属性.
我正在尝试使用文档中描述的'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
Run Code Online (Sandbox Code Playgroud)
我按照wiki(https://github.com/elasticsearch/elasticsearch-rails/wiki)和elasticsearch-model docs(https://github.com/elasticsearch/elasticsearch-rails/wiki)中的示例进行了操作.
它不起作用.如果我直接查询elasticsearch:
curl -XGET 'localhost:9200/users/_mapping
Run Code Online (Sandbox Code Playgroud)
它返回:
{
"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"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Cam*_*tin 15
这最终成为我创建索引的一个问题.我在努力:
User.__elasticsearch__.client.indices.delete index: User.index_name
User.import
Run Code Online (Sandbox Code Playgroud)
我希望这会删除索引,然后重新导入值.但是我需要这样做:
User.__elasticsearch__.create_index! force: true
User.import
Run Code Online (Sandbox Code Playgroud)