Search in sources :

Example 26 with GeoPoint

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());
}
Also used : GeoPoint(org.opensearch.common.geo.GeoPoint) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse)

Example 27 with GeoPoint

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)));
        }
    }
}
Also used : GeoPoint(org.opensearch.common.geo.GeoPoint) GeoPoint(org.opensearch.common.geo.GeoPoint) RandomShapeGenerator.randomPoint(org.opensearch.test.geo.RandomShapeGenerator.randomPoint)

Example 28 with GeoPoint

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()));
}
Also used : GeoPoint(org.opensearch.common.geo.GeoPoint) GeoPoints(org.opensearch.index.fielddata.ScriptDocValues.GeoPoints) GeoPoints(org.opensearch.index.fielddata.ScriptDocValues.GeoPoints)

Example 29 with GeoPoint

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"))));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) Matchers.arrayWithSize(org.hamcrest.Matchers.arrayWithSize) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) BytesRef(org.apache.lucene.util.BytesRef) Matchers.not(org.hamcrest.Matchers.not) Set(java.util.Set) IOException(java.io.IOException) Matchers.both(org.hamcrest.Matchers.both) GeoUtils(org.opensearch.common.geo.GeoUtils) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.nullValue(org.hamcrest.Matchers.nullValue) GeoPoint(org.opensearch.common.geo.GeoPoint) XContentFactory(org.opensearch.common.xcontent.XContentFactory) Matchers.containsString(org.hamcrest.Matchers.containsString) Geohash.stringEncode(org.opensearch.geometry.utils.Geohash.stringEncode) GeoPoint(org.opensearch.common.geo.GeoPoint) BytesRef(org.apache.lucene.util.BytesRef)

Example 30 with GeoPoint

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);
}
Also used : GeoPoint(org.opensearch.common.geo.GeoPoint) PointBuilder(org.opensearch.common.geo.builders.PointBuilder) ArrayList(java.util.ArrayList) Point(org.opensearch.geometry.Point) GeoPoint(org.opensearch.common.geo.GeoPoint)

Aggregations

GeoPoint (org.opensearch.common.geo.GeoPoint)150 SearchResponse (org.opensearch.action.search.SearchResponse)41 OpenSearchAssertions.assertSearchResponse (org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse)27 ArrayList (java.util.ArrayList)23 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)19 Matchers.containsString (org.hamcrest.Matchers.containsString)11 XContentParser (org.opensearch.common.xcontent.XContentParser)10 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)10 LatLonPoint (org.apache.lucene.document.LatLonPoint)8 Version (org.opensearch.Version)8 IOException (java.io.IOException)7 LatLonDocValuesField (org.apache.lucene.document.LatLonDocValuesField)7 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)7 OpenSearchParseException (org.opensearch.OpenSearchParseException)7 Range (org.opensearch.search.aggregations.bucket.range.Range)6 Bucket (org.opensearch.search.aggregations.bucket.range.Range.Bucket)6 Map (java.util.Map)5 Document (org.apache.lucene.document.Document)5 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)5 Query (org.apache.lucene.search.Query)5