批量插入elasticsearch curl powershell 时出现问题

问题描述 投票:0回答:2

我是 Elasticsearch 的新手,我正在按照教程加载示例数据:https://www.elastic.co/guide/en/kibana/current/tutorial-load-dataset.html 当我尝试在 powershell 中批量插入数据时 'curl -H '内容类型:application/x-ndjson' -XPOST 'localhost:9200/shakespeare/_bulk?pretty' --data-binary "@shakespeare.json"'

我收到以下错误

PS C:\开发lasticsearch-5.4.1\importdata>curl -H'内容类型:application/x-ndjson'-XPOST'localhost:9200/shakespeare/_bulk?pretty'--data-binary“@shakespeare .json” Invoke-WebRequest:无法绑定参数“标头”。无法转换类型“System.St”的“Content-Type:application/x-ndjson”值 环”以输入“System.Collections.IDictionary”。 行:1 字符:9 + curl -H '内容类型:application/x-ndjson' -XPOST 'localhost:9200/s ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException +FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

我尝试了几件事,阅读了批量 api 文档,但没有结果

以下是 json 文件内容的一些示例:

{"index":{"_index":"莎士比亚","_type":"act","_id":0}} {"line_id":1,"play_name":"亨利四世","speech_number":"","line_number":"","speaker":"","text_entry":"第一幕"} {"index":{"_index":"莎士比亚","_type":"场景","_id":1}} {"line_id":2,"play_name":"亨利四世","speech_number":"","line_number":"","speaker":"","text_entry":"场景 I. 伦敦。宫殿。 ”} {"index":{"_index":"莎士比亚","_type":"line","_id":2}} {"line_id":3,"play_name":"亨利四世","speech_number":"","line_number":"","speaker":"","text_entry":"兰开斯特的约翰勋爵亨利国王上、威斯特摩兰伯爵、沃尔特·布朗特爵士等”}

powershell curl elasticsearch
2个回答
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 lasticsearch-5.4.1\importdata> $postParams = Get-Content "shakespeare.json"


0
投票

任何更新,我也遇到同样的错误并受到打击。 我正在使用 Windows 并在 powershell/命令提示符和 git bash 中尝试过

curl -H“内容类型:application/x-ndjson”-XPOST https://localhost:9200/products/_bulk --data-binary“@products-bulk.json”

curl -H“内容类型:application/x-ndjson”-XPOST https://localhost:9200/products/_bulk --data-binary“@products-bulk.json”

PSC:\m

© www.soinside.com 2019 - 2024. All rights reserved.