diff --git a/src/main/java/org/opensearch/neuralsearch/processor/InferenceProcessor.java b/src/main/java/org/opensearch/neuralsearch/processor/InferenceProcessor.java index 2983e2920..958725451 100644 --- a/src/main/java/org/opensearch/neuralsearch/processor/InferenceProcessor.java +++ b/src/main/java/org/opensearch/neuralsearch/processor/InferenceProcessor.java @@ -209,12 +209,12 @@ private void validateEmbeddingFieldsValue(IngestDocument ingestDocument) { String sourceKey = embeddingFieldsEntry.getKey(); Class sourceValueClass = sourceValue.getClass(); if (List.class.isAssignableFrom(sourceValueClass) || Map.class.isAssignableFrom(sourceValueClass)) { - if(Map.class.isAssignableFrom(embeddingFieldsEntry.getValue().getClass())){ + if (Map.class.isAssignableFrom(embeddingFieldsEntry.getValue().getClass())) { Map innerFieldsEntry = (Map) embeddingFieldsEntry.getValue(); - for(Map.Entry innerKey: innerFieldsEntry.entrySet()){ + for (Map.Entry innerKey : innerFieldsEntry.entrySet()) { validateNestedTypeValue(innerKey.getKey(), sourceValue, () -> 2); } - }else{ + } else { validateNestedTypeValue(sourceKey, sourceValue, () -> 1); } } else if (!String.class.isAssignableFrom(sourceValueClass)) { @@ -232,7 +232,7 @@ private void validateNestedTypeValue(String sourceKey, Object sourceValue, Suppl if (maxDepth > MapperService.INDEX_MAPPING_DEPTH_LIMIT_SETTING.get(environment.settings())) { throw new IllegalArgumentException("map type field [" + sourceKey + "] reached max depth limit, cannot process it"); } else if ((List.class.isAssignableFrom(sourceValue.getClass()))) { - validateListTypeValue(sourceKey, sourceValue); + validateListTypeValue(sourceKey, sourceValue, maxDepthSupplier); } else if (Map.class.isAssignableFrom(sourceValue.getClass())) { ((Map) sourceValue).values() .stream() @@ -246,11 +246,11 @@ private void validateNestedTypeValue(String sourceKey, Object sourceValue, Suppl } @SuppressWarnings({ "rawtypes" }) - private void validateListTypeValue(String sourceKey, Object sourceValue) { + private void validateListTypeValue(String sourceKey, Object sourceValue, Supplier maxDepthSupplier) { for (Object value : (List) sourceValue) { - if(value instanceof Map){ - validateNestedTypeValue(sourceKey, value, () -> 1); - }else if (value == null) { + if (value instanceof Map) { + validateNestedTypeValue(sourceKey, value, () -> maxDepthSupplier.get() + 1); + } else if (value == null) { throw new IllegalArgumentException("list type field [" + sourceKey + "] has null, cannot process it"); } else if (!(value instanceof String)) { throw new IllegalArgumentException("list type field [" + sourceKey + "] has non string value, cannot process it");