diff --git a/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesIndexAction.java b/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesIndexAction.java index 2c0d4ef5635e7..4ce810be9311d 100644 --- a/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesIndexAction.java +++ b/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesIndexAction.java @@ -91,16 +91,22 @@ protected FieldCapabilitiesIndexResponse shardOperation(final FieldCapabilitiesI continue; } // add nested and object fields - int dotIndex = ft.name().indexOf('.'); + int dotIndex = ft.name().lastIndexOf('.'); while (dotIndex > -1) { String parentField = ft.name().substring(0, dotIndex); - ObjectMapper mapper = mapperService.getObjectMapper(parentField); - if (mapper != null) { + if (responseMap.containsKey(parentField)) { + // we added this path on another field already + break; + } + // checks if the parent field contains sub-fields + if (mapperService.fullName(parentField) == null) { + // no field type, it must be an object field + ObjectMapper mapper = mapperService.getObjectMapper(parentField); String type = mapper.nested().isNested() ? "nested" : "object"; FieldCapabilities fieldCap = new FieldCapabilities(parentField, type, false, false); responseMap.put(parentField, fieldCap); } - dotIndex = ft.name().indexOf('.', dotIndex + 1); + dotIndex = parentField.lastIndexOf('.'); } } }