Search in sources :

Example 36 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.

the class GeoPolygonQueryBuilderTests method testIgnoreUnmapped.

public void testIgnoreUnmapped() throws IOException {
    List<GeoPoint> polygon = randomPolygon();
    final GeoPolygonQueryBuilder queryBuilder = new GeoPolygonQueryBuilder("unmapped", polygon);
    queryBuilder.ignoreUnmapped(true);
    Query query = queryBuilder.toQuery(createShardContext());
    assertThat(query, notNullValue());
    assertThat(query, instanceOf(MatchNoDocsQuery.class));
    final GeoPolygonQueryBuilder failingQueryBuilder = new GeoPolygonQueryBuilder("unmapped", polygon);
    failingQueryBuilder.ignoreUnmapped(false);
    QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(createShardContext()));
    assertThat(e.getMessage(), containsString("failed to find geo_point field [unmapped]"));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery)

Example 37 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.

the class FunctionScoreQueryBuilderTests method createRandomDecayFunction.

/**
     * Create a random decay function setting all of its constructor parameters randomly. The caller is responsible for randomizing other
     * fields.
     */
private static DecayFunctionBuilder<?> createRandomDecayFunction() {
    String field = randomFrom(INT_FIELD_NAME, DOUBLE_FIELD_NAME, DATE_FIELD_NAME, GEO_POINT_FIELD_NAME);
    Object origin;
    Object scale;
    Object offset;
    switch(field) {
        case GEO_POINT_FIELD_NAME:
            origin = new GeoPoint(randomDouble(), randomDouble()).geohash();
            scale = randomFrom(DistanceUnit.values()).toString(randomDouble());
            offset = randomFrom(DistanceUnit.values()).toString(randomDouble());
            break;
        case DATE_FIELD_NAME:
            origin = new DateTime(System.currentTimeMillis() - randomIntBetween(0, 1000000), DateTimeZone.UTC).toString();
            scale = randomPositiveTimeValue();
            offset = randomPositiveTimeValue();
            break;
        default:
            origin = randomBoolean() ? randomInt() : randomFloat();
            scale = randomBoolean() ? between(1, Integer.MAX_VALUE) : randomFloat() + Float.MIN_NORMAL;
            offset = randomBoolean() ? between(1, Integer.MAX_VALUE) : randomFloat() + Float.MIN_NORMAL;
            break;
    }
    offset = randomBoolean() ? null : offset;
    double decay = randomDouble();
    switch(randomIntBetween(0, 2)) {
        case 0:
            return new GaussDecayFunctionBuilder(field, origin, scale, offset, decay);
        case 1:
            return new ExponentialDecayFunctionBuilder(field, origin, scale, offset, decay);
        case 2:
            return new LinearDecayFunctionBuilder(field, origin, scale, offset, decay);
        default:
            throw new UnsupportedOperationException();
    }
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) Matchers.containsString(org.hamcrest.Matchers.containsString) DateTime(org.joda.time.DateTime)

Example 38 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.

the class GeoPointParsingTests method testGeoPointParsing.

public void testGeoPointParsing() throws IOException {
    GeoPoint randomPt = RandomGeoGenerator.randomPoint(random());
    GeoPoint point = GeoUtils.parseGeoPoint(objectLatLon(randomPt.lat(), randomPt.lon()));
    assertPointsEqual(point, randomPt);
    GeoUtils.parseGeoPoint(arrayLatLon(randomPt.lat(), randomPt.lon()), point);
    assertPointsEqual(point, randomPt);
    GeoUtils.parseGeoPoint(geohash(randomPt.lat(), randomPt.lon()), point);
    assertCloseTo(point, randomPt.lat(), randomPt.lon());
    GeoUtils.parseGeoPoint(stringLatLon(randomPt.lat(), randomPt.lon()), point);
    assertCloseTo(point, randomPt.lat(), randomPt.lon());
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Example 39 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.

the class GeoUtilsTests method testNormalizePointInNormalRange.

public void testNormalizePointInNormalRange() {
    for (int i = 0; i < 100; i++) {
        double testLat = (randomDouble() * 180.0) - 90.0;
        double testLon = (randomDouble() * 360.0) - 180.0;
        GeoPoint testPoint = new GeoPoint(testLat, testLon);
        assertNormalizedPoint(testPoint, testPoint);
    }
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Example 40 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.

the class GeoUtilsTests method testParseGeoPointGeohash.

public void testParseGeoPointGeohash() throws IOException {
    for (int i = 0; i < 100; i++) {
        int geoHashLength = randomIntBetween(1, GeoHashUtils.PRECISION);
        StringBuilder geohashBuilder = new StringBuilder(geoHashLength);
        for (int j = 0; j < geoHashLength; j++) {
            geohashBuilder.append(BASE_32[randomInt(BASE_32.length - 1)]);
        }
        XContentBuilder json = jsonBuilder().startObject().field("geohash", geohashBuilder.toString()).endObject();
        XContentParser parser = createParser(json);
        parser.nextToken();
        GeoPoint point = GeoUtils.parseGeoPoint(parser);
        assertThat(point.lat(), allOf(lessThanOrEqualTo(90.0), greaterThanOrEqualTo(-90.0)));
        assertThat(point.lon(), allOf(lessThanOrEqualTo(180.0), greaterThanOrEqualTo(-180.0)));
        json = jsonBuilder().startObject().field("geohash", geohashBuilder.toString()).endObject();
        parser = createParser(json);
        while (parser.currentToken() != Token.VALUE_STRING) {
            parser.nextToken();
        }
        point = GeoUtils.parseGeoPoint(parser);
        assertThat(point.lat(), allOf(lessThanOrEqualTo(90.0), greaterThanOrEqualTo(-90.0)));
        assertThat(point.lon(), allOf(lessThanOrEqualTo(180.0), greaterThanOrEqualTo(-180.0)));
    }
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoPoint(org.elasticsearch.common.geo.GeoPoint) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Aggregations

GeoPoint (org.elasticsearch.common.geo.GeoPoint)122 SearchResponse (org.elasticsearch.action.search.SearchResponse)40 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)27 ArrayList (java.util.ArrayList)20 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)15 XContentParser (org.elasticsearch.common.xcontent.XContentParser)9 GeoBounds (org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds)9 Range (org.elasticsearch.search.aggregations.bucket.range.Range)8 GeoCentroid (org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid)8 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)7 Version (org.elasticsearch.Version)7 Bucket (org.elasticsearch.search.aggregations.bucket.range.Range.Bucket)7 Settings (org.elasticsearch.common.settings.Settings)6 MultiGeoPointValues (org.elasticsearch.index.fielddata.MultiGeoPointValues)6 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)5 ParsingException (org.elasticsearch.common.ParsingException)5 SearchHit (org.elasticsearch.search.SearchHit)5 Test (org.testng.annotations.Test)5 HashSet (java.util.HashSet)4 DistanceUnit (org.elasticsearch.common.unit.DistanceUnit)4