Content-Type header [application/x-www-form-urlencoded] is not supported, "status":406

Hello!
I am trying to run a simple query that I have copied as a curl from kibana and I am Trying to run it on my windows comand line. My curl is:
curl -XGET "http://localhost:9200/inspections/_doc/_search" -H 'Content-Type: application/json' -d'{ "query": { "match": { "business_name": "soup" } }}'
and I am getting this error:
"error":"Content-Type header [application/x-www-form-urlencoded] is not supported"

Any help would be appreciated

Welcome!

I believe it's a problem with curl on windows. I always found it painful.
I'd recommend using Kibana Dev Console or any REST console you could have in your browser instead.

I am really greatfull with your reply.
I thought something was wrong with my ES. So, I will continue using kibana.

If you're running on Windows with at least PowerShell 3.0+, you can always give the Elastic.Console PowerShell module a try. It provides a curl-like experience in PowerShell with API path and method completion

To install in PowerShell from the PowerShell gallery

Install-Module Elastic.Console -AllowPrerelease

Upon installation, the module will be configured with the APIs matching the version returned from

Get-ElasticsearchVersion

If you want to run with a different version of APIs, you can set this with

Set-ElasticsearchVersion 7.6.2

If not already downloaded, this will download the REST API specs of 7.6.2 version, which are used to power autocompletion.

Then, to make an API call

Invoke-Elasticsearch http://localhost:9200/inspections/_doc/_search -Body @'
{ "query": { "match": { "business_name": "soup" } }}
'@

es is an alias for Invoke-Elasticsearch, and http://localhost:9200 is the default protocol, host and port, so this can be shortened to

es inspections/_doc/_search -Body @'
{ "query": { "match": { "business_name": "soup" } }}
'@
1 Like

I'd use PowerShell's Invoke-WebRequest/Invoke-RestMethod instead., which should be something like this:

Invoke-WebRequest -Uri "http://localhost:9200/inspections/_doc/_search" -UseBasicParsing -ContentType 'application/json' -Method Get -Body '{ "query": { "match": { "business_name": "soup" } }}'
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.