# Update documents and field mapping

**URL:** https://discuss.elastic.co/t/update-documents-and-field-mapping/280277
**Category:** Elasticsearch
**Created:** [August 3, 2021, 6:52am UTC](https://discuss.elastic.co/t/update-documents-and-field-mapping/280277 "2021-08-03T06:52:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Dheeraj\_Gupta](https://avatars.discourse-cdn.com/v4/letter/d/49beb7/32.png) [@Dheeraj\_Gupta](https://discuss.elastic.co/u/Dheeraj_Gupta)
#### Post date: [August 3, 2021, 6:52am UTC](https://discuss.elastic.co/t/update-documents-and-field-mapping/280277/1 "2021-08-03T06:52:27Z")

</div>

I am using elasticsearch for some batch processing.

The general gist of steps involved are:  
1 Fetche each document from index A  
2 Search index B by filtering data using attributes of document returned in step 1.  
3. Process the data returned by 2 to compute a metric "mymetric"  
4. _Update_ the document returned in 1 by adding a new field "mymetric"

Now the program is working correctly and I can see updated documents have the new field. The problem is that field mappings do not get updated (I think this is to be expected) and so kibana does not pick up the field.

Do I need to update the mappings each time I decide to add a new field to an existing document or is there another way to somewhat automate this?

I am using Elasticsearch-7.13.2

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [August 3, 2021, 6:55am UTC](https://discuss.elastic.co/t/update-documents-and-field-mapping/280277/2 "2021-08-03T06:55:16Z")

</div>

> [@Dheeraj\_Gupta](#):
>
> The problem is that field mappings do not get updated (I think this is to be expected) and so kibana does not pick up the field.

Can you elaborate more on what you mean/are seeing here?

---

<div class="post-metadata">

### Author: ![Dheeraj\_Gupta](https://avatars.discourse-cdn.com/v4/letter/d/49beb7/32.png) [@Dheeraj\_Gupta](https://discuss.elastic.co/u/Dheeraj_Gupta)
#### Post date: [August 3, 2021, 7:28am UTC](https://discuss.elastic.co/t/update-documents-and-field-mapping/280277/3 "2021-08-03T07:28:21Z")

</div>

Hi, Sorry for not being clear.

My program adds a new field to many documents in index A like so (this is run in a loop)

```auto
es.update(index=hit_index, id=hit_id,
          body={"doc": {"periodic_prob": period_prob}})

```

Right now all values of this field are `null`.

After I add a new field to an existing document, it does not reflect in Kibana (discover or index pattern or even browsing individual document) but can be seen when doc is fetched using elasticsearch.

 ![es_fetch](https://us1.discourse-cdn.com/elastic/original/3X/d/d/ddffbd113abffb3c839fd88aeff5db858ac38063.png)

I looked up the field mapping for the index A on elasticsearch and the field was missing which I figure is what Kibana uses since 7.11.x

I used the update mapping API to add the new mapping for the field

```auto
curl -X PUT "esmasters:9200/myindex/_mapping?pretty" -H 'Content-Type: application/json' -d'
> {
> "properties": {
> "periodic_prob": {
> "type": "float"
> }
> }
> }
> '
{
  "acknowledged" : true
}

```

and the field showed up under Index Pattern in Kibana.

 ![index_pattern](https://us1.discourse-cdn.com/elastic/original/3X/2/d/2d9dc53f1104ab49827b2823c81288476ca51847.png)

However even now the field cannot be seen when browsing individual docs under Kibana or when using the discover tab.

 ![kibana_doc](https://us1.discourse-cdn.com/elastic/original/3X/b/5/b5a2902f1c30ad717128278e7fac880466fb47db.png)

I guess this is more of a Kibana issue but my original question was what should the workflow be like when updating an elasticsearch document with a new field? Update mapping first (and template if there is one) and then add the field? Can we perform a blind mapping update or should we first verify that the said mapping does not exist?

---

<div class="post-metadata">

### Author: ![Dheeraj\_Gupta](https://avatars.discourse-cdn.com/v4/letter/d/49beb7/32.png) [@Dheeraj\_Gupta](https://discuss.elastic.co/u/Dheeraj_Gupta)
#### Post date: [August 3, 2021, 10:11am UTC](https://discuss.elastic.co/t/update-documents-and-field-mapping/280277/4 "2021-08-03T10:11:26Z")

</div>

Ok so I think having `null` values was what tripped Kibana. After adding real values, I can see the doc OK in Kibana.

On update, Elasticsearch automatically updates the mapping of the document and Kibana picks up the new mapping. A manual mapping update is not necessary. Just make sure all entries for the attribute are of the same type or future indexing will fail with error.

---

<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: [August 31, 2021, 10:11am UTC](https://discuss.elastic.co/t/update-documents-and-field-mapping/280277/5 "2021-08-31T10:11:53Z")

</div>

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