A geo box with a top value of Double.NEGATIVE_INFINITY will yield an empty xContent which translates to a null `geoBoundingBox`. This commit marks the field as `Nullable` and guards against null when retrieving the `topLeft` and `bottomRight` fields. Fixes https://github.com/elastic/elasticsearch/issues/50505 (cherry picked from commit 051718f9b1e1ca957229b01e80d7b79d7e727e14) Signed-off-by: Andrei Dan <andrei.dan@elastic.co>
This commit is contained in:
parent
1abecad21b
commit
856607b5a6
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.search.aggregations.metrics;
|
package org.elasticsearch.search.aggregations.metrics;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.collect.Tuple;
|
import org.elasticsearch.common.collect.Tuple;
|
||||||
import org.elasticsearch.common.geo.GeoBoundingBox;
|
import org.elasticsearch.common.geo.GeoBoundingBox;
|
||||||
import org.elasticsearch.common.geo.GeoPoint;
|
import org.elasticsearch.common.geo.GeoPoint;
|
||||||
|
@ -30,14 +31,17 @@ import org.elasticsearch.search.aggregations.ParsedAggregation;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
|
|
||||||
import static org.elasticsearch.common.geo.GeoBoundingBox.BOTTOM_RIGHT_FIELD;
|
import static org.elasticsearch.common.geo.GeoBoundingBox.BOTTOM_RIGHT_FIELD;
|
||||||
import static org.elasticsearch.common.geo.GeoBoundingBox.BOUNDS_FIELD;
|
import static org.elasticsearch.common.geo.GeoBoundingBox.BOUNDS_FIELD;
|
||||||
import static org.elasticsearch.common.geo.GeoBoundingBox.LAT_FIELD;
|
import static org.elasticsearch.common.geo.GeoBoundingBox.LAT_FIELD;
|
||||||
import static org.elasticsearch.common.geo.GeoBoundingBox.LON_FIELD;
|
import static org.elasticsearch.common.geo.GeoBoundingBox.LON_FIELD;
|
||||||
import static org.elasticsearch.common.geo.GeoBoundingBox.TOP_LEFT_FIELD;
|
import static org.elasticsearch.common.geo.GeoBoundingBox.TOP_LEFT_FIELD;
|
||||||
|
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
|
||||||
|
|
||||||
public class ParsedGeoBounds extends ParsedAggregation implements GeoBounds {
|
public class ParsedGeoBounds extends ParsedAggregation implements GeoBounds {
|
||||||
|
|
||||||
|
// A top of Double.NEGATIVE_INFINITY yields an empty xContent, so the bounding box is null
|
||||||
|
@Nullable
|
||||||
private GeoBoundingBox geoBoundingBox;
|
private GeoBoundingBox geoBoundingBox;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,13 +58,15 @@ public class ParsedGeoBounds extends ParsedAggregation implements GeoBounds {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public GeoPoint topLeft() {
|
public GeoPoint topLeft() {
|
||||||
return geoBoundingBox.topLeft();
|
return geoBoundingBox != null ? geoBoundingBox.topLeft() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public GeoPoint bottomRight() {
|
public GeoPoint bottomRight() {
|
||||||
return geoBoundingBox.bottomRight();
|
return geoBoundingBox != null ? geoBoundingBox.bottomRight() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final ObjectParser<ParsedGeoBounds, Void> PARSER = new ObjectParser<>(ParsedGeoBounds.class.getSimpleName(), true,
|
private static final ObjectParser<ParsedGeoBounds, Void> PARSER = new ObjectParser<>(ParsedGeoBounds.class.getSimpleName(), true,
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.elasticsearch.search.aggregations.metrics;
|
||||||
|
|
||||||
import org.elasticsearch.common.io.stream.Writeable;
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
import org.elasticsearch.search.aggregations.ParsedAggregation;
|
import org.elasticsearch.search.aggregations.ParsedAggregation;
|
||||||
import org.elasticsearch.search.aggregations.metrics.InternalGeoBounds;
|
|
||||||
import org.elasticsearch.search.aggregations.metrics.ParsedGeoBounds;
|
|
||||||
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
|
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
|
||||||
import org.elasticsearch.test.InternalAggregationTestCase;
|
import org.elasticsearch.test.InternalAggregationTestCase;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue