gpt4 book ai didi

ruby-on-rails - ElasticSearch Rails - 设置自定义分析器

转载 作者:数据小太阳 更新时间:2023-10-29 06:48:55 27 4
gpt4 key购买 nike

我通过 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

关于ruby-on-rails - ElasticSearch Rails - 设置自定义分析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25258121/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com