如何使用rest客戶端執行以下查詢(在doc中給出)。在elasticsearch中傳遞json數據使用rest-client ruby獲取請求gem
curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{
"query" : {
"term" : { "user" : "kimchy" }
}
}
'
我試着這樣做:
q = '{
"query" : {
"term" : { "user" : "kimchy" }
}
}
'
r = JSON.parse(RestClient.get('http://localhost:9200/twitter/tweet/_search', q))
這投擲了一個錯誤:
in `process_url_params': undefined method `delete_if' for #<String:0x8b12e18> (NoMethodError)
from /home/socialapps/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:40:in `initialize'
from /home/socialapps/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `new'
from /home/socialapps/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
from /home/socialapps/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient.rb:68:in `get'
from get_check2.rb:12:in `<main>'
當我使用RestClient.post
一樣的,它給了我正確的結果!但elasticsearch文檔在curl命令中使用XGET
作爲搜索查詢,而不是XPOST
。如何獲得RestClient.get
方法?
如果有更多/更好的方法來做這個動作,請建議。
我認爲這與get或post沒有任何關係,但是使用'''get_check2.rb'''中的代碼。使用RestClient從ES獲得的實際響應是什麼?這可能是你處理錯誤的方式! – phoet
即使使用POST請求,Elasticsearch查詢似乎也能正常工作。所以我們可以使用簡單的休息客戶端。 –