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]"));
}
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();
}
}
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());
}
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);
}
}
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)));
}
}
Aggregations