elasticsearch,Curl,elasticsearch" /> elasticsearch,Curl,elasticsearch" />

Elasticsearch/Curl-won';无法读取批量API的换行符

Elasticsearch/Curl-won';无法读取批量API的换行符,curl,elasticsearch,Curl,elasticsearch,我目前正在运行windows 10,并在cmd.exe中使用curl\u 7\u 47\u 1\u openssl\u nghttp2\u x64,我的问题是每当我尝试在elasticsearch中使用批量API输入数据时,我总是会遇到以下错误: Validation Failed 1: no requests added, 我已经研究过如何使用批量API正确发送数据(为每个输入添加新行),但是cURL不会只读取我的break-line语句。我的全部命令如下: curl -XPOST loca

我目前正在运行windows 10,并在cmd.exe中使用
curl\u 7\u 47\u 1\u openssl\u nghttp2\u x64
,我的问题是每当我尝试在elasticsearch中使用批量API输入数据时,我总是会遇到以下错误:

Validation Failed 1: no requests added,
我已经研究过如何使用批量API正确发送数据(为每个输入添加新行),但是
cURL
不会只读取我的break-line语句。我的全部命令如下:

curl -XPOST localhost:9200/customer/external/_bulk?pretty --data-binary "{ \"index\": {\"_id\": \"1\"}} \n { \"name\": \"John Doe\" } \n {\"index\": {\"_id\": \"2\"}} \n {\"name\": \"Jane Doe\" }"
另外,其他信息包括:
cURL
在windows中不读取单引号,我在jSON中转义双引号


谢谢

您有两种解决方案:

您可以将批量查询存储在文件中。确保:

  • 双引号不会被转义,而且
  • 每行(也是最后一行)都以换行符结尾(不是换行符
    \n
    ,而是真正的换行符
bulk.json

{"index": {"_id": "1"}}
{"name": "John Doe" }
{"index": {"_id": "2"}}
{"name": "Jane Doe" }
然后可以运行此命令

curl -XPOST localhost:9200/customer/external/_bulk?pretty --data-binary @/path/to/your/file
另一种解决方案是简单地内联您拥有的相同数据,但使用
-d
参数发送数据,而不是使用用于发送文件的
--data binary

curl -XPOST localhost:9200/customer/external/_bulk?pretty -d "
{\"index\": {\"_id\": \"1\"}}
{\"name\": \"John Doe\" }
{\"index\": {\"_id\": \"2\"}}
{\"name\": \"Jane Doe\" }
"

再次确保在最后一行之后添加新行

谢谢!我尝试了第一个,它成功了,至于第二个,我不知道如何在cmd.exe中插入内联(换行?),但无论如何,谢谢你的帮助!好的,第一个对你来说可能更好。很高兴它成功了