【发布时间】:2014-08-01 20:30:18
【问题描述】:
我正在使用 sinatra 和 postgres。我想索引一个 postgres 数据库。
ruby 代码是:
get '/elastic_data' do
client = Elasticsearch::Client.new log: true
candidates.select(:id, :first, :last, :email, :industry).map do |row|
@first = row[:first]
puts @first
@industry = row[:industry]
puts @industry
result = {first:@first, industry:@industry}.to_json
client.index index: 'people', type: 'py', id: 1, body: result
end
end
当我运行它时,在终端中我得到了如下所示的格式良好的 json:
Eric
Legal
2014-06-11 18:05:00 +0100: PUT http://localhost:9200/people/py/1 [status:200, request:0.004s, query:n/a]
2014-06-11 18:05:00 +0100: > {"first":"Eric","industry":"Legal"}
2014-06-11 18:05:00 +0100: < {"ok":true,"_index":"people","_type":"py","_id":"1","_version":10143}
Kewu
Legal
2014-06-11 18:05:00 +0100: PUT http://localhost:9200/people/py/1 [status:200, request:0.002s, query:n/a]
2014-06-11 18:05:00 +0100: > {"first":"Kewu","industry":"Legal"}
2014-06-11 18:05:00 +0100: < {"ok":true,"_index":"people","_type":"py","_id":"1","_version":10144}
然后我收到一条错误消息:
NoMethodError at /elastic_data
undefined method `bytesize' for #<Hash:0x9228f40>
2 个问题:
- 出了什么问题,我该如何解决?
- elasticsearch ruby gem 是否有“更新”命令,以便我可以在每次有新记录时更新索引,还是每次搜索时都必须重新索引数据库?
非常感谢您的帮助。
【问题讨论】:
标签: ruby postgresql elasticsearch sinatra