2014-08-29 81 views
0

我想宝石迁移从轮胎(退役)至Elasticsearch持久性的宝石,在轮胎我用于设置从模型内的索引设置如下所示Elasticsearch:轮胎到Elasticsearch持久性迁移

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 

UPDATE:

当我发出

REPOSITORY.create_index! force: true 

更改应用,但我认为在elasticsearch的设置弄乱,如图截图(从头部插件抢下) enter image description here

回答

0

你有没有考虑过只是使用elasticsearch/elasticsearch-model - 它提供了automatic callbacks,它可以帮助你保存数据。

+0

我目前我正在使用“包括Tire :: Model :: Persistence”保持我的模型,我仍然使用Tire,因为它可以选择搜索多个索引,而不像新宝石 – 2014-08-29 19:00:48

+1

Well Tire已经过时并且作为其新名称建议也退休了。因此,从长远来看,您应该切换到“官方”ElasticSearch宝石或使用类似strecher的东西。另一方面,Strecher已经支持多种搜索。其他选项是只通过'手'搜索查询多个索引... $ curl -XGET'http:// localhost:9200/index_a,index_b/tweet/_search?q = tag:哇' – 2014-08-29 19:09:10

+0

同意但是这并没有解决最初的问题,我已经更新了这个问题,设置应该如何看待,还是应该以JSON结构呈现? – 2014-08-29 19:14:53

0

当使用elasticsearch宝石库对象,我们应该发出

REPOSITORY.create_index! 

这将创建与提供的设置索引,你可以添加force: true,如果你想重新创建索引再次

相关问题