我正在尝试使用我的Rails应用程序中的Solr 5.3.1(使用SolrCloud)进行基本的crud操作,但我对如何操作感到有些困惑。
这就是我到目前为止所做的事情:
bin/solr start -e cloud
http://localhost:8983/solr/$my_collection/
从rails控制台我输入
require 'net/http'
h = Net::HTTP.new 'localhost', 8983
data = Article.all.map {|a| {id: a.id, title: a.title, body: a.body, caption: a.caption}}
h.send_request 'POST', 'http://localhost:8983/solr/$my_collection/update', data, 'Content-Type: application/json'
然后我得到:NoMethodError: undefined method 'keys' for "Content-Type: application/json":String
我想我需要以某种方式添加这些键但不确定如何。
这也失败了:
h = Net::HTTP.new 'localhost', 8983
h.send_request 'POST', 'http://localhost:8983/solr/$my_collection/update/json', "{'id': '1'}"
=> #<Net::HTTPBadRequest 400 Bad Request readbody=true>
但是通过简单的curl命令工作:
curl 'http://localhost:8983/solr/$my_collection/update/json' --data-binary "[{'id':94},{'id':93}]"
{"responseHeader":{"status":0,"QTime":285}}
有什么建议吗? 谢谢!
修改
如果您感到好奇,data
变量最终会包含以下内容:
[
{:id=>94, :title=>"Some Title", :body=> "Some body", :caption=> "Some caption"},
{:id=>93, :title=>"Some Title", :body=> "Some body", :caption=> "Some caption"},
{:id=>92, :title=>"Some Title", :body=> "Some body", :caption=> "Some caption"},
{:id=>91, :title=>"Some Title", :body=> "Some body", :caption=> "Some caption"},
... and so on]