28
28
import org .elasticsearch .action .ValidateActions ;
29
29
import org .elasticsearch .action .support .IndicesOptions ;
30
30
import org .elasticsearch .common .Nullable ;
31
+ import org .elasticsearch .common .ParseField ;
31
32
import org .elasticsearch .common .ParsingException ;
32
33
import org .elasticsearch .common .Strings ;
33
34
import org .elasticsearch .common .io .stream .StreamInput ;
48
49
49
50
public class MultiGetRequest extends ActionRequest implements Iterable <MultiGetRequest .Item >, CompositeIndicesRequest , RealtimeRequest {
50
51
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" );
56
+ private static final ParseField PARENT = new ParseField ("parent" );
57
+ private static final ParseField VERSION = new ParseField ("version" );
58
+ private static final ParseField VERSION_TYPE = new ParseField ("version_type" );
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
+
51
63
/**
52
64
* A single get item.
53
65
*/
@@ -379,30 +391,30 @@ public static void parseDocuments(XContentParser parser, List<Item> items, @Null
379
391
if (token == XContentParser .Token .FIELD_NAME ) {
380
392
currentFieldName = parser .currentName ();
381
393
} else if (token .isValue ()) {
382
- if ("_index" . equals (currentFieldName )) {
394
+ if (INDEX . match (currentFieldName )) {
383
395
if (!allowExplicitIndex ) {
384
396
throw new IllegalArgumentException ("explicit index in multi get is not allowed" );
385
397
}
386
398
index = parser .text ();
387
- } else if ("_type" . equals (currentFieldName )) {
399
+ } else if (TYPE . match (currentFieldName )) {
388
400
type = parser .text ();
389
- } else if ("_id" . equals (currentFieldName )) {
401
+ } else if (ID . match (currentFieldName )) {
390
402
id = parser .text ();
391
- } else if ("_routing" . equals ( currentFieldName ) || "routing" . equals (currentFieldName )) {
403
+ } else if (ROUTING . match (currentFieldName )) {
392
404
routing = parser .text ();
393
- } else if ("_parent" . equals ( currentFieldName ) || "parent" . equals (currentFieldName )) {
405
+ } else if (PARENT . match (currentFieldName )) {
394
406
parent = parser .text ();
395
- } else if ("fields" . equals (currentFieldName )) {
407
+ } else if (FIELDS . match (currentFieldName )) {
396
408
throw new ParsingException (parser .getTokenLocation (),
397
409
"Unsupported field [fields] used, expected [stored_fields] instead" );
398
- } else if ("stored_fields" . equals (currentFieldName )) {
410
+ } else if (STORED_FIELDS . match (currentFieldName )) {
399
411
storedFields = new ArrayList <>();
400
412
storedFields .add (parser .text ());
401
- } else if ("_version" . equals ( currentFieldName ) || "version" . equals (currentFieldName )) {
413
+ } else if (VERSION . match (currentFieldName )) {
402
414
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 )) {
404
416
versionType = VersionType .fromString (parser .text ());
405
- } else if ("_source" . equals (currentFieldName )) {
417
+ } else if (SOURCE . match (currentFieldName )) {
406
418
// check lenient to avoid interpreting the value as string but parse strict in order to provoke an error early on.
407
419
if (parser .isBooleanValueLenient ()) {
408
420
fetchSourceContext = new FetchSourceContext (parser .booleanValue (), fetchSourceContext .includes (),
@@ -413,17 +425,19 @@ public static void parseDocuments(XContentParser parser, List<Item> items, @Null
413
425
} else {
414
426
throw new ElasticsearchParseException ("illegal type for _source: [{}]" , token );
415
427
}
428
+ } else {
429
+ throw new ElasticsearchParseException ("failed to parse multi get request. unknown field [{}]" , currentFieldName );
416
430
}
417
431
} else if (token == XContentParser .Token .START_ARRAY ) {
418
- if ("fields" . equals (currentFieldName )) {
432
+ if (FIELDS . match (currentFieldName )) {
419
433
throw new ParsingException (parser .getTokenLocation (),
420
434
"Unsupported field [fields] used, expected [stored_fields] instead" );
421
- } else if ("stored_fields" . equals (currentFieldName )) {
435
+ } else if (STORED_FIELDS . match (currentFieldName )) {
422
436
storedFields = new ArrayList <>();
423
437
while ((token = parser .nextToken ()) != XContentParser .Token .END_ARRAY ) {
424
438
storedFields .add (parser .text ());
425
439
}
426
- } else if ("_source" . equals (currentFieldName )) {
440
+ } else if (SOURCE . match (currentFieldName )) {
427
441
ArrayList <String > includes = new ArrayList <>();
428
442
while ((token = parser .nextToken ()) != XContentParser .Token .END_ARRAY ) {
429
443
includes .add (parser .text ());
@@ -433,7 +447,7 @@ public static void parseDocuments(XContentParser parser, List<Item> items, @Null
433
447
}
434
448
435
449
} else if (token == XContentParser .Token .START_OBJECT ) {
436
- if ("_source" . equals (currentFieldName )) {
450
+ if (SOURCE . match (currentFieldName )) {
437
451
List <String > currentList = null , includes = null , excludes = null ;
438
452
439
453
while ((token = parser .nextToken ()) != XContentParser .Token .END_OBJECT ) {
0 commit comments