31
31
import org .elasticsearch .common .xcontent .XContentSubParser ;
32
32
import org .elasticsearch .common .xcontent .support .MapXContentParser ;
33
33
import org .elasticsearch .common .xcontent .support .XContentMapValues ;
34
- import org .elasticsearch .geo .geometry .Rectangle ;
35
- import org .elasticsearch .geo .utils .Geohash ;
36
34
import org .elasticsearch .index .fielddata .FieldData ;
37
35
import org .elasticsearch .index .fielddata .GeoPointValues ;
38
36
import org .elasticsearch .index .fielddata .MultiGeoPointValues ;
@@ -476,7 +474,7 @@ public static GeoPoint parseGeoPoint(XContentParser parser, GeoPoint point, fina
476
474
if (!Double .isNaN (lat ) || !Double .isNaN (lon )) {
477
475
throw new ElasticsearchParseException ("field must be either lat/lon or geohash" );
478
476
} else {
479
- return parseGeoHash (point , geohash , effectivePoint );
477
+ return point . parseGeoHash (geohash , effectivePoint );
480
478
}
481
479
} else if (numberFormatException != null ) {
482
480
throw new ElasticsearchParseException ("[{}] and [{}] must be valid double values" , numberFormatException , LATITUDE ,
@@ -499,8 +497,10 @@ public static GeoPoint parseGeoPoint(XContentParser parser, GeoPoint point, fina
499
497
lon = subParser .doubleValue ();
500
498
} else if (element == 2 ) {
501
499
lat = subParser .doubleValue ();
502
- } else {
500
+ } else if ( element == 3 ) {
503
501
GeoPoint .assertZValue (ignoreZValue , subParser .doubleValue ());
502
+ } else {
503
+ throw new ElasticsearchParseException ("[geo_point] field type does not accept > 3 dimensions" );
504
504
}
505
505
} else {
506
506
throw new ElasticsearchParseException ("numeric value expected" );
@@ -510,35 +510,12 @@ public static GeoPoint parseGeoPoint(XContentParser parser, GeoPoint point, fina
510
510
return point .reset (lat , lon );
511
511
} else if (parser .currentToken () == Token .VALUE_STRING ) {
512
512
String val = parser .text ();
513
- if (val .contains ("," )) {
514
- return point .resetFromString (val , ignoreZValue );
515
- } else {
516
- return parseGeoHash (point , val , effectivePoint );
517
- }
518
-
513
+ return point .resetFromString (val , ignoreZValue , effectivePoint );
519
514
} else {
520
515
throw new ElasticsearchParseException ("geo_point expected" );
521
516
}
522
517
}
523
518
524
- private static GeoPoint parseGeoHash (GeoPoint point , String geohash , EffectivePoint effectivePoint ) {
525
- if (effectivePoint == EffectivePoint .BOTTOM_LEFT ) {
526
- return point .resetFromGeoHash (geohash );
527
- } else {
528
- Rectangle rectangle = Geohash .toBoundingBox (geohash );
529
- switch (effectivePoint ) {
530
- case TOP_LEFT :
531
- return point .reset (rectangle .getMaxLat (), rectangle .getMinLon ());
532
- case TOP_RIGHT :
533
- return point .reset (rectangle .getMaxLat (), rectangle .getMaxLon ());
534
- case BOTTOM_RIGHT :
535
- return point .reset (rectangle .getMinLat (), rectangle .getMaxLon ());
536
- default :
537
- throw new IllegalArgumentException ("Unsupported effective point " + effectivePoint );
538
- }
539
- }
540
- }
541
-
542
519
/**
543
520
* Parse a {@link GeoPoint} from a string. The string must have one of the following forms:
544
521
*
@@ -552,12 +529,7 @@ private static GeoPoint parseGeoHash(GeoPoint point, String geohash, EffectivePo
552
529
*/
553
530
public static GeoPoint parseFromString (String val ) {
554
531
GeoPoint point = new GeoPoint ();
555
- boolean ignoreZValue = false ;
556
- if (val .contains ("," )) {
557
- return point .resetFromString (val , ignoreZValue );
558
- } else {
559
- return parseGeoHash (point , val , EffectivePoint .BOTTOM_LEFT );
560
- }
532
+ return point .resetFromString (val , false , EffectivePoint .BOTTOM_LEFT );
561
533
}
562
534
563
535
/**
0 commit comments