Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to post data to Elastic Search using powershell?

Should I use convert-tojson or roll my own. Should I use invoke-restrequest, invokeweb-request, System.net.WebClient or system.net.http.HttpClient?

Sometimes I seem to post successfully, although the data isn't indexed.

{"_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"
}}
like image 943
Paul Miller Avatar asked Oct 21 '25 15:10

Paul Miller


1 Answers

I would recommend the following approach:

$body = ConvertTo-Json $curatorResult -Compress
Invoke-RestMethod -Method Post -Uri $uri -ContentType 'application/json'-Body $body -ErrorAction Stop | Out-Null
like image 110
Jordan Edwards Avatar answered Oct 23 '25 08:10

Jordan Edwards



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!