使用 cUrl 将 JSON 数据发送到 Solr

Den*_*vic 3 apache json curl solr cmd

如何使用 cUrl 将 JSON 对象发送到 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'}"
Run Code Online (Sandbox Code Playgroud)

当我使用这种格式时,我收到某种警告消息:

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
Run Code Online (Sandbox Code Playgroud)

我使用“”代替''解决了这个问题

当我使用第一个网址发送请求时,我收到以下响应:

{
  "responseHeader":{
    "status":0,
    "QTime":112}}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试通过搜索获得一些结果时,我在docs[]中看不到任何对象

curl -X GET "http://localhost:8983/solr/solr_sample/select?q=*:*"
Run Code Online (Sandbox Code Playgroud)

结果:

{
      "responseHeader":{
        "status":0,
        "QTime":0,
        "params":{
          "q":"*:*"}},
      "response":{"numFound":0,"start":0,"docs":[]
      }}
Run Code Online (Sandbox Code Playgroud)

当我使用 Solr UI 时,我可以毫无问题地添加 JSON 对象,也可以在终端中查看结果

Hol*_*row 8

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

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

也有效:

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