Curl -x put content-type: application/json throwing error

I have an Elasticsearch instance that has reached it's default max shards of 1000 and now I'm trying to increase that number using curl but am running into an issue with the -h content-type declaration.

Here is my curl statement--

curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d' { "persistent" : { "cluster.max_shards_per_node" : "3000" }}'

This is the response that I am getting back--

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

I went to a curl test site for posting json and copied the -h switch directly into my curl statement and I'm still getting this error.

Even though this isn't a frequently used instance I need to get it back up because it is in a production environment.

TIA
Bill Youngman

Update--

I changed my curl command to--

curl -X PUT localhost:9200/_cluster/settings?pretty -H "Content-Type: application/json" -d' {  "persistent" : {"cluster.max_shards_per_node" : "3000"  }}'

Error-

{
  "error" : {
    "root_cause" : [
      {
        "type" : "json_parse_exception",
        "reason" : "Unexpected character (''' (code 39)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n at [Source: (org.elasticsearch.common.io.stream.ByteBufferStreamInput); line: 1, column: 2]"
      }
    ],
    "type" : "json_parse_exception",
    "reason" : "Unexpected character (''' (code 39)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n at [Source: (org.elasticsearch.common.io.stream.ByteBufferStreamInput); line: 1, column:2]"
  },
  "status" : 400
}
curl: (3) unmatched brace in URL position 1:
{
 ^

I would try copying the command from Size your shards | Elasticsearch Guide [8.0] | Elastic and then pasting it directly into your console and seeing if that works. If it does, then just edit it and change to what you want.

However if you're exceeding this (soft) limit, then you may want to reevaluate your approach.

Thanks Mark I'll give this a try and unfortunately I'm constrained in this since my company is not willing to invest any budget for making this stack a proper enterprise level stack so I'm forced to use the basic license on 1 server for everything (Elasticsearch, Kibana, Logstash) for our entire enterprise and we are massively under provisioned here. I'm constantly having to apply band aids to keep the system up.

-Bill

Mark,

I did as you suggested and this is the command that I'm running--

curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
  "persistent" : {
    "cluster.max_shards_per_node": 1200
  }
}
'

Error--

{
  "error" : "Content-Type header [application/x-www-form-urlencoded] is not supp
orted",
  "status" : 406
}

Interesting I ran you exact command it is fine.

hyperion:docker sbrown$ curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
  "persistent" : {
    "cluster.max_shards_per_node": 1200
  }
}
'
{
  "acknowledged" : true,
  "persistent" : {
    "cluster" : {
      "max_shards_per_node" : "1200"
    }
  },
  "transient" : { }
}

I should add that our stack is on Windows and I am using the version of curl with mingw

-Bill

Hmmm I Think you are going to need to look close at the man page

Perhaps this section

--json

(HTTP) Sends the specified JSON data in a POST request to the HTTP server. --json works as a shortcut for passing on these three options:

--data [arg] --header "Content-Type: application/json" --header "Accept: application/json"

There is no verification that the passed in data is actual JSON or that the syntax is correct.

If you start the data with the letter @, the rest should be a file name to read the data from, or a single dash (-) if you want curl to read the data from stdin. Posting data from a file named 'foobar' would thus be done with --json @foobar and to instead read the data from stdin, use --json @-.

If this option is used more than once on the same command line, the additional data pieces will be concatenated to the previous before sending.

The headers this option sets can be overriden with --header as usual.

Examples:

curl --json '{ "drink": "coffe" }' https://example.com curl --json '{ "drink":' --json ' "coffe" }' https://example.com curl --json @prepared https://example.com curl --json @- https://example.com < json.txt

See also --data-binary and --data-raw. This option overrides -F, --form and -I, --head and -T, --upload-file. Added in 7.82.0.

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