[英]Elasticsearch: Tire to Elasticsearch Persistence migration
我想从Tire(retire)gem迁移到Elasticsearch Persistence gem,在Tyre中,我曾经从模型内部设置索引设置,如下所示
settings :number_of_shards => 5,
:number_of_replicas => 1,
:analysis => {
:analyzer => {
:my_pattern => {
"type" => "custom",
"tokenizer" => "keyword",
"filter" => ["url_ngram", "lowercase"]
}
}, :filter => {
:url_stop => {
:type => "stop",
:stopwords => ["="]
},
:url_ngram => {
:type => "nGram",
:min_gram => 4,
:max_gram => 40
}
}
} do
mapping {
indexes :msgpriority, :type => 'string', :analyzer => 'snowball'
indexes :msghostname, :type => 'string', :analyzer => 'snowball'
indexes :msgtext, :type => 'string', :analyzer => 'my_pattern'
indexes :msgdatetime, :type => 'date', :include_in_all => false
}
end
现在,我正在使用存储库对象,并且我想应用相同的设置(主要是分析器)
即使更改了分片的数量,就像我什么都没写一样,下面的代码也不起作用
REPOSITORY = Elasticsearch::Persistence::Repository.new do
# Configure the Elasticsearch client
client Elasticsearch::Client.new url: ENV['ELASTICSEARCH_URL'], log: true
now_time = Time.now
# Set a custom index name
index "ip_logstreams_#{now_time.year}_#{now_time.month}_#{now_time.day}"
# Set a custom document type
type :log_entry
# Specify the class to inicialize when deserializing documents
klass LogEntry
# Configure the settings and mappings for the Elasticsearch index
settings number_of_shards: 2, :analysis => {
:analyzer => {
:my_pattern => {
"type" => "custom",
"tokenizer" => "keyword",
"filter" => ["url_ngram", "lowercase"]
}
}, :filter => {
:url_stop => {
:type => "stop",
:stopwords => ["="]
},
:url_ngram => {
:type => "nGram",
:min_gram => 4,
:max_gram => 40
}
}
} do
mapping {
indexes :msgpriority, :type => 'string', :analyzer => 'snowball'
indexes :msghostname, :type => 'string', :analyzer => 'snowball'
indexes :msgtext, :type => 'string', :analyzer => 'my_pattern'
indexes :msgdatetime, :type => 'date', :include_in_all => false
}
end
end
更新:
当我发出
REPOSITORY.create_index! force: true
应用了更改,但我认为elasticsearch中的设置被弄乱了,如屏幕截图所示(从head插件获取)
您是否考虑过仅使用elasticsearch / elasticsearch-model-它提供了自动回调 ,旨在帮助您持久保存数据。
在Elasticsearch gem中使用存储库对象时,我们应该发出
REPOSITORY.create_index!
这将使用提供的设置创建索引,您可以添加force: true
如果要再次重新创建索引,则为force: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.