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 ;
@@ -154,6 +155,10 @@ public SortedNumericDocValues getInternalValues() {
154
155
155
156
public long getValue () {
156
157
if (count == 0 ) {
158
+ if (ScriptModule .EXCEPTION_FOR_MISSING_VALUE ) {
159
+ throw new IllegalStateException ("A document doesn't have a value for a field! " +
160
+ "Use doc[<field>].size()==0 to check if a document is missing a field!" );
161
+ }
157
162
return 0L ;
158
163
}
159
164
return values [0 ];
@@ -246,6 +251,10 @@ public Dates(SortedNumericDocValues in) {
246
251
*/
247
252
public ReadableDateTime getValue () {
248
253
if (count == 0 ) {
254
+ if (ScriptModule .EXCEPTION_FOR_MISSING_VALUE ) {
255
+ throw new IllegalStateException ("A document doesn't have a value for a field! " +
256
+ "Use doc[<field>].size()==0 to check if a document is missing a field!" );
257
+ }
249
258
return EPOCH ;
250
259
}
251
260
return get (0 );
@@ -381,6 +390,10 @@ public SortedNumericDoubleValues getInternalValues() {
381
390
382
391
public double getValue () {
383
392
if (count == 0 ) {
393
+ if (ScriptModule .EXCEPTION_FOR_MISSING_VALUE ) {
394
+ throw new IllegalStateException ("A document doesn't have a value for a field! " +
395
+ "Use doc[<field>].size()==0 to check if a document is missing a field!" );
396
+ }
384
397
return 0d ;
385
398
}
386
399
return values [0 ];
@@ -437,6 +450,10 @@ protected void resize(int newSize) {
437
450
438
451
public GeoPoint getValue () {
439
452
if (count == 0 ) {
453
+ if (ScriptModule .EXCEPTION_FOR_MISSING_VALUE ) {
454
+ throw new IllegalStateException ("A document doesn't have a value for a field! " +
455
+ "Use doc[<field>].size()==0 to check if a document is missing a field!" );
456
+ }
440
457
return null ;
441
458
}
442
459
return values [0 ];
@@ -549,7 +566,14 @@ protected void resize(int newSize) {
549
566
}
550
567
551
568
public boolean getValue () {
552
- return count != 0 && values [0 ];
569
+ if (count == 0 ) {
570
+ if (ScriptModule .EXCEPTION_FOR_MISSING_VALUE ) {
571
+ throw new IllegalStateException ("A document doesn't have a value for a field! " +
572
+ "Use doc[<field>].size()==0 to check if a document is missing a field!" );
573
+ }
574
+ return false ;
575
+ }
576
+ return values [0 ];
553
577
}
554
578
555
579
@ Override
@@ -632,7 +656,14 @@ public String get(int index) {
632
656
}
633
657
634
658
public String getValue () {
635
- return count == 0 ? null : get (0 );
659
+ if (count == 0 ) {
660
+ if (ScriptModule .EXCEPTION_FOR_MISSING_VALUE ) {
661
+ throw new IllegalStateException ("A document doesn't have a value for a field! " +
662
+ "Use doc[<field>].size()==0 to check if a document is missing a field!" );
663
+ }
664
+ return null ;
665
+ }
666
+ return get (0 );
636
667
}
637
668
}
638
669
@@ -653,7 +684,14 @@ public BytesRef get(int index) {
653
684
}
654
685
655
686
public BytesRef getValue () {
656
- return count == 0 ? new BytesRef () : get (0 );
687
+ if (count == 0 ) {
688
+ if (ScriptModule .EXCEPTION_FOR_MISSING_VALUE ) {
689
+ throw new IllegalStateException ("A document doesn't have a value for a field! " +
690
+ "Use doc[<field>].size()==0 to check if a document is missing a field!" );
691
+ }
692
+ return new BytesRef ();
693
+ }
694
+ return get (0 );
657
695
}
658
696
659
697
}
0 commit comments