Windows:在命令行上使用json数据进行卷曲

cur*_*us1 13 json curl elasticsearch

我在Windows提示符下运行以下命令:

curl -XPUT http://127.0.0.1:9200/test-index/test-type/_mapping?pretty=true -d '{"test-type": {"properties": {"name": {"index": "analyzed", "term_vector": "with_positions_offsets", "boost": 1.0, "store": "yes", "type": "string"}}}}'
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

{
  "error" : "ElasticsearchParseException[Failed to parse content to map]; nested: JsonParseException[Unexpected character (''' (code 39)): expected a
valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.elasticsearch.common.compress.lzf.LZFCompressedStreamInput@45
4ed1d2; line: 1, column: 2]]; ",
  "status" : 400
}
Run Code Online (Sandbox Code Playgroud)

我搜索了解决方案并找到了替代方法,例如将json数据放入文件中,但由于某些原因我无法使用它.

谢谢!

Dan*_*ite 20

Windows cmd不支持带单引号的字符串.使用"和逃避内在的\".


Pau*_*tha 7

"我搜索了解决方案并找到了替代方案,例如将json数据放入文件中,但由于某些原因我无法使用它"

这应该适用hello.json于临时工.需要的@是.

c:\temp>curl -v -X PUT  \ 
             --data "@hello.json"  \
             -H "Content-Type:application/json"  \
             http://localhost:8080/api/myresource
Run Code Online (Sandbox Code Playgroud)