我知道StackOverflow上已经有类似的问题,但没有一个能解决我目前的问题。
我正在使用ElasticSearch 6.7.0
,我目前正在学习它的教程。目前,我卡在此步骤上,这需要我下载存储在文件accounts.json
中的一些示例数据。以下是该文件的一小部分:
{"index":{"_id":"988"}}
{"account_number":988,"balance":17803,"firstname":"Lucy","lastname":"Castro","age":34,"gender":"F","address":"425 Fleet Walk","employer":"Geekfarm","email":"lucycastro@geekfarm.com","city":"Mulino","state":"VA"}
{"index":{"_id":"990"}}
{"account_number":990,"balance":44456,"firstname":"Kelly","lastname":"Steele","age":35,"gender":"M","address":"809 Hoyt Street","employer":"Eschoir","email":"kellysteele@eschoir.com","city":"Stewartville","state":"ID"}
{"index":{"_id":"995"}}
{"account_number":995,"balance":21153,"firstname":"Phelps","lastname":"Parrish","age":25,"gender":"M","address":"666 Miller Place","employer":"Pearlessa","email":"phelpsparrish@pearlessa.com","city":"Brecon","state":"ME"}
该文件保存在路径C:UsersMeDesktopaccounts.json
内。
我按照教程中的说明运行了以下命令:
PS C:\Users\Me\Downloads\curl-7.64.1-win64-mingw\bin> .\curl.exe -H "内容类型:applicati lhost:9200/bank/_doc/_bulk?pretty&refresh" --data-binary "C:\Users\Me\Desktop\accounts.json">
我收到此错误消息:
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "The bulk request must be terminated by a newline [n]"
}
],
"type" : "illegal_argument_exception",
"reason" : "The bulk request must be terminated by a newline [n]"
},
"status" : 400
}
为了解决这个问题,我转到文件末尾并通过按 Enter
插入了新行。但是,当我再次运行该命令时,出现了相同的错误消息。
如何解决此问题?
我将accounts.json
文件移动到运行curl.exe
的同一目录,并执行了以下命令:
.\curl.exe -H "Content-Type: applicati lhost:9200/bank/_doc/_bulk?漂亮&刷新" --data-binary "@accounts.json">
这一次,批量请求成功。
对于那些面临类似问题的人,请记住按 Enter
在文件末尾插入新行。如果这不起作用,请尝试将文件移动到另一个目录中。错误消息"批量请求必须通过换行符终止"可能会产生误导 - 您的文件可能根本没有格式错误;也许由于各种原因根本无法定位或访问它。
而不是 "C:\Users\Me\Desktop\accounts.json"
即
curl.exe -H "Content-Type: applicati lhost:9200/bank/_doc/_bulk?pretty&refresh" --data-binary "@C:UsersMeDesktopaccounts.json"
尝试更改文件的 EOL 字符和编码,如下所述:https://stackoverflow.com/a/59791215/2726844