Elasticsearch不会将文档添加到新索引

时间:2014-08-26 22:11:23

标签: ruby-on-rails ruby elasticsearch tire

我正在使用Tire(现在退休)索引我从套接字接收的文档,我每天通过修改Model.index_name创建一个新索引,新索引创建成功但文档没有添加到它也没有它被添加到旧索引中。我必须执行以下解决方法才能使其正常工作

  • 停止佣金任务(套接字脚本)
  • 删除新创建的索引
  • 启动佣金任务

然后创建索引并以正常方式插入文档

请参阅我的模型和我的rake索引脚本

型号:

class LogEntry

 include Tire::Model::Persistence
 index_name {"ip_logstreams_#{Time.now.year}_#{Time.now.month}_#{Time.now.day}"}
 ....
end

Rake Script:

require 'socket'
require 'net/http'

namespace :offline_logger do
 desc ""

 task :log_listener => :environment do
  begin
   u1 = UDPSocket.new
   u1.bind( '', 3007)
   while (true)
    begin
     now_time = Time.now
     message_array = u1.recvfrom(10000)
     Thread.new do
      message = message_array[0][2..10000]
      message = message.gsub(/\s+/m, ' ').strip.split(" ")
      msgdatetime = message[0].split(">")[1] +" " + message[1]
      msgpriority = message[2]
      msghostname = message[3]
      i = 4
      msgtext = ''
      while i < message.length
       msgtext = msgtext + message[i] + " "
       i = i + 1
      end
      LogEntry.index_name "ip_logstreams_#{now_time.year}_#{now_time.month}_#{now_time.day}"
      tr = LogEntry.new( :msgdatetime=> Time.parse(msgdatetime), :msgpriority => msgpriority, :msghostname=> msghostname,:msgtext=> msgtext)
      tr.update_index
    end
    rescue => e
     p e.message
    end
   end
  end
 end
end

这是正确的做法吗?线程可以成为负担吗?

0 个答案:

没有答案