Browse Source

[GEO] Fix GeoShapeQueryBuilder to check for valid spatial relations

Refactor left out the spatial strategy check in GeoShapeQueryBuilder.relation
setter method. This commit adds that check back in.
Nicholas Knize 6 years ago
parent
commit
0dfcdf327a

+ 18 - 0
server/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java

@@ -173,6 +173,24 @@ public class GeoShapeQueryBuilder extends AbstractGeometryQueryBuilder<GeoShapeQ
         return NAME;
     }
 
+    /**
+     * Sets the relation of query shape and indexed shape.
+     *
+     * @param relation relation of the shapes
+     * @return this
+     */
+    public GeoShapeQueryBuilder relation(ShapeRelation relation) {
+        if (relation == null) {
+            throw new IllegalArgumentException("No Shape Relation defined");
+        }
+        if (SpatialStrategy.TERM.equals(strategy) && relation != ShapeRelation.INTERSECTS) {
+            throw new IllegalArgumentException("current strategy [" + strategy.getStrategyName() + "] only supports relation ["
+                + ShapeRelation.INTERSECTS.getRelationName() + "] found relation [" + relation.getRelationName() + "]");
+        }
+        this.relation = relation;
+        return this;
+    }
+
     /**
      * Defines which spatial strategy will be used for building the geo shape
      * Query. When not set, the strategy that will be used will be the one that