Updating Child Mapping with new field fails with NullPointerException

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

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

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

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

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

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.

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

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