Regarding to add a header " -H 'Content-Type: application/json' "

Hi Experts,

I met an issue during modify a parameter from template.

I want to modify a value of parameter which named "total_fields" in template such like this:

I use curl to input several commands to modify it, but all of them are returned failed and the log shows as below:

[admin@HPG5L3 ~]$ curl -XPUT localhost:9200/_template/lsh_nokia_nokiasbc-2019.09                                                                             .05 -d ' { "settings" : { "index.mapping.total_fields.limit" : "2000" } }'
{"error":"Content-Type header [application/x-www-form-urlencoded] is not support                                                                             [admin@HPG5L3 ~]$ curl -XPUT localhost:9200/_template/lsh_nokia_nokiasbc-2019.09.05 -d ' { "settings" : { "index.mapping.total_fields.limit" : "2000" } }'
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}
[admin@HPG5L3 ~]$
[admin@HPG5L3 ~]$
[admin@HPG5L3 ~]$
[admin@HPG5L3 ~]$ curl -XPUT localhost:9200/_template/lsh_nokia_nokiasbc-2019.09.05 -d ' { "default" : { "total_fields.limit" : "3000" } }'
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}
[admin@HPG5L3 ~]$
[admin@HPG5L3 ~]$
[admin@HPG5L3 ~]$ curl -XPUT localhost:9200/_template/lsh_nokia_nokiasbc-2019.09.05 -d ' { "settings" : { "total_fields.limit" : "3000" } }'
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}[admin@HPG5L3 ~]$
[admin@HPG5L3 ~]$
[admin@HPG5L3 ~]$
[admin@HPG5L3 ~]$
[admin@HPG5L3 ~]$ curl -XPUT localhost:9200/_template/lsh_nokia_nokiasbc-2019.09.05 -d '
> {
>      "order" : 1,
>      "index_patterns": ["lsh_nokia_nokiasbc-2019.09*"],
>      "settings" : {
>          "index.mapping.total_fields.limit": 3000,
>      }
> }'
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}
[admin@HPG5L3 ~]$

All of the failed returns are showed as this:

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

I have retrieved the similar issue and find that in elasticsearch 6.0 or high version there is a "Strict Content-Type Checking for Elasticsearch REST Requests"

You can refer to this URL to find the detailed report:

In this report, we can see we need do this action to adapt our pattern script

I have followed its indication then add the Content-type by curl command, but it still failed:

[admin@HPG5L3 SBClog]$ curl -XPUT localhost:9200/_template/lsh_nokia_nokiasbc-2019.09.05 -H 'Content-Type: application/json'
{"error":{"root_cause":[{"type":"parse_exception","reason":"request body is required"}],"type":"parse_exception","reason":"request body is required"},"status":400}
[admin@HPG5L3 SBClog]$
[admin@HPG5L3 bin]$ curl -XPUT localhost:9200/_template/lsh_nokia_nokiasbc-2019.09.05 -H 'Content-Type: application/json' -d ' { "settings" : { "index.mapping.total_fields.limit" : "2000" } }'
{"error":{"root_cause":[{"type":"action_request_validation_exception","reason":"Validation Failed:                                                            1: index patterns are missing;"}],"type":"action_request_validation_exception","reason":"Validati                                                           [admin@HPG5L3 bin]$
[admin@HPG5L3 bin]$
[admin@HPG5L3 bin]$
[admin@HPG5L3 bin]$
[admin@HPG5L3 bin]$
[admin@HPG5L3 bin]$ curl -XGET http://localhost:9200/_cat/indices/?v
health status index                         uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   template                      d4QOtkyhSLyGi9Y3afAh7Q   1   1          0            0       283b           283b
green  open   .kibana_task_manager          0_fwrwI_TBqCB4gY3-3iPg   1   0          2            4     98.7kb         98.7kb
yellow open   lsh_nokia_nokiasbc-2019.09.05 ilVqiOj8S3Sp2a1YIyzYPA   1   1         54            0    330.6kb        330.6kb
green  open   .kibana_1                     3Yjilne2QVO_z83G1UZHkw   1   0         10            3    187.2kb        187.2kb

Now my major question is how can I do to add a header " -H 'Content-Type: application/json' " successfully?

Thank you.

This is the right way:

curl -XPUT localhost:9200/_template/lsh_nokia_nokiasbc-2019.09.05 -H 'Content-Type: application/json' -d ' { "settings" : { "index.mapping.total_fields.limit" : "2000" } }'

The problem here is that you don't respect the PUT Template API.

Hi dadoonet,

Thanks a lot for your reply, but I still can't clear where is the different between my command and you provided, and i have ran your command it still return failed, would you please help me check it? thanks again.

[admin@HPG5L3 bin]$ curl -XPUT localhost:9200/_template/lsh_nokia_nokiasbc-2019.09.05 -H 'Content-Type: application/json' -d ' { "settings" : { "index.mapping.total_fields.limit" : "2000" } }'
{"error":{"root_cause":[{"type":"action_request_validation_exception","reason":"Validation Failed: 1: index patterns are missing;"}],"type":"action_request_validation_exception","reason":"Validation Failed: 1: index patterns are missing;"},"status":400}
[admin@HPG5L3 bin]$

[/quote]

{ "settings" : { "index.mapping.total_fields.limit" : "2000" } }

This JSON is not valid for the PUT Template API. Read the documentation I linked to and you will see what Elasticsearch is expecting.

Thanks dadoonet,

I have tried to use this command, then command returned true! issue solved!

[admin@HPG5L3 bin]$ curl -XPUT http://localhost:9200/lsh_nokia_nokiasbc-2019.09*/_settings/?pretty -H 'Content-Type: application/json' -d ' { "index.mapping.total_fields.limit" : "2000" } '
{
  "acknowledged" : true
}

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