我应该使用convert-tojson还是自己动手。我应该使用invoke-restrequest,invokeweb-request,System.net.WebClient还是system.net.http.HttpClient?
有时我似乎成功发布,虽然数据没有编入索引。
{"_index":"dropstorage","_type":"connectionstats","_id":"97e156a5-4d16-48d4-84e8-fcc723aea1ae",
"_version":1,"found":true,"_source":{
"hnas": 1,
"active": 70,
"id": "97e156a5-4d16-48d4-84e8-fcc723aea1ae",
"total": "70",
"date": "4/9/2015 9:03:36 AM"
}}
答案 0 :(得分:4)
我建议采用以下方法:
$body = ConvertTo-Json $curatorResult -Compress
Invoke-RestMethod -Method Post -Uri $uri -ContentType 'application/json'-Body $body -ErrorAction Stop | Out-Null
答案 1 :(得分:0)
以下是使用PowerShell从第一原则使用Elasticsearch的演练。有关何时使用GET和POST,如何进行序列化,海量数据生成以及如何直接与多个调用进行交互的说明。
从一开始,您就会发现有关使PowerShell调用与Elasticsearch兼容的讨论(是的,这是一个技巧)。
答案 2 :(得分:0)
签出Elastic.Console
,这是一个小型PowerShell模块,用于使用PowerShell和PowerShell Core与Elasticsearch一起使用。它提供了针对所选Elasticsearch版本的API端点路径和方法的自动完成功能。
安装后
function createCalendarEvent(){
var sheet = SpreadsheetApp.getActiveSheet();
var calendar =CalendarApp.getCalendarById('e3pbfcblhsmehusmotijp1r9e8@group.calendar.google.com');
var startRow =2; //2 exempts header row check if applicable
var numRows = sheet.getLastRow(); //number of rows to process
var numColumns = sheet.getLastColumn();
var dataRange = sheet.getRange(startRow,1,numRows-1,numColumns);
var data = dataRange.getValues();
var complete="Done"
for(var i=0;i<data.length;++i)
var row = data[i];
var DONumber = row[1]; //D.O#
var Address = row[2]; //AddressDe
var contact = row[3]; //Deliver to Contact
var phone = row[4]; //Contact Phone Number
var time = row[5]; //Delivery time
var instructions = row[6]; //Instructions
var assign = row[7]; //Which truck to assign to
var notify = row[8]; //email to notify when delivery is complete
var goods = row[9]; //Description of goods
var quantity = row[10]; //Quantiy of each item
var date = new Date(row[11]); //Delivery date
var edate = new Date(row[12]); //end date
var eventID = row[13]; //stops duplication
if (eventID != complete) {
var currentCell = sheet.getRange(startRow +i, numColumns);
calendar.createEvent(contact,date,edate,{
description: contact + '\r' + phone + '\r' + instructions + '\r' + goods + '\r' + quantity
});
currentCell.setValue(complete);
}
}
您可以使用以下方式发送数据
Install-Module -Name Elastic.Console -AllowPrerelease
请求主体可以是JSON字符串文字,哈希表或包含JSON的文件的路径。
运行以下内容以查看完整的文档和示例
$body = ConvertTo-Json $curatorResult -Compress
$response = es -Method POST "/{index}/_doc/{id}" -Body $body