【问题标题】:Sending JSON Data to Solr using cUrl使用 cUrl 将 JSON 数据发送到 Solr
【发布时间】: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>

标签: json apache curl cmd solr


【解决方案1】:

您必须提交更新。将 commit true 或 commitWithin 1000 添加到请求中,例如。 g.

curl -X POST -d '{"add":{"doc":{"id":"delete.me","title":"change.me"},"commitWithin":1000}}' -H "Content-Type: application/json" http://localhost:8983/solr/solr_sample/update

也可以:

curl -X POST -d '{"add":{ "doc":{"id":"delete.me","title":"change.me"}}}' -H "Content-Type : 应用程序/json" http://localhost:8983/solr/solr_sample/update?commit=true

【讨论】:

  • 测试两个命令,不幸的是不起作用。我收到错误消息curl -X POST -d '{"add":{ "doc":{"id":"2","title":"Random title"}}}' -H "Content-Type:application/json" http://localhost:8983/solr/solr_sample/update?commit=truecurl: (3) [globbing] unmatched close brace/bracket in column 29 Error 404 Not Found HTTP ERROR 404 Problem accessing /solr/solr_sample/update. Reason: Not Found
  • curl -X POST -d '{"add":{"doc":{"id":"2","title":"Title 2"},"commitWithin":1000}}' -H "Content-Type:application/json" http://localhost:8983/solr/solr_sample/update/ <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>
  • 尝试用双引号替换单引号,例如。 G。 "{\"add\":{...}}" 或 "{'add':{...}}"。也许 curl 在 Windows 上的行为与我正在使用的平台 UNIX 和 OS X 上的行为不同。
  • 我刚刚在 Ubuntu 16 上进行了测试,效果很好。谢谢你,你太棒了!
猜你喜欢
  • 2022-10-18
  • 2013-09-09
  • 1970-01-01
  • 2015-09-30
  • 2012-04-15
  • 2015-07-17
  • 2021-07-08
  • 2013-12-11
  • 2018-09-19
相关资源
最近更新 更多