diff --git a/core/src/main/java/org/elasticsearch/common/geo/GeoUtils.java b/core/src/main/java/org/elasticsearch/common/geo/GeoUtils.java index a6de679991f..0d8fdfa2be7 100644 --- a/core/src/main/java/org/elasticsearch/common/geo/GeoUtils.java +++ b/core/src/main/java/org/elasticsearch/common/geo/GeoUtils.java @@ -310,8 +310,8 @@ public class GeoUtils { public static void normalizePoint(double[] lonLat, boolean normLon, boolean normLat) { assert lonLat != null && lonLat.length == 2; - normLat = normLat && (lonLat[1] > 90 || lonLat[1] <= -90); - normLon = normLon && (lonLat[0] > 180 || lonLat[0] <= -180); + normLat = normLat && (lonLat[1] > 90 || lonLat[1] < -90); + normLon = normLon && (lonLat[0] > 180 || lonLat[0] < -180); if (normLat) { lonLat[1] = centeredModulus(lonLat[1], 360); diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/SingletonMultiGeoPointValues.java b/core/src/main/java/org/elasticsearch/index/fielddata/SingletonMultiGeoPointValues.java index ff87cc00022..883444fabc7 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/SingletonMultiGeoPointValues.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/SingletonMultiGeoPointValues.java @@ -37,7 +37,7 @@ final class SingletonMultiGeoPointValues extends MultiGeoPointValues { @Override public void setDocument(int docID) { value = in.get(docID); - if (value.lat() == 0 && value.lon() == 0 && docsWithField != null && !docsWithField.get(docID)) { + if (value.lat() == Double.NaN && value.lon() == Double.NaN || (docsWithField != null && !docsWithField.get(docID))) { count = 0; } else { count = 1; diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractGeoPointDVIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractGeoPointDVIndexFieldData.java index 3939cd1b0e7..0b86b17f211 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractGeoPointDVIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractGeoPointDVIndexFieldData.java @@ -85,8 +85,7 @@ public abstract class AbstractGeoPointDVIndexFieldData extends DocValuesIndexFie CircuitBreakerService breakerService, MapperService mapperService) { // Ignore breaker return new GeoPointDVIndexFieldData(indexSettings.getIndex(), fieldType.names(), fieldType.fieldDataType(), - // norelease cut over to .before(Version.V_2_2_0) once GeoPointFieldV2 is completely merged - indexSettings.getIndexVersionCreated().onOrBefore(Version.CURRENT)); + indexSettings.getIndexVersionCreated().before(Version.V_2_2_0)); } } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointArrayAtomicFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointArrayAtomicFieldData.java index adf25487b66..ce4dc2559e4 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointArrayAtomicFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointArrayAtomicFieldData.java @@ -74,7 +74,7 @@ public abstract class GeoPointArrayAtomicFieldData extends AbstractAtomicGeoPoin public MultiGeoPointValues getGeoPointValues() { final RandomAccessOrds ords = ordinals.ordinals(); final SortedDocValues singleOrds = DocValues.unwrapSingleton(ords); - final GeoPoint point = new GeoPoint(); + final GeoPoint point = new GeoPoint(Double.NaN, Double.NaN); if (singleOrds != null) { final GeoPointValues values = new GeoPointValues() { @Override @@ -83,8 +83,7 @@ public abstract class GeoPointArrayAtomicFieldData extends AbstractAtomicGeoPoin if (ord >= 0) { return point.resetFromIndexHash(indexedPoints.get(ord)); } - // todo: same issue as in ParentChildIndexFieldData, handle issue upstream? - return null; + return point.reset(Double.NaN, Double.NaN); } }; return FieldData.singleton(values, DocValues.docsWithValue(singleOrds, maxDoc)); @@ -139,7 +138,10 @@ public abstract class GeoPointArrayAtomicFieldData extends AbstractAtomicGeoPoin final GeoPointValues values = new GeoPointValues() { @Override public GeoPoint get(int docID) { - return point.resetFromIndexHash(indexedPoint.get(docID)); + if (set == null || set.get(docID)) { + return point.resetFromIndexHash(indexedPoint.get(docID)); + } + return point.reset(Double.NaN, Double.NaN); } }; return FieldData.singleton(values, set); diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointArrayIndexFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointArrayIndexFieldData.java index 6af339df085..a0c0a55be71 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointArrayIndexFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointArrayIndexFieldData.java @@ -25,6 +25,7 @@ import org.apache.lucene.index.RandomAccessOrds; import org.apache.lucene.index.Terms; import org.apache.lucene.util.BitSet; import org.elasticsearch.Version; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.util.BigArrays; @@ -54,8 +55,9 @@ public class GeoPointArrayIndexFieldData extends AbstractIndexGeoPointFieldData public IndexFieldData build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache, CircuitBreakerService breakerService, MapperService mapperService) { return new GeoPointArrayIndexFieldData(indexSettings, fieldType.names(), fieldType.fieldDataType(), cache, - // norelease change to .before(Version.V_2_2_0) once GeoPointFieldV2 is completely merged - breakerService, indexSettings.getIndexVersionCreated().onOrBefore(Version.CURRENT)); + breakerService, fieldType.fieldDataType().getSettings() + .getAsVersion(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).before(Version.V_2_2_0) || + indexSettings.getIndexVersionCreated().before(Version.V_2_2_0)); } } diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointArrayLegacyAtomicFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointArrayLegacyAtomicFieldData.java index 54102ad094b..ca1926ce354 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointArrayLegacyAtomicFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointArrayLegacyAtomicFieldData.java @@ -83,9 +83,9 @@ public abstract class GeoPointArrayLegacyAtomicFieldData extends AbstractAtomicG public GeoPoint get(int docID) { final int ord = singleOrds.getOrd(docID); if (ord >= 0) { - point.reset(lat.get(ord), lon.get(ord)); + return point.reset(lat.get(ord), lon.get(ord)); } - return point; + return point.reset(Double.NaN, Double.NaN); } }; return FieldData.singleton(values, DocValues.docsWithValue(singleOrds, maxDoc)); @@ -96,8 +96,10 @@ public abstract class GeoPointArrayLegacyAtomicFieldData extends AbstractAtomicG @Override public GeoPoint valueAt(int index) { final long ord = ords.ordAt(index); - point.reset(lat.get(ord), lon.get(ord)); - return point; + if (ord >= 0) { + return point.reset(lat.get(ord), lon.get(ord)); + } + return point.reset(Double.NaN, Double.NaN); } @Override @@ -150,8 +152,10 @@ public abstract class GeoPointArrayLegacyAtomicFieldData extends AbstractAtomicG final GeoPointValues values = new GeoPointValues() { @Override public GeoPoint get(int docID) { - point.reset(lat.get(docID), lon.get(docID)); - return point; + if (set == null || set.get(docID)) { + return point.reset(lat.get(docID), lon.get(docID)); + } + return point.reset(Double.NaN, Double.NaN); } }; return FieldData.singleton(values, set); diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointDVAtomicFieldData.java b/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointDVAtomicFieldData.java index de66ab09d62..a71ea3a552e 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointDVAtomicFieldData.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/plain/GeoPointDVAtomicFieldData.java @@ -68,7 +68,7 @@ final class GeoPointDVAtomicFieldData extends AbstractAtomicGeoPointFieldData { final int previousLength = points.length; points = Arrays.copyOf(points, ArrayUtil.oversize(count, RamUsageEstimator.NUM_BYTES_OBJECT_REF)); for (int i = previousLength; i < points.length; ++i) { - points[i] = new GeoPoint(); + points[i] = new GeoPoint(Double.NaN, Double.NaN); } } for (int i=0; i parse(String name, Map node, ParserContext parserContext) throws MapperParsingException { Builder builder; - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (parserContext.indexVersionCreated().onOrBefore(Version.CURRENT)) { + if (parserContext.indexVersionCreated().before(Version.V_2_2_0)) { builder = new GeoPointFieldMapperLegacy.Builder(name); } else { builder = new GeoPointFieldMapper.Builder(name); diff --git a/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java index e3b31af03c1..13ce524a2dd 100644 --- a/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java @@ -264,9 +264,9 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder leftPoints = new ArrayList<>(); List rightPoints = new ArrayList<>(); @@ -580,11 +580,14 @@ public class DuelFieldDataTests extends AbstractFieldDataTestCase { GeoPoint r = rightValues.valueAt(j); rightPoints.add(new GeoPoint(r.getLat(), r.getLon())); } - for (GeoPoint l : leftPoints) { - assertTrue("Couldn't find " + l + " among " + rightPoints, contains(l, rightPoints, precision)); - } - for (GeoPoint r : rightPoints) { - assertTrue("Couldn't find " + r + " among " + leftPoints, contains(r, leftPoints, precision)); + // missing values were treated as 0,0 which are valid geopoints, this now correctly tests for missing values + if (leftPoints.isEmpty() == false) { + for (GeoPoint l : leftPoints) { + assertTrue("Couldn't find " + l + " among " + rightPoints, contains(l, rightPoints, precision)); + } + for (GeoPoint r : rightPoints) { + assertTrue("Couldn't find " + r + " among " + leftPoints, contains(r, leftPoints, precision)); + } } } } diff --git a/core/src/test/java/org/elasticsearch/index/fielddata/GeoFieldDataTests.java b/core/src/test/java/org/elasticsearch/index/fielddata/GeoFieldDataTests.java index cad968b837c..21780fdf1fa 100644 --- a/core/src/test/java/org/elasticsearch/index/fielddata/GeoFieldDataTests.java +++ b/core/src/test/java/org/elasticsearch/index/fielddata/GeoFieldDataTests.java @@ -34,7 +34,7 @@ public class GeoFieldDataTests extends AbstractGeoFieldDataTestCase { @Override protected FieldDataType getFieldDataType() { - return new FieldDataType("geo_point", getFieldDataSettings()); + return new FieldDataType("geo_point"); } @Override diff --git a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java index 7ce6fc7f2da..5b998e0a7f4 100755 --- a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalMapper.java @@ -102,8 +102,7 @@ public class ExternalMapper extends FieldMapper { context.path().add(name); BinaryFieldMapper binMapper = binBuilder.build(context); BooleanFieldMapper boolMapper = boolBuilder.build(context); - // norelease cut over to .before(Version.2_2_0) once GeoPointFieldV2 is fully merged - BaseGeoPointFieldMapper pointMapper = (context.indexCreatedVersion().onOrBefore(Version.CURRENT)) ? + BaseGeoPointFieldMapper pointMapper = (context.indexCreatedVersion().before(Version.V_2_2_0)) ? legacyPointBuilder.build(context) : pointBuilder.build(context); GeoShapeFieldMapper shapeMapper = shapeBuilder.build(context); FieldMapper stringMapper = (FieldMapper)stringBuilder.build(context); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/SimpleExternalMappingTests.java b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/SimpleExternalMappingTests.java index 7826f5c9dd4..b0535d71a5d 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/SimpleExternalMappingTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/SimpleExternalMappingTests.java @@ -65,8 +65,7 @@ public class SimpleExternalMappingTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getField("field.bool").stringValue(), is("T")); assertThat(doc.rootDoc().getField("field.point"), notNullValue()); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().getField("field.point").stringValue(), is("42.0,51.0")); } else { assertThat(Long.parseLong(doc.rootDoc().getField("field.point").stringValue()), is(GeoUtils.mortonHash(51.0, 42.0))); @@ -119,8 +118,7 @@ public class SimpleExternalMappingTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getField("field.bool").stringValue(), is("T")); assertThat(doc.rootDoc().getField("field.point"), notNullValue()); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().getField("field.point").stringValue(), is("42.0,51.0")); } else { assertThat(Long.parseLong(doc.rootDoc().getField("field.point").stringValue()), is(GeoUtils.mortonHash(51.0, 42.0))); @@ -179,8 +177,7 @@ public class SimpleExternalMappingTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getField("field.bool").stringValue(), is("T")); assertThat(doc.rootDoc().getField("field.point"), notNullValue()); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().getField("field.point").stringValue(), is("42.0,51.0")); } else { assertThat(Long.parseLong(doc.rootDoc().getField("field.point").stringValue()), is(GeoUtils.mortonHash(51.0, 42.0))); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapperTests.java index 15e0ef00f62..9741b82aad6 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapperTests.java @@ -67,8 +67,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { .endObject() .bytes()); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - boolean indexCreatedBefore22 = version.onOrBefore(Version.CURRENT); + boolean indexCreatedBefore22 = version.before(Version.V_2_2_0); assertThat(doc.rootDoc().getField("point.lat"), notNullValue()); final boolean stored = indexCreatedBefore22 == false; assertThat(doc.rootDoc().getField("point.lat").fieldType().stored(), is(stored)); @@ -168,8 +167,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { // default to normalize XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("point").field("type", "geo_point"); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { mapping.field("coerce", true); } mapping.field("ignore_malformed", true).endObject().endObject().endObject().endObject(); @@ -183,8 +181,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { .endObject() .bytes()); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().get("point"), equalTo("89.0,1.0")); } else { assertThat(Long.parseLong(doc.rootDoc().get("point")), equalTo(GeoUtils.mortonHash(1.0, 89.0))); @@ -196,8 +193,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { .endObject() .bytes()); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().get("point"), equalTo("-89.0,-1.0")); } else { assertThat(Long.parseLong(doc.rootDoc().get("point")), equalTo(GeoUtils.mortonHash(-1.0, -89.0))); @@ -209,8 +205,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { .endObject() .bytes()); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().get("point"), equalTo("-1.0,-179.0")); } else { assertThat(Long.parseLong(doc.rootDoc().get("point")), equalTo(GeoUtils.mortonHash(-179.0, -1.0))); @@ -221,8 +216,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { Version version = VersionUtils.randomVersionBetween(random(), Version.V_1_0_0, Version.CURRENT); XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { mapping.field("coerce", false); } mapping.field("ignore_malformed", false).endObject().endObject().endObject().endObject().string(); @@ -285,8 +279,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { Version version = VersionUtils.randomVersionBetween(random(), Version.V_1_0_0, Version.CURRENT); XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { mapping.field("coerce", false); } mapping.field("ignore_malformed", true).endObject().endObject().endObject().endObject().string(); @@ -345,8 +338,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getField("point.lon"), notNullValue()); assertThat(doc.rootDoc().getField("point.lon").numericValue().doubleValue(), equalTo(1.3)); assertThat(doc.rootDoc().getField("point.geohash"), nullValue()); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().get("point"), equalTo("1.2,1.3")); } else { assertThat(Long.parseLong(doc.rootDoc().get("point")), equalTo(GeoUtils.mortonHash(1.3, 1.2))); @@ -375,16 +367,14 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getFields("point.lon").length, equalTo(2)); assertThat(doc.rootDoc().getFields("point.lat")[0].numericValue().doubleValue(), equalTo(1.2)); assertThat(doc.rootDoc().getFields("point.lon")[0].numericValue().doubleValue(), equalTo(1.3)); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().getFields("point")[0].stringValue(), equalTo("1.2,1.3")); } else { assertThat(Long.parseLong(doc.rootDoc().getFields("point")[0].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); } assertThat(doc.rootDoc().getFields("point.lat")[1].numericValue().doubleValue(), equalTo(1.4)); assertThat(doc.rootDoc().getFields("point.lon")[1].numericValue().doubleValue(), equalTo(1.5)); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().getFields("point")[1].stringValue(), equalTo("1.4,1.5")); } else { assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoUtils.mortonHash(1.5, 1.4))); @@ -408,11 +398,10 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getField("point.lat"), notNullValue()); assertThat(doc.rootDoc().getField("point.lon"), notNullValue()); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().get("point"), equalTo("1.2,1.3")); } else { - assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); + assertThat(Long.parseLong(doc.rootDoc().getFields("point")[0].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); } } @@ -435,11 +424,10 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getField("point.lat").numericValue().doubleValue(), equalTo(1.2)); assertThat(doc.rootDoc().getField("point.lon"), notNullValue()); assertThat(doc.rootDoc().getField("point.lon").numericValue().doubleValue(), equalTo(1.3)); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().get("point"), equalTo("1.2,1.3")); } else { - assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); + assertThat(Long.parseLong(doc.rootDoc().getFields("point")[0].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); } } @@ -465,16 +453,14 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getFields("point.lon").length, equalTo(2)); assertThat(doc.rootDoc().getFields("point.lat")[0].numericValue().doubleValue(), equalTo(1.2)); assertThat(doc.rootDoc().getFields("point.lon")[0].numericValue().doubleValue(), equalTo(1.3)); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().getFields("point")[0].stringValue(), equalTo("1.2,1.3")); } else { - assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); + assertThat(Long.parseLong(doc.rootDoc().getFields("point")[0].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); } assertThat(doc.rootDoc().getFields("point.lat")[1].numericValue().doubleValue(), equalTo(1.4)); assertThat(doc.rootDoc().getFields("point.lon")[1].numericValue().doubleValue(), equalTo(1.5)); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().getFields("point")[1].stringValue(), equalTo("1.4,1.5")); } else { assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoUtils.mortonHash(1.5, 1.4))); @@ -498,11 +484,10 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getField("point.lat"), notNullValue()); assertThat(doc.rootDoc().getField("point.lon"), notNullValue()); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().get("point"), equalTo("1.2,1.3")); } else { - assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); + assertThat(Long.parseLong(doc.rootDoc().getFields("point")[0].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); } } @@ -524,11 +509,10 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getField("point.lat"), notNullValue()); assertThat(doc.rootDoc().getField("point.lon"), notNullValue()); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().get("point"), equalTo("1.2,1.3")); } else { - assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); + assertThat(Long.parseLong(doc.rootDoc().getFields("point")[0].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); } } @@ -551,11 +535,10 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getField("point.lat").numericValue().doubleValue(), equalTo(1.2)); assertThat(doc.rootDoc().getField("point.lon"), notNullValue()); assertThat(doc.rootDoc().getField("point.lon").numericValue().doubleValue(), equalTo(1.3)); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().get("point"), equalTo("1.2,1.3")); } else { - assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); + assertThat(Long.parseLong(doc.rootDoc().getFields("point")[0].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); } } @@ -581,16 +564,14 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getFields("point.lon").length, equalTo(2)); assertThat(doc.rootDoc().getFields("point.lat")[0].numericValue().doubleValue(), equalTo(1.2)); assertThat(doc.rootDoc().getFields("point.lon")[0].numericValue().doubleValue(), equalTo(1.3)); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().get("point"), equalTo("1.2,1.3")); } else { - assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); + assertThat(Long.parseLong(doc.rootDoc().getFields("point")[0].stringValue()), equalTo(GeoUtils.mortonHash(1.3, 1.2))); } assertThat(doc.rootDoc().getFields("point.lat")[1].numericValue().doubleValue(), equalTo(1.4)); assertThat(doc.rootDoc().getFields("point.lon")[1].numericValue().doubleValue(), equalTo(1.5)); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().get("point"), equalTo("1.2,1.3")); } else { assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoUtils.mortonHash(1.5, 1.4))); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/geo/GeohashMappingGeoPointTests.java b/core/src/test/java/org/elasticsearch/index/mapper/geo/GeohashMappingGeoPointTests.java index 3c8fa1a6a1a..c3a92e8846d 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/geo/GeohashMappingGeoPointTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/geo/GeohashMappingGeoPointTests.java @@ -59,8 +59,7 @@ public class GeohashMappingGeoPointTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getField("point.lat"), nullValue()); assertThat(doc.rootDoc().getField("point.lon"), nullValue()); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().get("point"), equalTo("1.2,1.3")); } else { assertThat(Long.parseLong(doc.rootDoc().get("point")), equalTo(GeoUtils.mortonHash(1.3, 1.2))); @@ -84,8 +83,7 @@ public class GeohashMappingGeoPointTests extends ESSingleNodeTestCase { assertThat(doc.rootDoc().getField("point.lat"), nullValue()); assertThat(doc.rootDoc().getField("point.lon"), nullValue()); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { assertThat(doc.rootDoc().get("point"), equalTo("1.2,1.3")); } else { assertThat(Long.parseLong(doc.rootDoc().get("point")), equalTo(GeoUtils.mortonHash(1.3, 1.2))); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/multifield/MultiFieldTests.java b/core/src/test/java/org/elasticsearch/index/mapper/multifield/MultiFieldTests.java index 04bebf333ee..8a6b183b11c 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/multifield/MultiFieldTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/multifield/MultiFieldTests.java @@ -257,8 +257,7 @@ public class MultiFieldTests extends ESSingleNodeTestCase { public void testConvertMultiFieldGeoPoint() throws Exception { Version version = VersionUtils.randomVersionBetween(random(), Version.V_1_0_0, Version.CURRENT); Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - boolean indexCreatedBefore22 = version.onOrBefore(Version.CURRENT); + boolean indexCreatedBefore22 = version.before(Version.V_2_2_0); String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/test-multi-field-type-geo_point.json"); DocumentMapper docMapper = createIndex("test", settings).mapperService().documentMapperParser().parse(mapping); diff --git a/core/src/test/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilderTests.java index 9588eda7dec..f2e1fea8c57 100644 --- a/core/src/test/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilderTests.java @@ -267,10 +267,14 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase 0); Query parsedQuery = parseQuery(query).toQuery(createShardContext()); Version version = queryShardContext().indexVersionCreated(); - // norelease update to .before(Version.V_2_2_0 once GeoPointFieldV2 is fully merged - if (version.onOrBefore(Version.CURRENT)) { + if (version.before(Version.V_2_2_0)) { GeoDistanceRangeQuery q = (GeoDistanceRangeQuery) parsedQuery; assertThat(q.fieldName(), equalTo(GEO_POINT_FIELD_NAME)); assertThat(q.lat(), closeTo(lat, 1E-5D)); diff --git a/core/src/test/java/org/elasticsearch/index/query/GeoDistanceRangeQueryTests.java b/core/src/test/java/org/elasticsearch/index/query/GeoDistanceRangeQueryTests.java index bfdc187d67d..fb84bb669a0 100644 --- a/core/src/test/java/org/elasticsearch/index/query/GeoDistanceRangeQueryTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/GeoDistanceRangeQueryTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoUtils; import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.index.search.geo.GeoDistanceRangeQuery; +import org.elasticsearch.test.geo.RandomGeoGenerator; import java.io.IOException; @@ -44,14 +45,13 @@ public class GeoDistanceRangeQueryTests extends AbstractQueryTestCase indexBuilders = new ArrayList<>(); diff --git a/core/src/test/java/org/elasticsearch/search/geo/GeoBoundingBoxIT.java b/core/src/test/java/org/elasticsearch/search/geo/GeoBoundingBoxIT.java index 518e4fc8373..b354edfc60e 100644 --- a/core/src/test/java/org/elasticsearch/search/geo/GeoBoundingBoxIT.java +++ b/core/src/test/java/org/elasticsearch/search/geo/GeoBoundingBoxIT.java @@ -19,12 +19,16 @@ package org.elasticsearch.search.geo; +import org.elasticsearch.Version; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.query.GeoValidationMethod; import org.elasticsearch.search.SearchHit; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.VersionUtils; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.boolQuery; @@ -39,10 +43,15 @@ import static org.hamcrest.Matchers.equalTo; */ public class GeoBoundingBoxIT extends ESIntegTestCase { public void testSimpleBoundingBoxTest() throws Exception { + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type1") - .startObject("properties").startObject("location").field("type", "geo_point").field("lat_lon", true).endObject().endObject() - .endObject().endObject(); - assertAcked(prepareCreate("test").addMapping("type1", xContentBuilder)); + .startObject("properties").startObject("location").field("type", "geo_point"); + if (version.before(Version.V_2_2_0)) { + xContentBuilder.field("lat_lon", true); + } + xContentBuilder.endObject().endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); ensureGreen(); client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() @@ -108,10 +117,15 @@ public class GeoBoundingBoxIT extends ESIntegTestCase { } public void testLimitsBoundingBox() throws Exception { + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type1") - .startObject("properties").startObject("location").field("type", "geo_point").field("lat_lon", true).endObject().endObject() - .endObject().endObject(); - assertAcked(prepareCreate("test").addMapping("type1", xContentBuilder)); + .startObject("properties").startObject("location").field("type", "geo_point"); + if (version.before(Version.V_2_2_0)) { + xContentBuilder.field("lat_lon", true); + } + xContentBuilder.endObject().endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); ensureGreen(); client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() @@ -210,10 +224,15 @@ public class GeoBoundingBoxIT extends ESIntegTestCase { } public void testLimit2BoundingBox() throws Exception { + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type1") - .startObject("properties").startObject("location").field("type", "geo_point").field("lat_lon", true).endObject().endObject() - .endObject().endObject(); - assertAcked(prepareCreate("test").addMapping("type1", xContentBuilder)); + .startObject("properties").startObject("location").field("type", "geo_point"); + if (version.before(Version.V_2_2_0)) { + xContentBuilder.field("lat_lon", true); + } + xContentBuilder.endObject().endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); ensureGreen(); client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() @@ -260,10 +279,15 @@ public class GeoBoundingBoxIT extends ESIntegTestCase { } public void testCompleteLonRange() throws Exception { + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type1") - .startObject("properties").startObject("location").field("type", "geo_point").field("lat_lon", true).endObject().endObject() - .endObject().endObject(); - assertAcked(prepareCreate("test").addMapping("type1", xContentBuilder)); + .startObject("properties").startObject("location").field("type", "geo_point"); + if (version.before(Version.V_2_2_0)) { + xContentBuilder.field("lat_lon", true); + } + xContentBuilder.endObject().endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); ensureGreen(); client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() diff --git a/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java b/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java index ee2fb575ed8..938739236a7 100644 --- a/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java +++ b/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java @@ -30,10 +30,13 @@ import org.apache.lucene.spatial.query.SpatialArgs; import org.apache.lucene.spatial.query.SpatialOperation; import org.apache.lucene.spatial.query.UnsupportedSpatialOperation; import org.apache.lucene.util.GeoHashUtils; +import org.apache.lucene.util.GeoProjectionUtils; +import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.action.bulk.BulkItemResponse; import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Priority; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; @@ -43,11 +46,14 @@ import org.elasticsearch.common.geo.builders.MultiPolygonBuilder; import org.elasticsearch.common.geo.builders.PolygonBuilder; import org.elasticsearch.common.geo.builders.ShapeBuilder; import org.elasticsearch.common.io.Streams; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.query.GeohashCellQuery; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.VersionUtils; import org.junit.BeforeClass; import java.io.ByteArrayOutputStream; @@ -73,10 +79,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFirs import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId; -import static org.hamcrest.Matchers.anyOf; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.*; /** * @@ -398,25 +401,28 @@ public class GeoFilterIT extends ESIntegTestCase { public void testBulk() throws Exception { byte[] bulkAction = unZipData("/org/elasticsearch/search/geo/gzippedmap.gz"); - - String mapping = XContentFactory.jsonBuilder() + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() .startObject() .startObject("country") .startObject("properties") .startObject("pin") - .field("type", "geo_point") - .field("lat_lon", true) - .field("store", true) + .field("type", "geo_point"); + if (version.before(Version.V_2_2_0)) { + xContentBuilder.field("lat_lon", true); + } + xContentBuilder.field("store", true) .endObject() .startObject("location") .field("type", "geo_shape") .endObject() .endObject() .endObject() - .endObject() - .string(); + .endObject(); - client().admin().indices().prepareCreate("countries").addMapping("country", mapping).execute().actionGet(); + client().admin().indices().prepareCreate("countries").setSettings(settings) + .addMapping("country", xContentBuilder.string()).execute().actionGet(); BulkResponse bulk = client().prepareBulk().add(bulkAction, 0, bulkAction.length, null, null).execute().actionGet(); for (BulkItemResponse item : bulk.getItems()) { @@ -450,13 +456,17 @@ public class GeoFilterIT extends ESIntegTestCase { GeoPoint point = new GeoPoint(); for (SearchHit hit : distance.getHits()) { String name = hit.getId(); - point.resetFromString(hit.fields().get("pin").getValue().toString()); + if (version.before(Version.V_2_2_0)) { + point.resetFromString(hit.fields().get("pin").getValue().toString()); + } else { + point.resetFromIndexHash(hit.fields().get("pin").getValue()); + } double dist = distance(point.getLat(), point.getLon(), 51.11, 9.851); assertThat("distance to '" + name + "'", dist, lessThanOrEqualTo(425000d)); assertThat(name, anyOf(equalTo("CZ"), equalTo("DE"), equalTo("BE"), equalTo("NL"), equalTo("LU"))); if (key.equals(name)) { - assertThat(dist, equalTo(0d)); + assertThat(dist, closeTo(0d, 0.1d)); } } } @@ -557,7 +567,7 @@ public class GeoFilterIT extends ESIntegTestCase { } public static double distance(double lat1, double lon1, double lat2, double lon2) { - return GeoUtils.EARTH_SEMI_MAJOR_AXIS * DistanceUtils.distHaversineRAD( + return GeoProjectionUtils.SEMIMAJOR_AXIS * DistanceUtils.distHaversineRAD( DistanceUtils.toRadians(lat1), DistanceUtils.toRadians(lon1), DistanceUtils.toRadians(lat2), diff --git a/core/src/test/java/org/elasticsearch/search/geo/GeoPolygonIT.java b/core/src/test/java/org/elasticsearch/search/geo/GeoPolygonIT.java index 7619962c440..69b93018d8d 100644 --- a/core/src/test/java/org/elasticsearch/search/geo/GeoPolygonIT.java +++ b/core/src/test/java/org/elasticsearch/search/geo/GeoPolygonIT.java @@ -19,12 +19,16 @@ package org.elasticsearch.search.geo; +import org.elasticsearch.Version; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.geo.GeoPoint; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.search.SearchHit; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.VersionUtils; import java.util.ArrayList; import java.util.List; @@ -42,10 +46,15 @@ public class GeoPolygonIT extends ESIntegTestCase { @Override protected void setupSuiteScopeCluster() throws Exception { + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type1") - .startObject("properties").startObject("location").field("type", "geo_point").field("lat_lon", true) - .endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test").addMapping("type1", xContentBuilder)); + .startObject("properties").startObject("location").field("type", "geo_point"); + if (version.before(Version.V_2_2_0)) { + xContentBuilder.field("lat_lon", true); + } + xContentBuilder.endObject().endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); ensureGreen(); indexRandom(true, client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() diff --git a/plugins/lang-groovy/src/test/java/org/elasticsearch/messy/tests/GeoDistanceTests.java b/plugins/lang-groovy/src/test/java/org/elasticsearch/messy/tests/GeoDistanceTests.java index 33a0df09bd2..f71a1f0014d 100644 --- a/plugins/lang-groovy/src/test/java/org/elasticsearch/messy/tests/GeoDistanceTests.java +++ b/plugins/lang-groovy/src/test/java/org/elasticsearch/messy/tests/GeoDistanceTests.java @@ -20,13 +20,17 @@ package org.elasticsearch.messy.tests; import org.apache.lucene.util.GeoHashUtils; +import org.elasticsearch.Version; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.geo.GeoDistance; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.json.JsonXContent; +import org.elasticsearch.index.query.GeoDistanceQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestStatus; @@ -36,6 +40,7 @@ import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.VersionUtils; import java.io.IOException; import java.util.ArrayList; @@ -71,10 +76,15 @@ public class GeoDistanceTests extends ESIntegTestCase { } public void testSimpleDistance() throws Exception { + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type1") - .startObject("properties").startObject("location").field("type", "geo_point").field("lat_lon", true) - .endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test").addMapping("type1", xContentBuilder)); + .startObject("properties").startObject("location").field("type", "geo_point"); + if (version.before(Version.V_2_2_0)) { + xContentBuilder.field("lat_lon", true); + } + xContentBuilder.endObject().endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); ensureGreen(); indexRandom(true, client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() @@ -222,12 +232,15 @@ public class GeoDistanceTests extends ESIntegTestCase { } public void testDistanceSortingMVFields() throws Exception { + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type1") - .startObject("properties").startObject("locations").field("type", "geo_point").field("lat_lon", true) - .field("ignore_malformed", true).field("coerce", true) - .endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test") - .addMapping("type1", xContentBuilder)); + .startObject("properties").startObject("locations").field("type", "geo_point"); + if (version.before(Version.V_2_2_0)) { + xContentBuilder.field("lat_lon", true).field("coerce", true); + } + xContentBuilder.field("ignore_malformed", true).endObject().endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); ensureGreen(); client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() @@ -357,10 +370,15 @@ public class GeoDistanceTests extends ESIntegTestCase { // Regression bug: https://github.com/elasticsearch/elasticsearch/issues/2851 public void testDistanceSortingWithMissingGeoPoint() throws Exception { + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type1") - .startObject("properties").startObject("locations").field("type", "geo_point").field("lat_lon", true) - .endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test").addMapping("type1", xContentBuilder)); + .startObject("properties").startObject("locations").field("type", "geo_point"); + if (version.before(Version.V_2_2_0)) { + xContentBuilder.field("lat_lon", true); + } + xContentBuilder.endObject().endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); ensureGreen(); client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() @@ -407,10 +425,15 @@ public class GeoDistanceTests extends ESIntegTestCase { double target_lat = 32.81; double target_long = -117.21; + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type1") - .startObject("properties").startObject("location").field("type", "geo_point").field("lat_lon", true).endObject().endObject() - .endObject().endObject(); - assertAcked(prepareCreate("test").addMapping("type1", xContentBuilder)); + .startObject("properties").startObject("location").field("type", "geo_point"); + if (version.before(Version.V_2_2_0)) { + xContentBuilder.field("lat_lon", true); + } + xContentBuilder.endObject().endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); ensureGreen(); client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() @@ -425,28 +448,28 @@ public class GeoDistanceTests extends ESIntegTestCase { .actionGet(); Double resultDistance1 = searchResponse1.getHits().getHits()[0].getFields().get("distance").getValue(); assertThat(resultDistance1, - closeTo(GeoDistance.ARC.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.DEFAULT), 0.0001d)); + closeTo(GeoDistance.ARC.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.DEFAULT), 0.01d)); SearchResponse searchResponse2 = client().prepareSearch().addField("_source") .addScriptField("distance", new Script("doc['location'].distance(" + target_lat + "," + target_long + ")")).execute() .actionGet(); Double resultDistance2 = searchResponse2.getHits().getHits()[0].getFields().get("distance").getValue(); assertThat(resultDistance2, - closeTo(GeoDistance.PLANE.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.DEFAULT), 0.0001d)); + closeTo(GeoDistance.PLANE.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.DEFAULT), 0.01d)); SearchResponse searchResponse3 = client().prepareSearch().addField("_source") .addScriptField("distance", new Script("doc['location'].arcDistanceInKm(" + target_lat + "," + target_long + ")")) .execute().actionGet(); Double resultArcDistance3 = searchResponse3.getHits().getHits()[0].getFields().get("distance").getValue(); assertThat(resultArcDistance3, - closeTo(GeoDistance.ARC.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.KILOMETERS), 0.0001d)); + closeTo(GeoDistance.ARC.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.KILOMETERS), 0.01d)); SearchResponse searchResponse4 = client().prepareSearch().addField("_source") .addScriptField("distance", new Script("doc['location'].distanceInKm(" + target_lat + "," + target_long + ")")).execute() .actionGet(); Double resultDistance4 = searchResponse4.getHits().getHits()[0].getFields().get("distance").getValue(); assertThat(resultDistance4, - closeTo(GeoDistance.PLANE.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.KILOMETERS), 0.0001d)); + closeTo(GeoDistance.PLANE.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.KILOMETERS), 0.01d)); SearchResponse searchResponse5 = client() .prepareSearch() @@ -455,7 +478,7 @@ public class GeoDistanceTests extends ESIntegTestCase { .execute().actionGet(); Double resultArcDistance5 = searchResponse5.getHits().getHits()[0].getFields().get("distance").getValue(); assertThat(resultArcDistance5, - closeTo(GeoDistance.ARC.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.KILOMETERS), 0.0001d)); + closeTo(GeoDistance.ARC.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.KILOMETERS), 0.01d)); SearchResponse searchResponse6 = client() .prepareSearch() @@ -464,24 +487,26 @@ public class GeoDistanceTests extends ESIntegTestCase { .execute().actionGet(); Double resultArcDistance6 = searchResponse6.getHits().getHits()[0].getFields().get("distance").getValue(); assertThat(resultArcDistance6, - closeTo(GeoDistance.ARC.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.KILOMETERS), 0.0001d)); + closeTo(GeoDistance.ARC.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.KILOMETERS), 0.01d)); SearchResponse searchResponse7 = client().prepareSearch().addField("_source") .addScriptField("distance", new Script("doc['location'].arcDistanceInMiles(" + target_lat + "," + target_long + ")")) .execute().actionGet(); Double resultDistance7 = searchResponse7.getHits().getHits()[0].getFields().get("distance").getValue(); assertThat(resultDistance7, - closeTo(GeoDistance.ARC.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.MILES), 0.0001d)); + closeTo(GeoDistance.ARC.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.MILES), 0.01d)); SearchResponse searchResponse8 = client().prepareSearch().addField("_source") .addScriptField("distance", new Script("doc['location'].distanceInMiles(" + target_lat + "," + target_long + ")")) .execute().actionGet(); Double resultDistance8 = searchResponse8.getHits().getHits()[0].getFields().get("distance").getValue(); assertThat(resultDistance8, - closeTo(GeoDistance.PLANE.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.MILES), 0.0001d)); + closeTo(GeoDistance.PLANE.calculate(source_lat, source_long, target_lat, target_long, DistanceUnit.MILES), 0.01d)); } public void testDistanceSortingNestedFields() throws Exception { + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("company") .startObject("properties") .startObject("name").field("type", "string").endObject() @@ -489,14 +514,17 @@ public class GeoDistanceTests extends ESIntegTestCase { .field("type", "nested") .startObject("properties") .startObject("name").field("type", "string").endObject() - .startObject("location").field("type", "geo_point").field("lat_lon", true) - .endObject() + .startObject("location").field("type", "geo_point"); + if (version.before(Version.V_2_2_0)) { + xContentBuilder.field("lat_lon", true); + } + xContentBuilder.endObject() .endObject() .endObject() .endObject() .endObject().endObject(); - assertAcked(prepareCreate("companies").addMapping("company", xContentBuilder)); + assertAcked(prepareCreate("companies").setSettings(settings).addMapping("company", xContentBuilder)); ensureGreen(); indexRandom(true, client().prepareIndex("companies", "company", "1").setSource(jsonBuilder().startObject() @@ -645,29 +673,28 @@ public class GeoDistanceTests extends ESIntegTestCase { * Issue 3073 */ public void testGeoDistanceFilter() throws IOException { + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); double lat = 40.720611; double lon = -73.998776; XContentBuilder mapping = JsonXContent.contentBuilder() .startObject() - .startObject("location") - .startObject("properties") - .startObject("pin") - .field("type", "geo_point") - .field("geohash", true) - .field("geohash_precision", 24) - .field("lat_lon", true) - .endObject() - .endObject() - .endObject() - .endObject(); + .startObject("location") + .startObject("properties") + .startObject("pin") + .field("type", "geo_point"); + if (version.before(Version.V_2_2_0)) { + mapping.field("lat_lon", true); + } + mapping.endObject().endObject().endObject().endObject(); XContentBuilder source = JsonXContent.contentBuilder() .startObject() .field("pin", GeoHashUtils.stringEncode(lon, lat)) .endObject(); - assertAcked(prepareCreate("locations").addMapping("location", mapping)); + assertAcked(prepareCreate("locations").setSettings(settings).addMapping("location", mapping)); client().prepareIndex("locations", "location", "1").setCreate(true).setSource(source).execute().actionGet(); refresh(); client().prepareGet("locations", "location", "1").execute().actionGet(); @@ -692,11 +719,19 @@ public class GeoDistanceTests extends ESIntegTestCase { } public void testDuelOptimizations() throws Exception { - assertAcked(prepareCreate("index").addMapping("type", "location", "type=geo_point,lat_lon=true")); + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + if (version.before(Version.V_2_2_0)) { + assertAcked(prepareCreate("index").setSettings(settings) + .addMapping("type", "location", "type=geo_point,lat_lon=true")); + } else { + assertAcked(prepareCreate("index").setSettings(settings).addMapping("type", "location", "type=geo_point")); + } final int numDocs = scaledRandomIntBetween(3000, 10000); List docs = new ArrayList<>(); for (int i = 0; i < numDocs; ++i) { - docs.add(client().prepareIndex("index", "type").setSource(jsonBuilder().startObject().startObject("location").field("lat", randomLat()).field("lon", randomLon()).endObject().endObject())); + docs.add(client().prepareIndex("index", "type").setSource(jsonBuilder().startObject().startObject("location") + .field("lat", randomLat()).field("lon", randomLon()).endObject().endObject())); } indexRandom(true, docs); ensureSearchable(); @@ -707,20 +742,34 @@ public class GeoDistanceTests extends ESIntegTestCase { final String distance = DistanceUnit.KILOMETERS.toString(randomInt(10000)); for (GeoDistance geoDistance : Arrays.asList(GeoDistance.ARC, GeoDistance.SLOPPY_ARC)) { logger.info("Now testing GeoDistance={}, distance={}, origin=({}, {})", geoDistance, distance, originLat, originLon); - long matches = -1; - for (String optimizeBbox : Arrays.asList("none", "memory", "indexed")) { - SearchResponse resp = client().prepareSearch("index").setSize(0).setQuery(QueryBuilders.constantScoreQuery( - QueryBuilders.geoDistanceQuery("location").point(originLat, originLon).distance(distance).geoDistance(geoDistance).optimizeBbox(optimizeBbox))).execute().actionGet(); - assertSearchResponse(resp); - logger.info("{} -> {} hits", optimizeBbox, resp.getHits().totalHits()); - if (matches < 0) { - matches = resp.getHits().totalHits(); - } else { - assertEquals(matches, resp.getHits().totalHits()); + GeoDistanceQueryBuilder qb = QueryBuilders.geoDistanceQuery("location").point(originLat, originLon).distance(distance).geoDistance(geoDistance); + long matches; + if (version.before(Version.V_2_2_0)) { + for (String optimizeBbox : Arrays.asList("none", "memory", "indexed")) { + qb.optimizeBbox(optimizeBbox); + SearchResponse resp = client().prepareSearch("index").setSize(0) + .setQuery(QueryBuilders.constantScoreQuery(qb)).execute().actionGet(); + matches = assertDuelOptimization(resp); + logger.info("{} -> {} hits", optimizeBbox, matches); } + } else { + SearchResponse resp = client().prepareSearch("index").setSize(0) + .setQuery(QueryBuilders.constantScoreQuery(qb)).execute().actionGet(); + matches = assertDuelOptimization(resp); + logger.info("{} hits", matches); } } } } + private long assertDuelOptimization(SearchResponse resp) { + long matches = -1; + assertSearchResponse(resp); + if (matches < 0) { + matches = resp.getHits().totalHits(); + } else { + assertEquals(matches, matches = resp.getHits().totalHits()); + } + return matches; + } } \ No newline at end of file diff --git a/plugins/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SimpleSortTests.java b/plugins/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SimpleSortTests.java index f8f4e982239..5a00bca9fac 100644 --- a/plugins/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SimpleSortTests.java +++ b/plugins/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SimpleSortTests.java @@ -24,6 +24,7 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.UnicodeUtil; +import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchPhaseExecutionException; @@ -32,6 +33,7 @@ import org.elasticsearch.action.search.ShardSearchFailure; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.geo.GeoDistance; import org.elasticsearch.common.geo.GeoPoint; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.text.StringAndBytesText; import org.elasticsearch.common.text.Text; import org.elasticsearch.common.unit.DistanceUnit; @@ -52,6 +54,7 @@ import org.elasticsearch.search.sort.ScriptSortBuilder; import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.junit.annotations.TestLogging; import org.hamcrest.Matchers; @@ -96,6 +99,7 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; +import static org.apache.lucene.util.GeoUtils.TOLERANCE; /** * @@ -851,7 +855,7 @@ public class SimpleSortTests extends ESIntegTestCase { assertThat(searchResponse.getHits().getTotalHits(), equalTo(20l)); for (int i = 0; i < 10; i++) { - assertThat("res: " + i + " id: " + searchResponse.getHits().getAt(i).getId(), (Double) searchResponse.getHits().getAt(i).field("min").value(), equalTo((double) i)); + assertThat("res: " + i + " id: " + searchResponse.getHits().getAt(i).getId(), (Double) searchResponse.getHits().getAt(i).field("min").value(), closeTo((double) i, TOLERANCE)); } } @@ -1732,7 +1736,9 @@ public class SimpleSortTests extends ESIntegTestCase { * |___________________________ * 1 2 3 4 5 6 7 */ - assertAcked(prepareCreate("index").addMapping("type", "location", "type=geo_point")); + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + assertAcked(prepareCreate("index").setSettings(settings).addMapping("type", "location", "type=geo_point")); XContentBuilder d1Builder = jsonBuilder(); GeoPoint[] d1Points = {new GeoPoint(3, 2), new GeoPoint(4, 1)}; createShuffeldJSONArray(d1Builder, d1Points); @@ -1761,32 +1767,32 @@ public class SimpleSortTests extends ESIntegTestCase { .addSort(new GeoDistanceSortBuilder("location").points(q).sortMode("min").order(SortOrder.ASC).geoDistance(GeoDistance.PLANE).unit(DistanceUnit.KILOMETERS)) .execute().actionGet(); assertOrderedSearchHits(searchResponse, "d1", "d2"); - assertThat(searchResponse.getHits().getAt(0).getSortValues()[0], equalTo(GeoDistance.PLANE.calculate(2, 2, 3, 2, DistanceUnit.KILOMETERS))); - assertThat(searchResponse.getHits().getAt(1).getSortValues()[0], equalTo(GeoDistance.PLANE.calculate(2, 1, 5, 1, DistanceUnit.KILOMETERS))); + assertThat((Double)searchResponse.getHits().getAt(0).getSortValues()[0], closeTo(GeoDistance.PLANE.calculate(2, 2, 3, 2, DistanceUnit.KILOMETERS), 0.01d)); + assertThat((Double)searchResponse.getHits().getAt(1).getSortValues()[0], closeTo(GeoDistance.PLANE.calculate(2, 1, 5, 1, DistanceUnit.KILOMETERS), 0.01d)); searchResponse = client().prepareSearch() .setQuery(matchAllQuery()) .addSort(new GeoDistanceSortBuilder("location").points(q).sortMode("min").order(SortOrder.DESC).geoDistance(GeoDistance.PLANE).unit(DistanceUnit.KILOMETERS)) .execute().actionGet(); assertOrderedSearchHits(searchResponse, "d2", "d1"); - assertThat(searchResponse.getHits().getAt(0).getSortValues()[0], equalTo(GeoDistance.PLANE.calculate(2, 1, 5, 1, DistanceUnit.KILOMETERS))); - assertThat(searchResponse.getHits().getAt(1).getSortValues()[0], equalTo(GeoDistance.PLANE.calculate(2, 2, 3, 2, DistanceUnit.KILOMETERS))); + assertThat((Double)searchResponse.getHits().getAt(0).getSortValues()[0], closeTo(GeoDistance.PLANE.calculate(2, 1, 5, 1, DistanceUnit.KILOMETERS), 0.01d)); + assertThat((Double)searchResponse.getHits().getAt(1).getSortValues()[0], closeTo(GeoDistance.PLANE.calculate(2, 2, 3, 2, DistanceUnit.KILOMETERS), 0.01d)); searchResponse = client().prepareSearch() .setQuery(matchAllQuery()) .addSort(new GeoDistanceSortBuilder("location").points(q).sortMode("max").order(SortOrder.ASC).geoDistance(GeoDistance.PLANE).unit(DistanceUnit.KILOMETERS)) .execute().actionGet(); assertOrderedSearchHits(searchResponse, "d1", "d2"); - assertThat(searchResponse.getHits().getAt(0).getSortValues()[0], equalTo(GeoDistance.PLANE.calculate(2, 2, 4, 1, DistanceUnit.KILOMETERS))); - assertThat(searchResponse.getHits().getAt(1).getSortValues()[0], equalTo(GeoDistance.PLANE.calculate(2, 1, 6, 2, DistanceUnit.KILOMETERS))); + assertThat((Double)searchResponse.getHits().getAt(0).getSortValues()[0], closeTo(GeoDistance.PLANE.calculate(2, 2, 4, 1, DistanceUnit.KILOMETERS), 0.01d)); + assertThat((Double)searchResponse.getHits().getAt(1).getSortValues()[0], closeTo(GeoDistance.PLANE.calculate(2, 1, 6, 2, DistanceUnit.KILOMETERS), 0.01d)); searchResponse = client().prepareSearch() .setQuery(matchAllQuery()) .addSort(new GeoDistanceSortBuilder("location").points(q).sortMode("max").order(SortOrder.DESC).geoDistance(GeoDistance.PLANE).unit(DistanceUnit.KILOMETERS)) .execute().actionGet(); assertOrderedSearchHits(searchResponse, "d2", "d1"); - assertThat(searchResponse.getHits().getAt(0).getSortValues()[0], equalTo(GeoDistance.PLANE.calculate(2, 1, 6, 2, DistanceUnit.KILOMETERS))); - assertThat(searchResponse.getHits().getAt(1).getSortValues()[0], equalTo(GeoDistance.PLANE.calculate(2, 2, 4, 1, DistanceUnit.KILOMETERS))); + assertThat((Double)searchResponse.getHits().getAt(0).getSortValues()[0], closeTo(GeoDistance.PLANE.calculate(2, 1, 6, 2, DistanceUnit.KILOMETERS), 0.01d)); + assertThat((Double)searchResponse.getHits().getAt(1).getSortValues()[0], closeTo(GeoDistance.PLANE.calculate(2, 2, 4, 1, DistanceUnit.KILOMETERS), 0.01d)); } protected void createShuffeldJSONArray(XContentBuilder builder, GeoPoint[] pointsArray) throws IOException { @@ -1814,7 +1820,9 @@ public class SimpleSortTests extends ESIntegTestCase { * |______________________ * 1 2 3 4 5 6 */ - assertAcked(prepareCreate("index").addMapping("type", "location", "type=geo_point")); + Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT); + Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build(); + assertAcked(prepareCreate("index").setSettings(settings).addMapping("type", "location", "type=geo_point")); XContentBuilder d1Builder = jsonBuilder(); GeoPoint[] d1Points = {new GeoPoint(2.5, 1), new GeoPoint(2.75, 2), new GeoPoint(3, 3), new GeoPoint(3.25, 4)}; createShuffeldJSONArray(d1Builder, d1Points);