Skip to content

Commit

Permalink
HSEARCH-4173 Assume no value in spatial predicates if the target fiel…
Browse files Browse the repository at this point in the history
…d doesn't exist in one of the targeted indexes

Signed-off-by: Yoann Rodière <yoann@hibernate.org>
  • Loading branch information
yrodiere committed Mar 2, 2021
1 parent a6c63ca commit 7549bd6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
Expand Up @@ -24,7 +24,10 @@

public class ElasticsearchGeoPointSpatialWithinBoundingBoxPredicate extends AbstractElasticsearchSingleFieldPredicate {

private static final JsonObjectAccessor GEO_BOUNDING_BOX_ACCESSOR = JsonAccessor.root().property( "geo_bounding_box" ).asObject();
private static final JsonObjectAccessor GEO_BOUNDING_BOX_ACCESSOR =
JsonAccessor.root().property( "geo_bounding_box" ).asObject();
private static final JsonAccessor<Boolean> IGNORE_UNMAPPED_ACCESSOR =
JsonAccessor.root().property( "ignore_unmapped" ).asBoolean();

private static final String TOP_LEFT_PROPERTY_NAME = "top_left";
private static final String BOTTOM_RIGHT_PROPERTY_NAME = "bottom_right";
Expand All @@ -47,6 +50,12 @@ protected JsonObject doToJsonQuery(PredicateRequestContext context, JsonObject o

innerObject.add( absoluteFieldPath, boundingBoxObject );

if ( indexNames().size() > 1 ) {
// There are multiple target indexes; some of them may not declare the field.
// Instruct ES to behave as if the field had no value in that case.
IGNORE_UNMAPPED_ACCESSOR.set( innerObject, true );
}

GEO_BOUNDING_BOX_ACCESSOR.set( outerObject, innerObject );
return outerObject;
}
Expand Down
Expand Up @@ -24,9 +24,12 @@

public class ElasticsearchGeoPointSpatialWithinCirclePredicate extends AbstractElasticsearchSingleFieldPredicate {

private static final JsonObjectAccessor GEO_DISTANCE_ACCESSOR = JsonAccessor.root().property( "geo_distance" ).asObject();

private static final JsonAccessor<Double> DISTANCE_ACCESSOR = JsonAccessor.root().property( "distance" ).asDouble();
private static final JsonObjectAccessor GEO_DISTANCE_ACCESSOR =
JsonAccessor.root().property( "geo_distance" ).asObject();
private static final JsonAccessor<Double> DISTANCE_ACCESSOR =
JsonAccessor.root().property( "distance" ).asDouble();
private static final JsonAccessor<Boolean> IGNORE_UNMAPPED_ACCESSOR =
JsonAccessor.root().property( "ignore_unmapped" ).asBoolean();

private final double distanceInMeters;
private final JsonElement center;
Expand All @@ -43,6 +46,12 @@ protected JsonObject doToJsonQuery(PredicateRequestContext context, JsonObject o
DISTANCE_ACCESSOR.set( innerObject, distanceInMeters );
innerObject.add( absoluteFieldPath, center );

if ( indexNames().size() > 1 ) {
// There are multiple target indexes; some of them may not declare the field.
// Instruct ES to behave as if the field had no value in that case.
IGNORE_UNMAPPED_ACCESSOR.set( innerObject, true );
}

GEO_DISTANCE_ACCESSOR.set( outerObject, innerObject );
return outerObject;
}
Expand Down
Expand Up @@ -25,7 +25,10 @@

public class ElasticsearchGeoPointSpatialWithinPolygonPredicate extends AbstractElasticsearchSingleFieldPredicate {

private static final JsonObjectAccessor GEO_POLYGON_ACCESSOR = JsonAccessor.root().property( "geo_polygon" ).asObject();
private static final JsonObjectAccessor GEO_POLYGON_ACCESSOR =
JsonAccessor.root().property( "geo_polygon" ).asObject();
private static final JsonAccessor<Boolean> IGNORE_UNMAPPED_ACCESSOR =
JsonAccessor.root().property( "ignore_unmapped" ).asBoolean();

private static final String POINTS_PROPERTY_NAME = "points";

Expand All @@ -50,6 +53,13 @@ protected JsonObject doToJsonQuery(PredicateRequestContext context, JsonObject o
pointsObject.add( POINTS_PROPERTY_NAME, pointsArray );

innerObject.add( absoluteFieldPath, pointsObject );

if ( indexNames().size() > 1 ) {
// There are multiple target indexes; some of them may not declare the field.
// Instruct ES to behave as if the field had no value in that case.
IGNORE_UNMAPPED_ACCESSOR.set( innerObject, true );
}

GEO_POLYGON_ACCESSOR.set( outerObject, innerObject );
return outerObject;
}
Expand Down

0 comments on commit 7549bd6

Please sign in to comment.