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

**URL:** https://discuss.elastic.co/t/regarding-to-add-a-header-h-content-type-application-json/198363
**Category:** Elasticsearch
**Created:** [September 6, 2019, 7:50am UTC](https://discuss.elastic.co/t/regarding-to-add-a-header-h-content-type-application-json/198363 "2019-09-06T07:50:07Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![terrymu](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@terrymu](https://discuss.elastic.co/u/terrymu)
#### Post date: [September 6, 2019, 7:50am UTC](https://discuss.elastic.co/t/regarding-to-add-a-header-h-content-type-application-json/198363/1 "2019-09-06T07:50:07Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/a/3afe946f5bfa18e2f7be43375ea55acdfef692b2.png)

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:

> **[Strict Content-Type Checking for Elasticsearch REST Requests](https://www.elastic.co/fr/blog/strict-content-type-checking-for-elasticsearch-rest-requests)**
>
> Elasticsearch 6.0 will enforce strict content-type checking. All REST requests that include a body must also provide the correct Content-Type header.

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

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/5/053b9a9894cb4fac56fd16de6e444710de6260bd.png)

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.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 6, 2019, 7:53am UTC](https://discuss.elastic.co/t/regarding-to-add-a-header-h-content-type-application-json/198363/2 "2019-09-06T07:53:32Z")

</div>

This is the right way:

```auto
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](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html).

---

<div class="post-metadata">

### Author: ![terrymu](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@terrymu](https://discuss.elastic.co/u/terrymu)
#### Post date: [September 6, 2019, 8:00am UTC](https://discuss.elastic.co/t/regarding-to-add-a-header-h-content-type-application-json/198363/4 "2019-09-06T08:00:52Z")

</div>

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.

```auto
[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]

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 6, 2019, 8:09am UTC](https://discuss.elastic.co/t/regarding-to-add-a-header-h-content-type-application-json/198363/5 "2019-09-06T08:09:30Z")

</div>

```auto
{ "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.

---

<div class="post-metadata">

### Author: ![terrymu](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@terrymu](https://discuss.elastic.co/u/terrymu)
#### Post date: [September 9, 2019, 2:56am UTC](https://discuss.elastic.co/t/regarding-to-add-a-header-h-content-type-application-json/198363/6 "2019-09-09T02:56:12Z")

</div>

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
}
```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 7, 2019, 2:56am UTC](https://discuss.elastic.co/t/regarding-to-add-a-header-h-content-type-application-json/198363/7 "2019-10-07T02:56:14Z")

</div>

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