29
29
import org .elasticsearch .common .geo .GeoUtils ;
30
30
import org .elasticsearch .common .logging .DeprecationLogger ;
31
31
import org .elasticsearch .common .logging .ESLoggerFactory ;
32
+ import org .elasticsearch .script .ScriptModule ;
32
33
import org .joda .time .DateTime ;
33
34
import org .joda .time .DateTimeZone ;
34
35
import org .joda .time .MutableDateTime ;
@@ -125,6 +126,10 @@ protected void resize(int newSize) {
125
126
126
127
public long getValue () {
127
128
if (count == 0 ) {
129
+ if (ScriptModule .EXCEPTION_FOR_MISSING_VALUE ) {
130
+ throw new IllegalStateException ("A document doesn't have a value for a field! " +
131
+ "Use doc[<field>].size()==0 to check if a document is missing a field!" );
132
+ }
128
133
return 0L ;
129
134
}
130
135
return values [0 ];
@@ -167,6 +172,10 @@ public Dates(SortedNumericDocValues in) {
167
172
*/
168
173
public ReadableDateTime getValue () {
169
174
if (count == 0 ) {
175
+ if (ScriptModule .EXCEPTION_FOR_MISSING_VALUE ) {
176
+ throw new IllegalStateException ("A document doesn't have a value for a field! " +
177
+ "Use doc[<field>].size()==0 to check if a document is missing a field!" );
178
+ }
170
179
return EPOCH ;
171
180
}
172
181
return get (0 );
@@ -268,6 +277,10 @@ public SortedNumericDoubleValues getInternalValues() {
268
277
269
278
public double getValue () {
270
279
if (count == 0 ) {
280
+ if (ScriptModule .EXCEPTION_FOR_MISSING_VALUE ) {
281
+ throw new IllegalStateException ("A document doesn't have a value for a field! " +
282
+ "Use doc[<field>].size()==0 to check if a document is missing a field!" );
283
+ }
271
284
return 0d ;
272
285
}
273
286
return values [0 ];
@@ -324,6 +337,10 @@ protected void resize(int newSize) {
324
337
325
338
public GeoPoint getValue () {
326
339
if (count == 0 ) {
340
+ if (ScriptModule .EXCEPTION_FOR_MISSING_VALUE ) {
341
+ throw new IllegalStateException ("A document doesn't have a value for a field! " +
342
+ "Use doc[<field>].size()==0 to check if a document is missing a field!" );
343
+ }
327
344
return null ;
328
345
}
329
346
return values [0 ];
@@ -436,7 +453,14 @@ protected void resize(int newSize) {
436
453
}
437
454
438
455
public boolean getValue () {
439
- return count != 0 && values [0 ];
456
+ if (count == 0 ) {
457
+ if (ScriptModule .EXCEPTION_FOR_MISSING_VALUE ) {
458
+ throw new IllegalStateException ("A document doesn't have a value for a field! " +
459
+ "Use doc[<field>].size()==0 to check if a document is missing a field!" );
460
+ }
461
+ return false ;
462
+ }
463
+ return values [0 ];
440
464
}
441
465
442
466
@ Override
@@ -519,7 +543,14 @@ public String get(int index) {
519
543
}
520
544
521
545
public String getValue () {
522
- return count == 0 ? null : get (0 );
546
+ if (count == 0 ) {
547
+ if (ScriptModule .EXCEPTION_FOR_MISSING_VALUE ) {
548
+ throw new IllegalStateException ("A document doesn't have a value for a field! " +
549
+ "Use doc[<field>].size()==0 to check if a document is missing a field!" );
550
+ }
551
+ return null ;
552
+ }
553
+ return get (0 );
523
554
}
524
555
}
525
556
@@ -540,7 +571,14 @@ public BytesRef get(int index) {
540
571
}
541
572
542
573
public BytesRef getValue () {
543
- return count == 0 ? new BytesRef () : get (0 );
574
+ if (count == 0 ) {
575
+ if (ScriptModule .EXCEPTION_FOR_MISSING_VALUE ) {
576
+ throw new IllegalStateException ("A document doesn't have a value for a field! " +
577
+ "Use doc[<field>].size()==0 to check if a document is missing a field!" );
578
+ }
579
+ return new BytesRef ();
580
+ }
581
+ return get (0 );
544
582
}
545
583
546
584
}
0 commit comments