// check type first
Object type = content.get("type");
if (type instanceof String) {
String typeString = type.toString();
FieldType fieldType = FieldType.parse(typeString);
// handle multi_field separately
if (FieldType.MULTI_FIELD == fieldType) {
// get fields
Map<String, Object> fields = (Map<String, Object>) content.get("fields");
// return default field
Map<String, Object> defaultField = (Map<String, Object>) fields.get(key);
FieldType defaultType = null;
// check if there's no default field - corner case but is possible on 0.90
// if so, check the field types and if all are the same, use that
if (defaultField == null) {
String defaultFieldName = null;
for (Entry<String, Object> subfield : fields.entrySet()) {
Map<String, Object> subFieldDef = (Map<String, Object>) subfield.getValue();
FieldType subFieldType = FieldType.parse(subFieldDef.get("type").toString());
if (defaultType != null) {
if (defaultType != subFieldType) {
throw new EsHadoopIllegalArgumentException(
String.format("Ambiguous mapping, multi_field [%s] provides no default field and subfields have different mapping types [%s=%s], [%s=%s]",
key, defaultFieldName, defaultType, subfield.getKey(), subFieldType));