I'm trying to push some data into ElasticSearch via PowerShell. I'm converting the data into JSON, then trying both Invoke-WebRequest
and Invoke-RestMethod
, but always get errors on malformed data or content-type not supported. I haven't created the index as I believe it will create it for me.
Anyone able to assist on what I'm missing/doing wrong?
Example code:
$data = @()
$CustomObject = [pscustomobject]@{
SqlInstance = "myserver1"
Database = "mydb"
Schema = "versioning"
Name = "DataVersionHistory"
IndexSpaceUsed = 0
DataSpaceUsed = 0
RowCount = 0
};
$data += $CustomObject;
$CustomObject = [pscustomobject]@{
SqlInstance = "myserver1"
Database = "mydb"
Schema = "versioning"
Name = "VersionHistory"
IndexSpaceUsed = 10
DataSpaceUsed = 25
RowCount = 3000
};
$data += $CustomObject;
$myJson = ConvertTo-Json -InputObject $data ;
Invoke-RestMethod -Uri http://localhost:9200/myindex/mytype/_bulk?pretty `
-Method POST -Body $myJson -ContentType "application/json"