Sven Grosen
Sven Grosen

Reputation: 5636

Pass update_all_types on ElasticSearch Put Mapping

We are upgrading to ElasticSearch 2.0 and have come across an issue with our mappings in Nest 1.7.0 : we have two types that share a field (with the same format):

"@timestamp": {
            "type": "date",
            "format": "epoch_millis||dateOptionalTime"
          }

When we try to add a mapping on startup for one of the affected types (we are currently PUTing the mappings every time), we get this error back:

{
  "error": {
    "root_cause": [{
      "type": "merge_mapping_exception",
      "reason": "Merge failed with failures {[mapper [@timestamp] is used by multiple types. Set update_all_types to true to update [format] across all types.]}"
    }],
    "type": "merge_mapping_exception",
    "reason": "Merge failed with failures {[mapper [@timestamp] is used by multiple types. Set update_all_types to true to update [format] across all types.]}"
  },
  "status": 400
}

We are using a code based mapping described here, but I do not see a way of hanging a query string off of this method without resorting to the Raw property of our client using something like this:

_client.Raw.IndicesPutMapping("ourindex", "ourtype", PutMappingDescriptorObj, parameters => parameters.AddQueryString("update_all_types", null));

I've browsed the 2.0 branch of Nest, but have not found any references to this update_all_types query string parameter for these mapping calls.

Assuming that IndicesPutMapping() call could be made to work, is that our only option at this point? I am starting to wonder if we should instead only conditionally add these mappings.

Upvotes: 0

Views: 1284

Answers (1)

Sven Grosen
Sven Grosen

Reputation: 5636

It turns out that we were able to find another way: when we were creating our mapping we were not explicitly providing a format for our @timestamp field, and with 2.0 that seemingly caused the system to treat it as a change, hence our issue. We were able to get past this by, in our mapping logic, pin on the existing format for these date fields like this:

// formatted strangely to make the addition more obvious
_client.Map<OurType>(m =>
    m.Properties(ps => ps
        .Date(d => d.Name(es => es.Date) // es is a reference to an instance of OurType, and Date is the name of the field being mapped to @timestamp
                    .Format("epoch_millis||dateOptionalTime") // this is what fixed it
             )
        //other props
    )
    //other stuff
);

Upvotes: 0

Related Questions