3434import org .elasticsearch .common .Explicit ;
3535import org .elasticsearch .common .geo .GeoUtils ;
3636import org .elasticsearch .common .geo .SpatialStrategy ;
37+ import org .elasticsearch .common .geo .XShapeCollection ;
3738import org .elasticsearch .common .geo .builders .ShapeBuilder ;
3839import org .elasticsearch .common .geo .builders .ShapeBuilder .Orientation ;
3940import org .elasticsearch .common .geo .parsers .ShapeParser ;
@@ -463,7 +464,6 @@ public GeoShapeFieldMapper(String simpleName, MappedFieldType fieldType, Explici
463464 public GeoShapeFieldType fieldType () {
464465 return (GeoShapeFieldType ) super .fieldType ();
465466 }
466-
467467 @ Override
468468 public Mapper parse (ParseContext context ) throws IOException {
469469 try {
@@ -475,14 +475,20 @@ public Mapper parse(ParseContext context) throws IOException {
475475 }
476476 shape = shapeBuilder .build ();
477477 }
478- if (fieldType ().pointsOnly () && !(shape instanceof Point )) {
479- throw new MapperParsingException ("[{" + fieldType ().name () + "}] is configured for points only but a " +
480- ((shape instanceof JtsGeometry ) ? ((JtsGeometry ) shape ).getGeom ().getGeometryType () : shape .getClass ()) + " was found" );
481- }
482- List <IndexableField > fields = new ArrayList <>(Arrays .asList (fieldType ().defaultStrategy ().createIndexableFields (shape )));
483- createFieldNamesField (context , fields );
484- for (IndexableField field : fields ) {
485- context .doc ().add (field );
478+ if (fieldType ().pointsOnly () == true ) {
479+ // index configured for pointsOnly
480+ if (shape instanceof XShapeCollection && XShapeCollection .class .cast (shape ).pointsOnly ()) {
481+ // MULTIPOINT data: index each point separately
482+ List <Shape > shapes = ((XShapeCollection ) shape ).getShapes ();
483+ for (Shape s : shapes ) {
484+ indexShape (context , s );
485+ }
486+ } else if (shape instanceof Point == false ) {
487+ throw new MapperParsingException ("[{" + fieldType ().name () + "}] is configured for points only but a " +
488+ ((shape instanceof JtsGeometry ) ? ((JtsGeometry )shape ).getGeom ().getGeometryType () : shape .getClass ()) + " was found" );
489+ }
490+ } else {
491+ indexShape (context , shape );
486492 }
487493 } catch (Exception e ) {
488494 if (ignoreMalformed .value () == false ) {
@@ -492,6 +498,14 @@ public Mapper parse(ParseContext context) throws IOException {
492498 return null ;
493499 }
494500
501+ private void indexShape (ParseContext context , Shape shape ) {
502+ List <IndexableField > fields = new ArrayList <>(Arrays .asList (fieldType ().defaultStrategy ().createIndexableFields (shape )));
503+ createFieldNamesField (context , fields );
504+ for (IndexableField field : fields ) {
505+ context .doc ().add (field );
506+ }
507+ }
508+
495509 @ Override
496510 protected void parseCreateField (ParseContext context , List <IndexableField > fields ) throws IOException {
497511 }
0 commit comments