use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.
the class GeoQueryContextTests method testIllegalArguments.
public void testIllegalArguments() {
final GeoQueryContext.Builder builder = GeoQueryContext.builder();
try {
builder.setGeoPoint(null);
fail("geoPoint must not be null");
} catch (NullPointerException e) {
assertEquals(e.getMessage(), "geoPoint must not be null");
}
try {
builder.setBoost(-randomIntBetween(1, Integer.MAX_VALUE));
fail("boost must be positive");
} catch (IllegalArgumentException e) {
assertEquals(e.getMessage(), "boost must be greater than 0");
}
int precision = 0;
try {
do {
precision = randomInt();
} while (precision >= 1 && precision <= 12);
builder.setPrecision(precision);
} catch (IllegalArgumentException e) {
assertEquals(e.getMessage(), "precision must be between 1 and 12");
}
try {
List<Integer> neighbours = new ArrayList<>();
neighbours.add(precision);
for (int i = 1; i < randomIntBetween(1, 11); i++) {
neighbours.add(i);
}
Collections.shuffle(neighbours, random());
builder.setNeighbours(neighbours);
} catch (IllegalArgumentException e) {
assertEquals(e.getMessage(), "neighbour value must be between 1 and 12");
}
}
use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.
the class FieldStatsIntegrationIT method testRandom.
public void testRandom() throws Exception {
assertAcked(prepareCreate("test").addMapping("test", "string", "type=text", "date", "type=date", "double", "type=double", "half_float", "type=half_float", "float", "type=float", "long", "type=long", "integer", "type=integer", "short", "type=short", "byte", "type=byte", "location", "type=geo_point"));
ensureGreen("test");
// index=false
assertAcked(prepareCreate("test1").addMapping("test", "string", "type=text,index=false", "date", "type=date,index=false", "double", "type=double,index=false", "half_float", "type=half_float", "float", "type=float,index=false", "long", "type=long,index=false", "integer", "type=integer,index=false", "short", "type=short,index=false", "byte", "type=byte,index=false", "location", "type=geo_point,index=false"));
ensureGreen("test1");
// no value indexed
assertAcked(prepareCreate("test3").addMapping("test", "string", "type=text,index=false", "date", "type=date,index=false", "double", "type=double,index=false", "half_float", "type=half_float", "float", "type=float,index=false", "long", "type=long,index=false", "integer", "type=integer,index=false", "short", "type=short,index=false", "byte", "type=byte,index=false", "location", "type=geo_point,index=false"));
ensureGreen("test3");
long minByte = Byte.MAX_VALUE;
long maxByte = Byte.MIN_VALUE;
long minShort = Short.MAX_VALUE;
long maxShort = Short.MIN_VALUE;
long minInt = Integer.MAX_VALUE;
long maxInt = Integer.MIN_VALUE;
long minLong = Long.MAX_VALUE;
long maxLong = Long.MIN_VALUE;
double minHalfFloat = Double.POSITIVE_INFINITY;
double maxHalfFloat = Double.NEGATIVE_INFINITY;
double minFloat = Double.POSITIVE_INFINITY;
double maxFloat = Double.NEGATIVE_INFINITY;
double minDouble = Double.POSITIVE_INFINITY;
double maxDouble = Double.NEGATIVE_INFINITY;
GeoPoint minLoc = new GeoPoint(90, 180);
GeoPoint maxLoc = new GeoPoint(-90, -180);
String minString = new String(Character.toChars(1114111));
String maxString = "0";
int numDocs = scaledRandomIntBetween(128, 1024);
List<IndexRequestBuilder> request = new ArrayList<>(numDocs);
for (int doc = 0; doc < numDocs; doc++) {
byte b = randomByte();
minByte = Math.min(minByte, b);
maxByte = Math.max(maxByte, b);
short s = randomShort();
minShort = Math.min(minShort, s);
maxShort = Math.max(maxShort, s);
int i = randomInt();
minInt = Math.min(minInt, i);
maxInt = Math.max(maxInt, i);
long l = randomLong();
minLong = Math.min(minLong, l);
maxLong = Math.max(maxLong, l);
float hf = randomFloat();
hf = HalfFloatPoint.sortableShortToHalfFloat(HalfFloatPoint.halfFloatToSortableShort(hf));
minHalfFloat = Math.min(minHalfFloat, hf);
maxHalfFloat = Math.max(maxHalfFloat, hf);
float f = randomFloat();
minFloat = Math.min(minFloat, f);
maxFloat = Math.max(maxFloat, f);
double d = randomDouble();
minDouble = Math.min(minDouble, d);
maxDouble = Math.max(maxDouble, d);
GeoPoint loc = RandomGeoGenerator.randomPoint(random());
minLoc.reset(Math.min(loc.lat(), minLoc.lat()), Math.min(loc.lon(), minLoc.lon()));
maxLoc.reset(Math.max(loc.lat(), maxLoc.lat()), Math.max(loc.lon(), maxLoc.lon()));
String str = randomRealisticUnicodeOfLength(3);
if (str.compareTo(minString) < 0) {
minString = str;
}
if (str.compareTo(maxString) > 0) {
maxString = str;
}
request.add(client().prepareIndex("test", "test", Integer.toString(doc)).setSource("byte", b, "short", s, "integer", i, "long", l, "half_float", hf, "float", f, "double", d, "location", loc, "string", str));
}
indexRandom(true, false, request);
FieldStatsResponse response = client().prepareFieldStats().setFields("byte", "short", "integer", "long", "half_float", "float", "double", "location", "string").get();
assertAllSuccessful(response);
for (FieldStats<?> stats : response.getAllFieldStats().values()) {
assertThat(stats.getMaxDoc(), equalTo((long) numDocs));
assertThat(stats.getDocCount(), equalTo((long) numDocs));
assertThat(stats.getDensity(), equalTo(100));
}
assertThat(response.getAllFieldStats().get("byte").getMinValue(), equalTo(minByte));
assertThat(response.getAllFieldStats().get("byte").getMaxValue(), equalTo(maxByte));
assertThat(response.getAllFieldStats().get("byte").getDisplayType(), equalTo("integer"));
assertThat(response.getAllFieldStats().get("short").getMinValue(), equalTo(minShort));
assertThat(response.getAllFieldStats().get("short").getMaxValue(), equalTo(maxShort));
assertThat(response.getAllFieldStats().get("short").getDisplayType(), equalTo("integer"));
assertThat(response.getAllFieldStats().get("integer").getMinValue(), equalTo(minInt));
assertThat(response.getAllFieldStats().get("integer").getMaxValue(), equalTo(maxInt));
assertThat(response.getAllFieldStats().get("integer").getDisplayType(), equalTo("integer"));
assertThat(response.getAllFieldStats().get("long").getMinValue(), equalTo(minLong));
assertThat(response.getAllFieldStats().get("long").getMaxValue(), equalTo(maxLong));
assertThat(response.getAllFieldStats().get("long").getDisplayType(), equalTo("integer"));
assertThat(response.getAllFieldStats().get("half_float").getMinValue(), equalTo(minHalfFloat));
assertThat(response.getAllFieldStats().get("half_float").getMaxValue(), equalTo(maxHalfFloat));
assertThat(response.getAllFieldStats().get("half_float").getDisplayType(), equalTo("float"));
assertThat(response.getAllFieldStats().get("float").getMinValue(), equalTo(minFloat));
assertThat(response.getAllFieldStats().get("float").getMaxValue(), equalTo(maxFloat));
assertThat(response.getAllFieldStats().get("float").getDisplayType(), equalTo("float"));
assertThat(response.getAllFieldStats().get("double").getMinValue(), equalTo(minDouble));
assertThat(response.getAllFieldStats().get("double").getMaxValue(), equalTo(maxDouble));
assertThat(response.getAllFieldStats().get("double").getDisplayType(), equalTo("float"));
assertThat(((GeoPoint) response.getAllFieldStats().get("location").getMinValue()).lat(), closeTo(minLoc.lat(), 1E-5));
assertThat(((GeoPoint) response.getAllFieldStats().get("location").getMinValue()).lon(), closeTo(minLoc.lon(), 1E-5));
assertThat(((GeoPoint) response.getAllFieldStats().get("location").getMaxValue()).lat(), closeTo(maxLoc.lat(), 1E-5));
assertThat(((GeoPoint) response.getAllFieldStats().get("location").getMaxValue()).lon(), closeTo(maxLoc.lon(), 1E-5));
assertThat(response.getAllFieldStats().get("location").getDisplayType(), equalTo("geo_point"));
}
use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.
the class ScriptDocValuesGeoPointsTests method testGeoGetLatLon.
public void testGeoGetLatLon() {
final double lat1 = randomLat();
final double lat2 = randomLat();
final double lon1 = randomLon();
final double lon2 = randomLon();
final MultiGeoPointValues values = wrap(new GeoPoint(lat1, lon1), new GeoPoint(lat2, lon2));
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(Arrays.asList(new GeoPoint(lat1, lon1), new GeoPoint(lat2, lon2)), script.getValues());
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.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.
the class ScriptDocValuesGeoPointsTests method testGeoDistance.
public void testGeoDistance() {
final double lat = randomLat();
final double lon = randomLon();
final MultiGeoPointValues values = wrap(new GeoPoint(lat, lon));
final ScriptDocValues.GeoPoints script = new ScriptDocValues.GeoPoints(values);
script.setNextDocId(0);
final ScriptDocValues.GeoPoints emptyScript = new ScriptDocValues.GeoPoints(wrap());
emptyScript.setNextDocId(0);
final double otherLat = randomLat();
final double otherLon = randomLon();
assertEquals(GeoUtils.arcDistance(lat, lon, otherLat, otherLon) / 1000d, script.arcDistance(otherLat, otherLon) / 1000d, 0.01);
assertEquals(GeoUtils.arcDistance(lat, lon, otherLat, otherLon) / 1000d, script.arcDistanceWithDefault(otherLat, otherLon, 42) / 1000d, 0.01);
assertEquals(42, emptyScript.arcDistanceWithDefault(otherLat, otherLon, 42), 0);
assertEquals(GeoUtils.planeDistance(lat, lon, otherLat, otherLon) / 1000d, script.planeDistance(otherLat, otherLon) / 1000d, 0.01);
assertEquals(GeoUtils.planeDistance(lat, lon, otherLat, otherLon) / 1000d, script.planeDistanceWithDefault(otherLat, otherLon, 42) / 1000d, 0.01);
assertEquals(42, emptyScript.planeDistanceWithDefault(otherLat, otherLon, 42), 0);
}
use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.
the class ExternalMapper method parse.
@Override
public Mapper 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;
GeoPoint point = new GeoPoint(lat, lng);
pointMapper.parse(context.createExternalValueContext(point));
// Let's add a Dummy Shape
Point shape = ShapeBuilders.newPoint(-100, 45).build();
shapeMapper.parse(context.createExternalValueContext(shape));
context = context.createExternalValueContext(generatedValue);
// Let's add a Original String
stringMapper.parse(context);
multiFields.parse(this, context);
return null;
}
Aggregations