【发布时间】:2018-03-18 22:40:54
【问题描述】:
如何将 JSON 对象发送到 usinc cUrl 的 solr 集合
我使用的是 Windows 10。
curl -X POST -H "Content-Type:application/json" "http://localhost:8983/solr/solr_sample/update/json/docs" --data-binary "{'id': '1','title':'Doc 1'}"
当我使用这种格式时,我会收到一些警告信息:
curl -X POST -H 'Content-Type:application/json' 'http://localhost:8983/solr/sorl_sample/update/json/docs' --data-binary '{"id": "1","title":"Doc 1"}'
curl: (1) Protocol "'http" not supported or disabled in libcurl
curl: (3) [globbing] unmatched close brace/bracket in column 14
我使用 " " insted of ' '
解决了这个问题当我使用第一个 url 发送请求时,我得到了这个响应:
{
"responseHeader":{
"status":0,
"QTime":112}}
但是当我尝试通过搜索获得一些结果时,我在 docs[]
中看不到任何对象curl -X GET "http://localhost:8983/solr/solr_sample/select?q=*:*"
结果:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"*:*"}},
"response":{"numFound":0,"start":0,"docs":[]
}}
当我使用 Solr UI 时,我可以毫无问题地添加 JSON 对象,也可以在终端中查看结果
【问题讨论】:
-
您必须提交更新。将 commit=true 添加到请求中。
-
你是这个意思吗?
curl -X POST -H "Content-Type:application/json" "http://localhost:8983/solr/solr_sample/update?commit=true" --data- binary "{'id':'1'}"我收到此错误:<html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Error 404 Not Found</title> </head> <body><h2>HTTP ERROR 404</h2> <p>Problem accessing /solr/solr_sample/update. Reason: <pre> Not Found</pre></p> </body> </html>