# Updating Child Mapping with new field fails with NullPointerException

**URL:** <https://discuss.elastic.co/t/updating-child-mapping-with-new-field-fails-with-nullpointerexception/39256>\
**Category:** Elasticsearch\
**Created:** [January 14, 2016, 6:12pm UTC](https://discuss.elastic.co/t/updating-child-mapping-with-new-field-fails-with-nullpointerexception/39256 "2016-01-14T18:12:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![turp1twin](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@turp1twin](https://discuss.elastic.co/u/turp1twin)\
**Post date:** [January 14, 2016, 6:12pm UTC](https://discuss.elastic.co/t/updating-child-mapping-with-new-field-fails-with-nullpointerexception/39256/1 "2016-01-14T18:12:33Z")

</div>

I am running Elasticsearch 2.1.1. I have an Index which is made of a single parent type and multiple child types. I am trying to update a Child mapping by adding a new field. This results in a NullPointerException on the server:

[2016-01-14 10:48:32,354][DEBUG][action.admin.indices.mapping.put] [Philip Fetter] failed to put mappings on indices [[oha\_patient\_registry]], type [encounters]  
java.lang.NullPointerException  
at org.elasticsearch.index.mapper.MappedFieldType.checkCompatibility(MappedFieldType.java:246)  
at org.elasticsearch.index.mapper.internal.ParentFieldMapper.merge(ParentFieldMapper.java:391)  
at org.elasticsearch.index.mapper.Mapping.merge(Mapping.java:113)  
at org.elasticsearch.index.mapper.DocumentMapper.merge(DocumentMapper.java:396)  
at org.elasticsearch.cluster.metadata.MetaDataMappingService$2.execute(MetaDataMappingService.java:389)  
at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:388)  
at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:231)  
at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:194)  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)  
at java.lang.Thread.run(Thread.java:745)

In Sense the error is displayed as:

{  
"error": {  
"root\_cause": [  
{  
"type": "null\_pointer\_exception",  
"reason": null  
}  
],  
"type": "null\_pointer\_exception",  
"reason": null  
},  
"status": 500  
}

Now it is possible that updating Child mappings is not supported, although I didn't get that from the doc... That being said, an error better than a NPE would be expected. Thoughts?

Jeff

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [January 15, 2016, 9:36am UTC](https://discuss.elastic.co/t/updating-child-mapping-with-new-field-fails-with-nullpointerexception/39256/2 "2016-01-15T09:36:47Z")

</div>

Hi Jeff,

Thanks for bringing this up. This looks like a bug to me. Regardless of parent child adding a field to a mapping should always be possible. I'll investigate this further.

Martijn

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [January 15, 2016, 10:34am UTC](https://discuss.elastic.co/t/updating-child-mapping-with-new-field-fails-with-nullpointerexception/39256/3 "2016-01-15T10:34:41Z")

</div>

The error only occurs if the `_parent` field is forgotten to be added to the put mapping api:

```auto
PUT /my-index/child/_mapping
{
  "child" : {
    "properties" : {
      "new_field" : {"type" : "string"}
    }
  }
}

```

If the `_parent` field is included then the NPE doesn't occur:

```auto
PUT /my-index/child/_mapping
{
  "child" : {
    "_parent" : {"type" : "parent"},
    "properties" : {
      "new_field" : {"type" : "string"}
    }
  }
}

```

and the mapping is updated. When using the put mapping api all the meta fields should be redefined.

Instead of throwing a NPE, ES should report an error that parent type is missing. Actually this does happen, but due to the NPE that error gets lost. I'll fix this.

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [January 15, 2016, 11:14am UTC](https://discuss.elastic.co/t/updating-child-mapping-with-new-field-fails-with-nullpointerexception/39256/4 "2016-01-15T11:14:00Z")

</div>

I opened a PR for this issue: [https://github.com/elastic/elasticsearch/pull/16013](https://github.com/elastic/elasticsearch/pull/16013)

---

<div class="post-metadata">

**Author:** ![turp1twin](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@turp1twin](https://discuss.elastic.co/u/turp1twin)\
**Post date:** [January 20, 2016, 1:33am UTC](https://discuss.elastic.co/t/updating-child-mapping-with-new-field-fails-with-nullpointerexception/39256/5 "2016-01-20T01:33:37Z")

</div>

Thanks Martijn! Appreciate the update.. Sorry for the slow response, I was off for a few days and just got back to work today! Cheers!

Jeff

---

<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:** [July 5, 2017, 11:23pm UTC](https://discuss.elastic.co/t/updating-child-mapping-with-new-field-fails-with-nullpointerexception/39256/6 "2017-07-05T23:23:13Z")

</div>

Closed on July 5, 2017, 11:23pm UTC


