Aggregations: Fix geo bounds aggregation when longitude is 0

When the longitude is zero for a document, the left and right bounds do not get updated in the geo bounds aggregation which can cause the bounds to be returned with Infinite values for longitude

Closes #11085
This commit is contained in:
Colin Goodheart-Smithe 2015-05-11 11:56:03 +01:00
parent 36c373e615
commit 671e3ef074
2 changed files with 24 additions and 2 deletions

View File

@ -115,11 +115,11 @@ public final class GeoBoundsAggregator extends MetricsAggregator {
bottom = value.lat();
}
double posLeft = posLefts.get(bucket);
if (value.lon() > 0 && value.lon() < posLeft) {
if (value.lon() >= 0 && value.lon() < posLeft) {
posLeft = value.lon();
}
double posRight = posRights.get(bucket);
if (value.lon() > 0 && value.lon() > posRight) {
if (value.lon() >= 0 && value.lon() > posRight) {
posRight = value.lon();
}
double negLeft = negLefts.get(bucket);

View File

@ -156,6 +156,10 @@ public class GeoBoundsTests extends ElasticsearchIntegrationTest {
.endObject()));
}
builders.add(client().prepareIndex("idx_zero", "type").setSource(
jsonBuilder().startObject().array(SINGLE_VALUED_FIELD_NAME, 0.0, 1.0).endObject()));
assertAcked(prepareCreate("idx_zero").addMapping("type", SINGLE_VALUED_FIELD_NAME, "type=geo_point"));
indexRandom(true, builders);
ensureSearchable();
@ -415,4 +419,22 @@ public class GeoBoundsTests extends ElasticsearchIntegrationTest {
}
}
@Test
public void singleValuedFieldWithZeroLon() throws Exception {
SearchResponse response = client().prepareSearch("idx_zero")
.addAggregation(geoBounds("geoBounds").field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).execute().actionGet();
assertSearchResponse(response);
GeoBounds geoBounds = response.getAggregations().get("geoBounds");
assertThat(geoBounds, notNullValue());
assertThat(geoBounds.getName(), equalTo("geoBounds"));
GeoPoint topLeft = geoBounds.topLeft();
GeoPoint bottomRight = geoBounds.bottomRight();
assertThat(topLeft.lat(), equalTo(1.0));
assertThat(topLeft.lon(), equalTo(0.0));
assertThat(bottomRight.lat(), equalTo(1.0));
assertThat(bottomRight.lon(), equalTo(0.0));
}
}