Add new field in existing index and template

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

Please format your code, logs or configuration files using </> icon as explained in this guide 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:

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.

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

Just update the template with the new field.

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

Try:

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

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}

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"}} }'

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.

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