2

我正在从这里运行 Apache Solr 教程:

http://lucene.apache.org/solr/guide/7_6/solr-tutorial.html

Solr 正在运行,我可以在 Web 浏览器中运行查询。

该教程提到cURL了我不熟悉的内容。

我已经解压CURLC:\CurlCurl 并将其包含在PATH environment variableC:\Curl\curl-7.63.0-win64-mingw\bin

在 Windows 命令提示符下运行以下命令时出现错误。我用谷歌搜索试图找到一个无济于事的解决方案:

下面的代码:

C:\Curl\curl-7.63.0-win64-mingw\bin>curl -X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' http://localhost:8983/solr/films/schema

生成以下错误:

curl: (3) unmatched brace in URL position 1:
{name:name,
 ^
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched close brace/bracket in URL position 12:
stored:true}}'
           ^
{
  "responseHeader":{
    "status":400,
    "QTime":1},
  "error":{
    "metadata":[
      "error-class","org.apache.solr.common.SolrException",
      "root-error-class","org.apache.solr.common.SolrException"],
    "msg":"no stream",
    "code":400}}

我尝试添加一个-g来关闭通配符。

curl -g -X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' http://localhost:8983/solr/films/schema

这产生了几乎相同的错误:

C:\Curl\curl-7.63.0-win64-mingw\bin>curl -g -X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' http://localhost:8983/solr/films/schema

curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
{
  "responseHeader":{
    "status":400,
    "QTime":1},
  "error":{
    "metadata":[
      "error-class","org.apache.solr.common.SolrException",
      "root-error-class","org.apache.solr.common.SolrException"],
    "msg":"no stream",
    "code":400}}

然后我尝试删除单引号并转义双引号,但随后出现以下错误:

curl -g -X POST -H Content-type:application/json --data-binary {\"add-field\": {\"name\":\"name\", \"type\":\"text_general\", \"multiValued\":false, \"stored\":true}} http://localhost:8983/solr/films/schema

ScopedHandler.nextHandle(ScopedHandler.java:255)\r\n\tat org.eclipse.jetty.server.handler。ContextHandler.doHandle(ContextHandler.java:1317)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)\r\n\tat org.eclipse.jetty.servlet。 ServletHandler.doScope(Serv letHandler.java:473)\r\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)\r\n\tat org.eclipse.jetty.server .handler.ScopedHandler.nextScope(ScopedHandler.java:201)\r\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1219)\r\n\tat org.eclipse.jetty .server.handler.ScopedHandler.handle(ScopedHandler.java:144)\r\n\tat org.eclipse.jett y.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:219)\r\n\tat org. eclipse.jetty.server.handler.HandlerCollection。runTask(EatWhatYouKill .java:333)\r\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)\r\n\tat org.eclipse.jetty.util。 thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java :168)\r\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)\r\n\tat org. eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762)\r\n \tat org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680)\r\n\tat java。lang.Thread.run(Unknown Source)\r\n", "code":500}} EatWhatYouKill.tryProduce(EatWhatYouKill.java :168)\r\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)\r\n\tat org.eclipse.jetty。 util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762)\r\n\tat org. eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680)\r\n\tat java。lang.Thread.run(Unknown Source)\r\n", "code":500}} EatWhatYouKill.tryProduce(EatWhatYouKill.java :168)\r\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)\r\n\tat org.eclipse.jetty。 util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762)\r\n\tat org. eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680)\r\n\tat java。lang.Thread.run(Unknown Source)\r\n", "code":500}} 762)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680)\r\n\tat java。lang.Thread.run(Unknown Source)\r\n", "code":500}} 762)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680)\r\n\tat java。lang.Thread.run(Unknown Source)\r\n", "code":500}}

我知道关于这个问题有很多类似的问答,但它们并不完全相同,而且我尝试过的解决方案都没有解决我的问题。

4

5 回答 5

13

我用双引号替换了单引号,并用反斜杠转义了花括号内的双引号,它已经奏效了。

我从这个出发:

curl --X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' http://localhost:8983/solr/films/schema

对此:

curl --X POST -H "Content-type:application/json" --data-binary "{\"add-field\": {\"name\":\"name\", \"type\":\"text_general\", \"multiValued\":false, \"stored\":true}}" http://localhost:8983/solr/films/schema

谢谢大家的集体回答。我确信将其添加JSON到单独的文件中有一些可能的积极因素,但我想避免创建其他文件。

于 2019-01-25T09:26:54.857 回答
1

Windows 命令提示符不支持单引号。这是一个问题,因为 cURL 语句使用单引号来指定 JSON 数据。

要解决此问题,请将 JSON 保存在单独的文件中(例如add-field.txt)并将其导入 cURL 语句,以便稍后您可以像这样运行它:

curl -X POST -H 'Content-type:application/json' --data-binary @add-field.txt http://localhost:8983/solr/films/schema
于 2019-01-20T09:53:38.863 回答
1

我会走另一条路。如果你安装了微软的 Wonderfool 工具WSL。您将能够按原样运行所有这些命令,因为您将在 linux 系统中运行。最终将节省大量时间。

于 2019-01-20T11:42:28.803 回答
0

Gitbash 为我解决了这个问题。WSL 崩溃的原因是我目前忽略的。

于 2022-01-07T00:15:06.317 回答
0

您可能正在发送没有转义字符的请求 json 数据。因此,如果您"在请求中使用了任何双引号 ( ),那么您可以使用反斜杠 ( \) 对其进行转义。

更改以下内容

curl --X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' http://localhost:8983/solr/films/schema

curl --X POST -H "Content-type:application/json" --data-binary "{\"add-field\": {\"name\":\"name\", \"type\":\"text_general\", \"multiValued\":false, \"stored\":true}}" http://localhost:8983/solr/films/schema
于 2022-02-12T17:23:15.007 回答