我是Elasticsearch的新手,我正在按照教程加载示例数据:https://www.elastic.co/guide/en/kibana/current/tutorial-load-dataset.html 当我尝试在powershell中批量插入数据时 'curl -H'Content-Type:application / x-ndjson'-XPOST'localhost:9200 / shakespeare / _bulk?pretty'--data-binary“@shakespeare.json”'
我收到以下错误
PS C:\ Development \ elasticsearch-5.4.1 \ importdata> curl -H'Content-Type:application / x-ndjson'-XPOST'localhost:9200 / shakespeare / _bulk?pretty'--data-binary“@shakespeare.json” Invoke-WebRequest:无法绑定参数'Headers'。无法转换“System.St”类型的“Content-Type:application / x-ndjson”值 ring“to type”System.Collections.IDictionary“。 在行:1个字符:9 + curl -H'Content-Type:application / x-ndjson'-XPOST'localhost:9200 / s ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidArgument:(:) [Invoke-WebRequest],ParameterBindingException + FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
我尝试过几件事,阅读批量api文档,但没有结果
以下是json文件内容的一些示例:
{ “索引”:{ “_索引”: “莎士比亚”, “_类型”: “行动”, “_ ID”:0}} {“line_id”:1,“play_name”:“Henry IV”,“speech_number”:“”,“line_number”:“”,“speaker”:“”,“text_entry”:“ACT I”} { “索引”:{ “_索引”: “莎士比亚”, “_类型”: “场景”, “_编码”:1}} {“line_id”:2,“play_name”:“Henry IV”,“speech_number”:“”,“line_number”:“”,“speaker”:“”,“text_entry”:“SCENE I.伦敦。宫殿。 “} { “索引”:{ “_索引”: “莎士比亚”, “_类型”: “行”, “_ ID”:2}} {“line_id”:3,“play_name”:“Henry IV”,“speech_number”:“”,“line_number”:“”,“speaker”:“”,“text_entry”:“进入KING HENRY,LORD JOHN OF LANCASTER ,WESTMORELAND的EARL,SIR WALTER BLUNT和其他人“}
答案 0 :(得分:0)
我找到了解决方案。因为我在windows和PowerShell上使用curl,所以我不得不翻译
curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/shakespeare/_bulk?pretty' --data-binary @shakespeare.json
到
PS C:\Development\elasticsearch-5.4.1\importdata> $postParams = @"
>> {"index":{"_index":"shakespeare","_type":"act","_id":0}}
>> {"line_id":1,"play_name":"Henry IV","speech_number":"","line_number":"","speaker":"","text_entry":"ACT I"}
>>
>> "@
PS C:\Development\elasticsearch-5.4.1\importdata> curl -H @{"Content-Type" = "application/x-ndjson"} -Method POST 'http://localhost:92
00/shakespeare/_bulk?pretty' -body $postParams
当我使用演示文件时,批量插入没有成功,但这是另一个问题
PS C:\ Development \ elasticsearch-5.4.1 \ importdata> $ postParams = Get-Content" shakespeare.json"