# Add new field in existing index and template

**URL:** <https://discuss.elastic.co/t/add-new-field-in-existing-index-and-template/270679>\
**Category:** Elasticsearch\
**Created:** [April 20, 2021, 9:28am UTC](https://discuss.elastic.co/t/add-new-field-in-existing-index-and-template/270679 "2021-04-20T09:28:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![niraj\_pandey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niraj_pandey/32/44034_2.png) [@niraj\_pandey](https://discuss.elastic.co/u/niraj_pandey)\
**Post date:** [April 20, 2021, 9:28am UTC](https://discuss.elastic.co/t/add-new-field-in-existing-index-and-template/270679/1 "2021-04-20T09:28:45Z")

</div>

Hi,

I want to add an new field in exiting index and corresponding to it's template.  
Could you pls help me on this ?

This is current template:

```
curl -XPUT 'vl-dev01:9200/_template/latesttmpl-farm-qusage-mon?pretty' -H 'Content-Type: application/json' -d'
{
        "index_patterns": "latest-mon-*",
        "order": 0,
        "version": 1,
        "settings": {
                "number_of_shards": 1,
                "refresh_interval": "5s"
        },
        "mappings": {
           "doc": {
                 "properties":
                 {
                        "clustername":
                        {
                                "type": "keyword",
                                "ignore_above": 256
                        },
                        "type":
                        {
                                "type": "keyword"
                        },
                        "qname":
                        {
                                "type": "keyword",
                                "ignore_above": 256
                        },
                        "qmemut":
                        {
                                "type": "float"
                        },
                        "qcpuut":
                        {
                                "type": "float"
                        },
                        "qslotut":
                        {
                                "type": "float"
                        }

                }
             }
    }
}
'

```

Now I want to add new field "total\_slots" with integer datatype.

I want this changes on existing index and for all future indexes which I create on monthly basis

---

<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:** [April 20, 2021, 9:40am UTC](https://discuss.elastic.co/t/add-new-field-in-existing-index-and-template/270679/2 "2021-04-20T09:40:45Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
Please update your post.

> [@niraj\_pandey](#):
>
> I want this changes on existing index

You can't. I mean that you can add the new field but you will have to reindex the data as the new field will be empty. Or you can use the new runtime fields feature to compute it on the fly if it's computed from the existing data. See

> **[Introducing Elasticsearch runtime fields](https://www.elastic.co/blog/introducing-elasticsearch-runtime-fields)**
>
> In 7.11, we’re excited to announce schema on read in the Elastic Stack. We now offer the best of both worlds on a single platform. Schema on read for flexibility and schema on write for performance. We call our implementation runtime fields.

> [@niraj\_pandey](#):
>
> and for all future indexes which I create on monthly basis

Just update the template with the new field.

---

<div class="post-metadata">

**Author:** ![niraj\_pandey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niraj_pandey/32/44034_2.png) [@niraj\_pandey](https://discuss.elastic.co/u/niraj_pandey)\
**Post date:** [April 20, 2021, 10:48am UTC](https://discuss.elastic.co/t/add-new-field-in-existing-index-and-template/270679/3 "2021-04-20T10:48:34Z")

</div>

I tried this but not luck.

`curl -X PUT "http://vl-dev01:9200/latestqusage-mon-2021.04/_mapping/latesttmpl-farm-qusage-mon" -H 'Content-Type: application/json' -d '{ "properties":{"newslot" : {"type" : "float"}} }'`

Here latestqusage-mon-2021.04 is my index name and "latesttmpl-farm-qusage-mon" is template name. I want this change on this current index as well as in template so the when we create a new index the same would be reflect over there as well.

Getting following error.

```
"type":"illegal_argument_exception","reason":"Rejecting mapping update to [latestqusage-mon-2021.04] as the final mapping would have more than 1 type: [doc, latesttmpl-farm-qusage-mon]"},"status":400
```

---

<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:** [April 20, 2021, 11:01am UTC](https://discuss.elastic.co/t/add-new-field-in-existing-index-and-template/270679/4 "2021-04-20T11:01:22Z")

</div>

Try:

```auto
curl -X PUT "http://vl-dev01:9200/latestqusage-mon-2021.04/_mapping" -H 'Content-Type: application/json' -d '{ "properties":{"newslot" : {"type" : "float"}} }'

```

---

<div class="post-metadata">

**Author:** ![niraj\_pandey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niraj_pandey/32/44034_2.png) [@niraj\_pandey](https://discuss.elastic.co/u/niraj_pandey)\
**Post date:** [April 20, 2021, 11:09am UTC](https://discuss.elastic.co/t/add-new-field-in-existing-index-and-template/270679/5 "2021-04-20T11:09:42Z")

</div>

It says mapping type missing.

`{"error":{"root_cause":[{"type":"action_request_validation_exception","reason":"Validation Failed: 1: mapping type is missing;"}],"type":"action_request_validation_exception","reason":"Validation Failed: 1: mapping type is missing;"},"status":400}`

---

<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:** [April 20, 2021, 12:39pm UTC](https://discuss.elastic.co/t/add-new-field-in-existing-index-and-template/270679/6 "2021-04-20T12:39:54Z")

</div>

So try

```
curl -X PUT "http://vl-dev01:9200/latestqusage-mon-2021.04/_mapping/_doc" -H 'Content-Type: application/json' -d '{ "properties":{"newslot" : {"type" : "float"}} }'
```

---

<div class="post-metadata">

**Author:** ![niraj\_pandey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niraj_pandey/32/44034_2.png) [@niraj\_pandey](https://discuss.elastic.co/u/niraj_pandey)\
**Post date:** [April 20, 2021, 1:10pm UTC](https://discuss.elastic.co/t/add-new-field-in-existing-index-and-template/270679/7 "2021-04-20T13:10:59Z")

</div>

> [@dadoonet](#):
>
> ```auto
> curl -X PUT "http://vl-dev01:9200/latestqusage-mon-2021.04/_mapping/_doc" -H 'Content-Type: application/json' -d '{ "properties":{"newslot" : {"type" : "float"}} }'
> 
> ```

Thanks the above command works. I just need to replace "\_doc" with "doc".

One quick qus we create a new index every month using the template (ie: latestqusage-mon-2021.05 for may) .Will this changes reflect in new index as well which will be created in next month by itself or we need to do this manually for each month.

---

<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:** [May 18, 2021, 1:11pm UTC](https://discuss.elastic.co/t/add-new-field-in-existing-index-and-template/270679/8 "2021-05-18T13:11:01Z")

</div>

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