【问题标题】:Elasticsearch: Tire to Elasticsearch Persistence migrationElasticsearch:轮胎到 Elasticsearch 持久性迁移
【发布时间】:2014-10-23 19:56:30
【问题描述】:

我想从 Tyre (retire) gem 迁移到 Elasticsearch Persistence gem,在轮胎中我曾经从模型内部设置索引设置,如下所示

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 对象,我想应用相同的设置(主要是分析器)

下面的代码不起作用,即使我改变了分片的数量,就好像我什么都没写一样

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 插件中获取)

【问题讨论】:

    标签: ruby-on-rails ruby elasticsearch tire


    【解决方案1】:

    您是否考虑过只使用elasticsearch/elasticsearch-model - 它提供了automatic callbacks,可以帮助您持久化数据。

    【讨论】:

    • 我目前使用“include Tire::Model::Persistence”将我的模型与轮胎保持在一起,我仍在使用轮胎,因为它可以选择在多个索引中进行搜索,这与新 gem 不同
    • Well Tire 已经过时,正如它的新名称所暗示的那样,它也已退役。因此,从长远来看,您应该切换到“官方”ElasticSearch gem 或使用类似 strecher 的东西。另一方面,Strecher 已经支持多搜索。其他选择是通过“手”对多个索引进行搜索查询... $ curl -XGET 'localhost:9200/index_a,index_b/tweet/_search?q=tag:wow'
    • 同意,但这并不能解决最初的问题,我已经更新了问题,设置应该是这样还是应该以 JSON 结构呈现?
    • 这就是mapping/settings usually look。我使用关注来保持我的代码更干净。
    【解决方案2】:

    在 elasticsearch gem 中使用存储库对象时,我们应该发出

    REPOSITORY.create_index!
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-26
      • 2013-07-23
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      • 2012-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多