2828import org .elasticsearch .action .ValidateActions ;
2929import org .elasticsearch .action .support .IndicesOptions ;
3030import org .elasticsearch .common .Nullable ;
31+ import org .elasticsearch .common .ParseField ;
3132import org .elasticsearch .common .ParsingException ;
3233import org .elasticsearch .common .Strings ;
3334import org .elasticsearch .common .io .stream .StreamInput ;
4849
4950public class MultiGetRequest extends ActionRequest implements Iterable <MultiGetRequest .Item >, CompositeIndicesRequest , RealtimeRequest {
5051
52+ private static final ParseField INDEX = new ParseField ("_index" );
53+ private static final ParseField TYPE = new ParseField ("_type" );
54+ private static final ParseField ID = new ParseField ("_id" );
55+ private static final ParseField ROUTING = new ParseField ("routing" , "_routing" );
56+ private static final ParseField PARENT = new ParseField ("parent" , "_parent" );
57+ private static final ParseField VERSION = new ParseField ("version" , "_version" );
58+ private static final ParseField VERSION_TYPE = new ParseField ("version_type" , "_version_type" , "_versionType" , "versionType" );
59+ private static final ParseField FIELDS = new ParseField ("fields" );
60+ private static final ParseField STORED_FIELDS = new ParseField ("stored_fields" );
61+ private static final ParseField SOURCE = new ParseField ("_source" );
62+
5163 /**
5264 * A single get item.
5365 */
@@ -379,30 +391,30 @@ public static void parseDocuments(XContentParser parser, List<Item> items, @Null
379391 if (token == XContentParser .Token .FIELD_NAME ) {
380392 currentFieldName = parser .currentName ();
381393 } else if (token .isValue ()) {
382- if ("_index" . equals (currentFieldName )) {
394+ if (INDEX . match (currentFieldName )) {
383395 if (!allowExplicitIndex ) {
384396 throw new IllegalArgumentException ("explicit index in multi get is not allowed" );
385397 }
386398 index = parser .text ();
387- } else if ("_type" . equals (currentFieldName )) {
399+ } else if (TYPE . match (currentFieldName )) {
388400 type = parser .text ();
389- } else if ("_id" . equals (currentFieldName )) {
401+ } else if (ID . match (currentFieldName )) {
390402 id = parser .text ();
391- } else if ("_routing" . equals ( currentFieldName ) || "routing" . equals (currentFieldName )) {
403+ } else if (ROUTING . match (currentFieldName )) {
392404 routing = parser .text ();
393- } else if ("_parent" . equals ( currentFieldName ) || "parent" . equals (currentFieldName )) {
405+ } else if (PARENT . match (currentFieldName )) {
394406 parent = parser .text ();
395- } else if ("fields" . equals (currentFieldName )) {
407+ } else if (FIELDS . match (currentFieldName )) {
396408 throw new ParsingException (parser .getTokenLocation (),
397409 "Unsupported field [fields] used, expected [stored_fields] instead" );
398- } else if ("stored_fields" . equals (currentFieldName )) {
410+ } else if (STORED_FIELDS . match (currentFieldName )) {
399411 storedFields = new ArrayList <>();
400412 storedFields .add (parser .text ());
401- } else if ("_version" . equals ( currentFieldName ) || "version" . equals (currentFieldName )) {
413+ } else if (VERSION . match (currentFieldName )) {
402414 version = parser .longValue ();
403- } else if ("_version_type" . equals ( currentFieldName ) || "_versionType" . equals ( currentFieldName ) || "version_type" . equals ( currentFieldName ) || "versionType" . equals (currentFieldName )) {
415+ } else if (VERSION_TYPE . match (currentFieldName )) {
404416 versionType = VersionType .fromString (parser .text ());
405- } else if ("_source" . equals (currentFieldName )) {
417+ } else if (SOURCE . match (currentFieldName )) {
406418 // check lenient to avoid interpreting the value as string but parse strict in order to provoke an error early on.
407419 if (parser .isBooleanValueLenient ()) {
408420 fetchSourceContext = new FetchSourceContext (parser .booleanValue (), fetchSourceContext .includes (),
@@ -413,17 +425,19 @@ public static void parseDocuments(XContentParser parser, List<Item> items, @Null
413425 } else {
414426 throw new ElasticsearchParseException ("illegal type for _source: [{}]" , token );
415427 }
428+ } else {
429+ throw new ElasticsearchParseException ("failed to parse multi get request. unknown field [{}]" , currentFieldName );
416430 }
417431 } else if (token == XContentParser .Token .START_ARRAY ) {
418- if ("fields" . equals (currentFieldName )) {
432+ if (FIELDS . match (currentFieldName )) {
419433 throw new ParsingException (parser .getTokenLocation (),
420434 "Unsupported field [fields] used, expected [stored_fields] instead" );
421- } else if ("stored_fields" . equals (currentFieldName )) {
435+ } else if (STORED_FIELDS . match (currentFieldName )) {
422436 storedFields = new ArrayList <>();
423437 while ((token = parser .nextToken ()) != XContentParser .Token .END_ARRAY ) {
424438 storedFields .add (parser .text ());
425439 }
426- } else if ("_source" . equals (currentFieldName )) {
440+ } else if (SOURCE . match (currentFieldName )) {
427441 ArrayList <String > includes = new ArrayList <>();
428442 while ((token = parser .nextToken ()) != XContentParser .Token .END_ARRAY ) {
429443 includes .add (parser .text ());
@@ -433,7 +447,7 @@ public static void parseDocuments(XContentParser parser, List<Item> items, @Null
433447 }
434448
435449 } else if (token == XContentParser .Token .START_OBJECT ) {
436- if ("_source" . equals (currentFieldName )) {
450+ if (SOURCE . match (currentFieldName )) {
437451 List <String > currentList = null , includes = null , excludes = null ;
438452
439453 while ((token = parser .nextToken ()) != XContentParser .Token .END_OBJECT ) {
0 commit comments