Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coerce validation_method in GeoBoundingBoxQueryBuilder #31747

Merged
merged 1 commit into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ public static GeoBoundingBoxQueryBuilder fromXContent(XContentParser parser) thr
GeoValidationMethod validationMethod = null;
boolean ignoreUnmapped = DEFAULT_IGNORE_UNMAPPED;

Rectangle bbox = null;
// bottom (minLat), top (maxLat), left (minLon), right (maxLon)
double[] bbox = null;
String type = "memory";

while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
Expand Down Expand Up @@ -424,8 +425,8 @@ public static GeoBoundingBoxQueryBuilder fromXContent(XContentParser parser) thr
throw new ElasticsearchParseException("failed to parse [{}] query. bounding box not provided", NAME);
}

final GeoPoint topLeft = new GeoPoint(bbox.maxLat, bbox.minLon); //just keep the object
final GeoPoint bottomRight = new GeoPoint(bbox.minLat, bbox.maxLon);
final GeoPoint topLeft = new GeoPoint(bbox[1], bbox[2]);
final GeoPoint bottomRight = new GeoPoint(bbox[0], bbox[3]);

GeoBoundingBoxQueryBuilder builder = new GeoBoundingBoxQueryBuilder(fieldName);
builder.setCorners(topLeft, bottomRight);
Expand Down Expand Up @@ -460,7 +461,10 @@ public String getWriteableName() {
return NAME;
}

public static Rectangle parseBoundingBox(XContentParser parser) throws IOException, ElasticsearchParseException {
/**
* Parses the bounding box and returns bottom, top, left, right coordinates
*/
public static double[] parseBoundingBox(XContentParser parser) throws IOException, ElasticsearchParseException {
XContentParser.Token token = parser.currentToken();
if (token != XContentParser.Token.START_OBJECT) {
throw new ElasticsearchParseException("failed to parse bounding box. Expected start object but found [{}]", token);
Expand Down Expand Up @@ -521,8 +525,8 @@ public static Rectangle parseBoundingBox(XContentParser parser) throws IOExcepti
+ "using well-known text and explicit corners.");
}
org.locationtech.spatial4j.shape.Rectangle r = envelope.build();
return new Rectangle(r.getMinY(), r.getMaxY(), r.getMinX(), r.getMaxX());
return new double[]{r.getMinY(), r.getMaxY(), r.getMinX(), r.getMaxX()};
}
return new Rectangle(bottom, top, left, right);
return new double[]{bottom, top, left, right};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,26 @@ public void testMalformedGeohashes() {
assertThat(e1.getMessage(), containsString("Conflicting definition found using well-known text and explicit corners."));
}

public void testHonorsCoercion() throws IOException {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
String query = "{\n" +
" \"geo_bounding_box\": {\n" +
" \"validation_method\": \"COERCE\",\n" +
" \"" + GEO_POINT_FIELD_NAME + "\": {\n" +
" \"top_left\": {\n" +
" \"lat\": -15.5,\n" +
" \"lon\": 176.5\n" +
" },\n" +
" \"bottom_right\": {\n" +
" \"lat\": -19.6,\n" +
" \"lon\": 181\n" +
" }\n" +
" }\n" +
" }\n" +
"}\n";
assertGeoBoundingBoxQuery(query);
}

@Override
public void testMustRewrite() throws IOException {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
Expand Down