@@ -1349,26 +1349,39 @@ private static String[] processPathParts(String fullPath, String[] pathParts, In
13491349 throw new IllegalArgumentException ("path [" + fullPath + "] is not valid" );
13501350 }
13511351 return switch (accessPattern ) {
1352- case CLASSIC -> pathParts ;
1352+ case CLASSIC -> validateClassicFields ( fullPath , pathParts ) ;
13531353 case FLEXIBLE -> parseFlexibleFields (fullPath , pathParts );
13541354 };
13551355 }
13561356
1357+ /**
1358+ * Parses path syntax that is specific to the {@link IngestPipelineFieldAccessPattern#CLASSIC} ingest doc access pattern. Supports
1359+ * syntax like context aware array access.
1360+ * @param fullPath The un-split path to use for error messages
1361+ * @param pathParts The tokenized field path to parse
1362+ * @return An array of Strings
1363+ */
1364+ private static String [] validateClassicFields (String fullPath , String [] pathParts ) {
1365+ for (String pathPart : pathParts ) {
1366+ if (pathPart .isEmpty ()) {
1367+ throw new IllegalArgumentException ("path [" + fullPath + "] is not valid" );
1368+ }
1369+ }
1370+ return pathParts ;
1371+ }
1372+
13571373 /**
13581374 * Parses path syntax that is specific to the {@link IngestPipelineFieldAccessPattern#FLEXIBLE} ingest doc access pattern. Supports
13591375 * syntax like square bracket array access, which is the only way to index arrays in flexible mode.
13601376 * @param fullPath The un-split path to use for error messages
13611377 * @param pathParts The tokenized field path to parse
1362- * @return An array of Elements
1378+ * @return An array of Strings
13631379 */
13641380 private static String [] parseFlexibleFields (String fullPath , String [] pathParts ) {
1365- boolean invalidPath = Arrays .stream (pathParts ).anyMatch (pathPart -> {
1366- int openBracket = pathPart .indexOf ('[' );
1367- int closedBracket = pathPart .indexOf (']' );
1368- return openBracket != -1 && closedBracket != -1 ;
1369- });
1370- if (invalidPath ) {
1371- throw new IllegalArgumentException ("path [" + fullPath + "] is not valid" );
1381+ for (String pathPart : pathParts ) {
1382+ if (pathPart .isEmpty () || pathPart .indexOf ('[' ) >= 0 || pathPart .indexOf (']' ) >= 0 ) {
1383+ throw new IllegalArgumentException ("path [" + fullPath + "] is not valid" );
1384+ }
13721385 }
13731386 return pathParts ;
13741387 }
0 commit comments