我有一个ruby代码块,如下:
require "elasticsearch"
require "json"
search_term = "big data"
city = "Hong Kong"
client = Elasticsearch::Client.new log: true
r = client.search index: 'candidates', body:
{
query: {
bool: {
must: [
{
match: {
tags: search_term
}
},
{
match: {
city: city
}
}
]
}
}
}
它会产生多个返回,如下所示:
{"_index":"candidates","_type":"data",
"_id":"AU3DyAmvtewNSFHuYn88",
"_score":3.889237,
"_source":{"first":"Kota","last":"Okayama","city":"Tokyo","designation":"Systems Engineer","email":"[email protected]","phone":"phone","country":"Japan","industry":"Technology","tags":["remarks","virtualization big data"]}}
我想迭代它并提取各种元素。我努力了
data = JSON.parse(r)
data.each do |row|
puts row["_source"]["first"]
end
错误是:
no implicit conversion of Hash into String (TypeError)
解决这个问题的最佳方法是什么?