use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
the class GeoCentroidIT method testPartiallyUnmapped.
public void testPartiallyUnmapped() throws Exception {
SearchResponse response = client().prepareSearch(IDX_NAME, UNMAPPED_IDX_NAME).addAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME)).get();
assertSearchResponse(response);
GeoCentroid geoCentroid = response.getAggregations().get(aggName);
assertThat(geoCentroid, notNullValue());
assertThat(geoCentroid.getName(), equalTo(aggName));
GeoPoint centroid = geoCentroid.centroid();
assertThat(centroid.lat(), closeTo(singleCentroid.lat(), GEOHASH_TOLERANCE));
assertThat(centroid.lon(), closeTo(singleCentroid.lon(), GEOHASH_TOLERANCE));
assertEquals(numDocs, geoCentroid.count());
}
use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
the class AbstractGeoFieldDataTestCase method assertValues.
private void assertValues(MultiGeoPointValues values, int docId, boolean missing) throws IOException {
assertEquals(missing == false, values.advanceExact(docId));
if (missing == false) {
final int docCount = values.docValueCount();
for (int i = 0; i < docCount; ++i) {
final GeoPoint point = values.nextValue();
assertThat(point.lat(), allOf(greaterThanOrEqualTo(GeoUtils.MIN_LAT), lessThanOrEqualTo(GeoUtils.MAX_LAT)));
assertThat(point.lon(), allOf(greaterThanOrEqualTo(GeoUtils.MIN_LON), lessThanOrEqualTo(GeoUtils.MAX_LON)));
}
}
}
use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
the class ScriptDocValuesGeoPointsTests method testGeoGetLatLon.
public void testGeoGetLatLon() throws IOException {
final double lat1 = randomLat();
final double lat2 = randomLat();
final double lon1 = randomLon();
final double lon2 = randomLon();
GeoPoint[][] points = { { new GeoPoint(lat1, lon1), new GeoPoint(lat2, lon2) } };
final MultiGeoPointValues values = wrap(points);
final ScriptDocValues.GeoPoints script = new ScriptDocValues.GeoPoints(values);
script.setNextDocId(1);
assertEquals(true, script.isEmpty());
script.setNextDocId(0);
assertEquals(false, script.isEmpty());
assertEquals(new GeoPoint(lat1, lon1), script.getValue());
assertEquals(lat1, script.getLat(), 0);
assertEquals(lon1, script.getLon(), 0);
assertTrue(Arrays.equals(new double[] { lat1, lat2 }, script.getLats()));
assertTrue(Arrays.equals(new double[] { lon1, lon2 }, script.getLons()));
}
use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
the class GeoPointFieldMapperTests method testNullValue.
public void testNullValue() throws Exception {
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "geo_point")));
Mapper fieldMapper = mapper.mappers().getMapper("field");
assertThat(fieldMapper, instanceOf(GeoPointFieldMapper.class));
ParsedDocument doc = mapper.parse(source(b -> b.nullField("field")));
assertThat(doc.rootDoc().getField("field"), nullValue());
assertThat(doc.rootDoc().getFields(FieldNamesFieldMapper.NAME).length, equalTo(0));
mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "geo_point").field("doc_values", false)));
fieldMapper = mapper.mappers().getMapper("field");
assertThat(fieldMapper, instanceOf(GeoPointFieldMapper.class));
doc = mapper.parse(source(b -> b.nullField("field")));
assertThat(doc.rootDoc().getField("field"), nullValue());
assertThat(doc.rootDoc().getFields(FieldNamesFieldMapper.NAME).length, equalTo(0));
mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "geo_point").field("null_value", "1,2")));
fieldMapper = mapper.mappers().getMapper("field");
assertThat(fieldMapper, instanceOf(GeoPointFieldMapper.class));
AbstractPointGeometryFieldMapper.ParsedPoint nullValue = ((GeoPointFieldMapper) fieldMapper).nullValue;
assertThat(nullValue, equalTo(new GeoPoint(1, 2)));
doc = mapper.parse(source(b -> b.nullField("field")));
assertThat(doc.rootDoc().getField("field"), notNullValue());
BytesRef defaultValue = doc.rootDoc().getBinaryValue("field");
// Shouldn't matter if we specify the value explicitly or use null value
doc = mapper.parse(source(b -> b.field("field", "1, 2")));
assertThat(defaultValue, equalTo(doc.rootDoc().getBinaryValue("field")));
doc = mapper.parse(source(b -> b.field("field", "3, 4")));
assertThat(defaultValue, not(equalTo(doc.rootDoc().getBinaryValue("field"))));
}
use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.
the class ExternalMapper method parse.
@Override
public void parse(ParseContext context) throws IOException {
byte[] bytes = "Hello world".getBytes(Charset.defaultCharset());
binMapper.parse(context.createExternalValueContext(bytes));
boolMapper.parse(context.createExternalValueContext(true));
// Let's add a Dummy Point
double lat = 42.0;
double lng = 51.0;
ArrayList<GeoPoint> points = new ArrayList<>();
points.add(new GeoPoint(lat, lng));
pointMapper.parse(context.createExternalValueContext(points));
// Let's add a Dummy Shape
if (shapeMapper instanceof GeoShapeFieldMapper) {
shapeMapper.parse(context.createExternalValueContext(new Point(-100, 45)));
} else {
PointBuilder pb = new PointBuilder(-100, 45);
shapeMapper.parse(context.createExternalValueContext(pb.buildS4J()));
}
context = context.createExternalValueContext(generatedValue);
// Let's add a Original String
stringMapper.parse(context);
multiFields.parse(this, context);
}
Aggregations