2014-08-29 127 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,如果你想重新創建索引再次