Hi,
I'm tring run a request in Elasticsearch using PowerShell, but when I try use the JSON request in "-Body" following error is showing:
The request without -Body response Http 200. But I need send the JSON Query.
“Invoke-RestMethod: It is not possible to send content with this type of verb.Invoke-RestMethod: It is not possible to send content with this type of verb.”
$USERNAME = 'user'
$PASSWORD = 'pass'
$credPair = "$($USERNAME):$($PASSWORD)"
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))
$request = '{
"query": {
"range": {
"@timestamp": {
"time_zone": "-03:00",
"gte": "now-15m",
"lte": "now"
}
}
},
"size": 0,
"aggs": {
"total_doc": {
"value_count": {
"field": "S_ComputerName"
}
},
"total_per_server": {
"terms": {
"field": "S_ComputerName"
}
}
}
}'
$headers = @{}
$headers.Add("Content-Type", "application/json")
$headers.Add("Authorization", "Basic $encodedCredentials")
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$body=@{}
$body.add("Text",$request)
$response = Invoke-RestMethod -Uri 'https://elastic:9200/iis_crm_ocs*/_search?format=JSON&filter_path=aggregations.total_doc%2Caggregations.total_per_server.buckets&=&=' -Method GET -Headers $headers -WebSession $session -ContentType 'application/json' -Body $request