Skip to content

Commit

Permalink
Aggregations: Fix geo bounds aggregation when longitude is 0
Browse files Browse the repository at this point in the history
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
  • Loading branch information
colings86 committed May 11, 2015
1 parent 9518e32 commit b4a3def
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Expand Up @@ -130,11 +130,11 @@ public void collect(int docId, long owningBucketOrdinal) throws IOException {
bottom = value.lat();
}
double posLeft = posLefts.get(owningBucketOrdinal);
if (value.lon() > 0 && value.lon() < posLeft) {
if (value.lon() >= 0 && value.lon() < posLeft) {
posLeft = value.lon();
}
double posRight = posRights.get(owningBucketOrdinal);
if (value.lon() > 0 && value.lon() > posRight) {
if (value.lon() >= 0 && value.lon() > posRight) {
posRight = value.lon();
}
double negLeft = negLefts.get(owningBucketOrdinal);
Expand Down
Expand Up @@ -153,6 +153,10 @@ public void setupSuiteScopeCluster() throws Exception {
.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();

Expand Down Expand Up @@ -376,4 +380,22 @@ public void singleValuedFieldAsSubAggToHighCardTermsAgg() {
}
}

@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));
}

}

0 comments on commit b4a3def

Please sign in to comment.