我用的是辛纳特拉和波斯特格斯。我想索引postgres数据库。
红宝石代码是:
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个问题:
非常感谢您的帮助。
发布于 2014-06-11 17:26:06
你想要做的是非常不正统的--试图用相同的数据同步两个不同的存储库是很脆弱的,容易出错,而且会让人头疼。
从片段中显示的数据类型来看,我甚至没有看到用例,为什么不简单地将添加索引放到postgres表中呢?Postgres甚至支持全文搜索,因此即使您有使用elasticsearch的真正诱惑(毕竟--这是它的主要特性之一),对于大多数用例,postgres也可以。
在远程情况下,您绝对需要elasticsearch提供的postgres不提供的特性,我建议将此表完全移植到elasticsearch,而不是试图保持两个存储库保持同步.
https://stackoverflow.com/questions/24168747
复制相似问题