|
@@ -18,7 +18,6 @@
|
|
|
*/
|
|
|
package org.elasticsearch.index.mapper;
|
|
|
|
|
|
-import org.apache.lucene.index.IndexableField;
|
|
|
import org.apache.lucene.spatial.geopoint.document.GeoPointField;
|
|
|
import org.apache.lucene.util.BytesRef;
|
|
|
import org.elasticsearch.Version;
|
|
@@ -31,17 +30,13 @@ 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.index.mapper.DocumentMapper;
|
|
|
-import org.elasticsearch.index.mapper.DocumentMapperParser;
|
|
|
-import org.elasticsearch.index.mapper.MapperParsingException;
|
|
|
-import org.elasticsearch.index.mapper.MapperService;
|
|
|
-import org.elasticsearch.index.mapper.ParsedDocument;
|
|
|
import org.elasticsearch.plugins.Plugin;
|
|
|
import org.elasticsearch.search.SearchHitField;
|
|
|
import org.elasticsearch.test.ESSingleNodeTestCase;
|
|
|
import org.elasticsearch.test.InternalSettingsPlugin;
|
|
|
import org.elasticsearch.test.VersionUtils;
|
|
|
import org.elasticsearch.test.geo.RandomGeoGenerator;
|
|
|
+import org.hamcrest.CoreMatchers;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
@@ -67,12 +62,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
return pluginList(InternalSettingsPlugin.class);
|
|
|
}
|
|
|
|
|
|
- public void testLatLonValues() throws Exception {
|
|
|
+ public void testLegacyLatLonValues() throws Exception {
|
|
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
|
|
|
.endObject().endObject().string();
|
|
|
|
|
|
- Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_5_0_0_alpha5);
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
|
|
|
|
@@ -96,13 +91,13 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void testLatLonValuesWithGeohash() throws Exception {
|
|
|
+ public void testLegacyLatLonValuesWithGeohash() throws Exception {
|
|
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true)
|
|
|
.field("geohash", true).endObject().endObject()
|
|
|
.endObject().endObject().string();
|
|
|
|
|
|
- Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_5_0_0_alpha5);
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
|
|
|
|
@@ -121,12 +116,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void testLatLonInOneValueWithGeohash() throws Exception {
|
|
|
+ public void testLegacyLatLonInOneValueWithGeohash() throws Exception {
|
|
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true)
|
|
|
.field("geohash", true).endObject().endObject().endObject().endObject().string();
|
|
|
|
|
|
- Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_5_0_0_alpha5);
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
|
|
|
|
@@ -145,12 +140,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void testGeoHashIndexValue() throws Exception {
|
|
|
+ public void testLegacyGeoHashIndexValue() throws Exception {
|
|
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true)
|
|
|
.field("geohash", true).endObject().endObject().endObject().endObject().string();
|
|
|
|
|
|
- Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_5_0_0_alpha5);
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
|
|
|
|
@@ -170,11 +165,13 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
}
|
|
|
|
|
|
public void testGeoHashValue() throws Exception {
|
|
|
- String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true)
|
|
|
- .endObject().endObject().endObject().endObject().string();
|
|
|
-
|
|
|
Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point");
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true);
|
|
|
+ }
|
|
|
+ String mapping = xContentBuilder.endObject().endObject().endObject().endObject().string();
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
|
|
|
|
@@ -184,13 +181,15 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
.endObject()
|
|
|
.bytes());
|
|
|
|
|
|
- assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
|
|
|
- assertThat(doc.rootDoc().getField("point.lon"), notNullValue());
|
|
|
- assertThat(doc.rootDoc().get("point"), notNullValue());
|
|
|
+ assertThat(doc.rootDoc().getField("point"), notNullValue());
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
|
|
|
+ assertThat(doc.rootDoc().getField("point.lon"), notNullValue());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public void testNormalizeLatLonValuesDefault() throws Exception {
|
|
|
- Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ public void testNormalizeLegacyLatLonValuesDefault() throws Exception {
|
|
|
+ Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_5_0_0_alpha5);
|
|
|
// default to normalize
|
|
|
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
.startObject("properties").startObject("point").field("type", "geo_point");
|
|
@@ -239,8 +238,8 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void testValidateLatLonValues() throws Exception {
|
|
|
- Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ public void testLegacyValidateLatLonValues() throws Exception {
|
|
|
+ Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_5_0_0_alpha5);
|
|
|
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true);
|
|
|
if (version.before(Version.V_2_2_0)) {
|
|
@@ -338,8 +337,8 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void testNoValidateLatLonValues() throws Exception {
|
|
|
- Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ public void testNoValidateLegacyLatLonValues() throws Exception {
|
|
|
+ Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_5_0_0_alpha5);
|
|
|
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true);
|
|
|
if (version.before(Version.V_2_2_0)) {
|
|
@@ -400,11 +399,13 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
}
|
|
|
|
|
|
public void testLatLonValuesStored() throws Exception {
|
|
|
- String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true)
|
|
|
- .field("store", true).endObject().endObject().endObject().endObject().string();
|
|
|
-
|
|
|
- Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ Version version = VersionUtils.randomVersionBetween(random(), Version.CURRENT, Version.CURRENT);
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point");
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true);
|
|
|
+ }
|
|
|
+ String mapping = xContentBuilder.field("store", true).endObject().endObject().endObject().endObject().string();
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
|
|
|
|
@@ -414,24 +415,30 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
.endObject()
|
|
|
.bytes());
|
|
|
|
|
|
- assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
|
|
|
- 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));
|
|
|
- assertThat(doc.rootDoc().getField("point.geohash"), nullValue());
|
|
|
- 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(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
+ assertThat(doc.rootDoc().getField("point"), notNullValue());
|
|
|
+ // TODO LatLonPoint FieldType is private and frozen, need to add ability to store field
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
|
|
|
+ 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));
|
|
|
+ assertThat(doc.rootDoc().getField("point.geohash"), nullValue());
|
|
|
+ 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(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void testArrayLatLonValues() throws Exception {
|
|
|
- String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true)
|
|
|
- .field("store", true).endObject().endObject().endObject().endObject().string();
|
|
|
-
|
|
|
Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point").field("doc_values", false);
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true);
|
|
|
+ }
|
|
|
+ String mapping = xContentBuilder.field("store", true).endObject().endObject().endObject().endObject().string();
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
|
|
|
|
@@ -444,28 +451,10 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
.endObject()
|
|
|
.bytes());
|
|
|
|
|
|
- if (version.onOrAfter(Version.V_5_0_0_alpha2)) {
|
|
|
- assertThat(doc.rootDoc().getFields("point.lat").length, equalTo(4));
|
|
|
- assertThat(doc.rootDoc().getFields("point.lon").length, equalTo(4));
|
|
|
-
|
|
|
- // point field for 1st value
|
|
|
- assertThat(doc.rootDoc().getFields("point.lat")[0].numericValue().doubleValue(), equalTo(1.2));
|
|
|
- assertThat(doc.rootDoc().getFields("point.lon")[0].numericValue().doubleValue(), equalTo(1.3));
|
|
|
- // stored field for 1st value
|
|
|
- assertThat(doc.rootDoc().getFields("point.lat")[1].numericValue().doubleValue(), equalTo(1.2));
|
|
|
- assertThat(doc.rootDoc().getFields("point.lon")[1].numericValue().doubleValue(), equalTo(1.3));
|
|
|
- // indexed hash
|
|
|
- assertThat(Long.parseLong(doc.rootDoc().getFields("point")[0].stringValue()), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
-
|
|
|
- // point field for 2nd value
|
|
|
- assertThat(doc.rootDoc().getFields("point.lat")[2].numericValue().doubleValue(), equalTo(1.4));
|
|
|
- assertThat(doc.rootDoc().getFields("point.lon")[2].numericValue().doubleValue(), equalTo(1.5));
|
|
|
- // stored field for 2nd value
|
|
|
- assertThat(doc.rootDoc().getFields("point.lat")[3].numericValue().doubleValue(), equalTo(1.4));
|
|
|
- assertThat(doc.rootDoc().getFields("point.lon")[3].numericValue().doubleValue(), equalTo(1.5));
|
|
|
- // indexed hash
|
|
|
- assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoPointField.encodeLatLon(1.4, 1.5)));
|
|
|
- } else {
|
|
|
+ // doc values are enabled by default, but in this test we disable them; we should only have 2 points
|
|
|
+ assertThat(doc.rootDoc().getFields("point"), notNullValue());
|
|
|
+ assertThat(doc.rootDoc().getFields("point").length, equalTo(2));
|
|
|
+ if (version.before(Version.V_5_0_0_alpha2)) {
|
|
|
assertThat(doc.rootDoc().getFields("point.lat").length, equalTo(2));
|
|
|
assertThat(doc.rootDoc().getFields("point.lon").length, equalTo(2));
|
|
|
assertThat(doc.rootDoc().getFields("point.lat")[0].numericValue().doubleValue(), equalTo(1.2));
|
|
@@ -486,13 +475,16 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
}
|
|
|
|
|
|
public void testLatLonInOneValue() throws Exception {
|
|
|
- String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true)
|
|
|
- .endObject().endObject().endObject().endObject().string();
|
|
|
-
|
|
|
Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point");
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true);
|
|
|
+ }
|
|
|
+ String mapping = xContentBuilder.endObject().endObject().endObject().endObject().string();
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
- DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
|
|
+ DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type",
|
|
|
+ new CompressedXContent(mapping));
|
|
|
|
|
|
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
|
|
.startObject()
|
|
@@ -500,49 +492,61 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
.endObject()
|
|
|
.bytes());
|
|
|
|
|
|
- assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
|
|
|
- assertThat(doc.rootDoc().getField("point.lon"), notNullValue());
|
|
|
- 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")[0].stringValue()), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
+ assertThat(doc.rootDoc().getField("point"), notNullValue());
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
|
|
|
+ assertThat(doc.rootDoc().getField("point.lon"), notNullValue());
|
|
|
+ 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")[0].stringValue()), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void testLatLonInOneValueStored() throws Exception {
|
|
|
- String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("store", true).endObject().endObject()
|
|
|
- .endObject().endObject().string();
|
|
|
-
|
|
|
Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point");
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true);
|
|
|
+ }
|
|
|
+ String mapping = xContentBuilder.field("store", true).endObject().endObject().endObject().endObject().string();
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
- DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
|
|
+ DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type",
|
|
|
+ new CompressedXContent(mapping));
|
|
|
|
|
|
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
|
|
.startObject()
|
|
|
.field("point", "1.2,1.3")
|
|
|
.endObject()
|
|
|
.bytes());
|
|
|
-
|
|
|
- assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
|
|
|
- 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));
|
|
|
- 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")[0].stringValue()), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
+ assertThat(doc.rootDoc().getField("point"), notNullValue());
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
|
|
|
+ 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));
|
|
|
+ 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")[0].stringValue()),
|
|
|
+ equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void testLatLonInOneValueArray() throws Exception {
|
|
|
- String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true)
|
|
|
- .field("store", true).endObject().endObject().endObject().endObject().string();
|
|
|
-
|
|
|
Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point").field("doc_values", false);
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true);
|
|
|
+ }
|
|
|
+ String mapping = xContentBuilder.field("store", true).endObject().endObject().endObject().endObject().string();
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
- DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
|
|
+ DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type",
|
|
|
+ new CompressedXContent(mapping));
|
|
|
|
|
|
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
|
|
|
.startObject()
|
|
@@ -553,6 +557,9 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
.endObject()
|
|
|
.bytes());
|
|
|
|
|
|
+ // doc values are enabled by default, but in this test we disable them; we should only have 2 points
|
|
|
+ assertThat(doc.rootDoc().getFields("point"), notNullValue());
|
|
|
+ assertThat(doc.rootDoc().getFields("point").length, equalTo(2));
|
|
|
if (version.before(Version.V_5_0_0_alpha2)) {
|
|
|
assertThat(doc.rootDoc().getFields("point.lat").length, equalTo(2));
|
|
|
assertThat(doc.rootDoc().getFields("point.lon").length, equalTo(2));
|
|
@@ -560,34 +567,27 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
assertThat(doc.rootDoc().getFields("point.lon")[0].numericValue().doubleValue(), equalTo(1.3));
|
|
|
assertThat(doc.rootDoc().getFields("point.lat")[1].numericValue().doubleValue(), equalTo(1.4));
|
|
|
assertThat(doc.rootDoc().getFields("point.lon")[1].numericValue().doubleValue(), equalTo(1.5));
|
|
|
- } else {
|
|
|
- IndexableField[] latPoints = doc.rootDoc().getFields("point.lat");
|
|
|
- IndexableField[] lonPoints = doc.rootDoc().getFields("point.lon");
|
|
|
- assertThat(latPoints.length, equalTo(4));
|
|
|
- assertThat(lonPoints.length, equalTo(4));
|
|
|
- assertThat(latPoints[0].numericValue().doubleValue(), equalTo(1.2));
|
|
|
- assertThat(lonPoints[0].numericValue().doubleValue(), equalTo(1.3));
|
|
|
- assertThat(latPoints[2].numericValue().doubleValue(), equalTo(1.4));
|
|
|
- assertThat(lonPoints[2].numericValue().doubleValue(), equalTo(1.5));
|
|
|
}
|
|
|
if (version.before(Version.V_2_2_0)) {
|
|
|
assertThat(doc.rootDoc().getFields("point")[0].stringValue(), equalTo("1.2,1.3"));
|
|
|
- } else {
|
|
|
+ } else if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
assertThat(Long.parseLong(doc.rootDoc().getFields("point")[0].stringValue()), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
}
|
|
|
if (version.before(Version.V_2_2_0)) {
|
|
|
assertThat(doc.rootDoc().getFields("point")[1].stringValue(), equalTo("1.4,1.5"));
|
|
|
- } else {
|
|
|
+ } else if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoPointField.encodeLatLon(1.4, 1.5)));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void testLonLatArray() throws Exception {
|
|
|
- String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
|
|
|
- .endObject().endObject().string();
|
|
|
-
|
|
|
Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point");
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true);
|
|
|
+ }
|
|
|
+ String mapping = xContentBuilder.endObject().endObject().endObject().endObject().string();
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
|
|
|
|
@@ -597,22 +597,27 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
.endObject()
|
|
|
.bytes());
|
|
|
|
|
|
- assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
|
|
|
- assertThat(doc.rootDoc().getField("point.lon"), notNullValue());
|
|
|
- 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")[0].stringValue()), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
+ assertThat(doc.rootDoc().getField("point"), notNullValue());
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
|
|
|
+ assertThat(doc.rootDoc().getField("point.lon"), notNullValue());
|
|
|
+ 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")[0].stringValue()), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void testLonLatArrayDynamic() throws Exception {
|
|
|
- String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startArray("dynamic_templates").startObject()
|
|
|
- .startObject("point").field("match", "point*").startObject("mapping").field("type", "geo_point")
|
|
|
- .field("lat_lon", true).endObject().endObject().endObject().endArray().endObject().endObject().string();
|
|
|
-
|
|
|
- Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ Version version = VersionUtils.randomVersionBetween(random(), Version.CURRENT, Version.CURRENT);
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startArray("dynamic_templates").startObject().startObject("point").field("match", "point*")
|
|
|
+ .startObject("mapping").field("type", "geo_point");
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true);
|
|
|
+ }
|
|
|
+ String mapping = xContentBuilder.endObject().endObject().endObject().endArray().endObject().endObject().string();
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
|
|
|
|
@@ -622,21 +627,26 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
.endObject()
|
|
|
.bytes());
|
|
|
|
|
|
- assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
|
|
|
- assertThat(doc.rootDoc().getField("point.lon"), notNullValue());
|
|
|
- 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")[0].stringValue()), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
+ assertThat(doc.rootDoc().getField("point"), notNullValue());
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
|
|
|
+ assertThat(doc.rootDoc().getField("point.lon"), notNullValue());
|
|
|
+ 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")[0].stringValue()), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void testLonLatArrayStored() throws Exception {
|
|
|
- String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true)
|
|
|
- .field("store", true).endObject().endObject().endObject().endObject().string();
|
|
|
-
|
|
|
Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point");
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true);
|
|
|
+ }
|
|
|
+ String mapping = xContentBuilder.field("store", true).endObject().endObject().endObject().endObject().string();
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
|
|
|
|
@@ -646,23 +656,29 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
.endObject()
|
|
|
.bytes());
|
|
|
|
|
|
- assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
|
|
|
- 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));
|
|
|
- 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")[0].stringValue()), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
+ assertThat(doc.rootDoc().getField("point"), notNullValue());
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
|
|
|
+ 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));
|
|
|
+ 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")[0].stringValue()), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void testLonLatArrayArrayStored() throws Exception {
|
|
|
- String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true)
|
|
|
- .field("store", true).endObject().endObject().endObject().endObject().string();
|
|
|
-
|
|
|
Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point");
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true);
|
|
|
+ }
|
|
|
+ String mapping = xContentBuilder.field("store", true).field("doc_values", false).endObject().endObject()
|
|
|
+ .endObject().endObject().string();
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
|
|
|
|
@@ -675,6 +691,8 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
.endObject()
|
|
|
.bytes());
|
|
|
|
|
|
+ assertThat(doc.rootDoc().getFields("point"), notNullValue());
|
|
|
+ assertThat(doc.rootDoc().getFields("point").length, CoreMatchers.equalTo(2));
|
|
|
if (version.before(Version.V_5_0_0_alpha2)) {
|
|
|
assertThat(doc.rootDoc().getFields("point.lat").length, equalTo(2));
|
|
|
assertThat(doc.rootDoc().getFields("point.lon").length, equalTo(2));
|
|
@@ -692,19 +710,6 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
} else {
|
|
|
assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoPointField.encodeLatLon(1.4, 1.5)));
|
|
|
}
|
|
|
- } else {
|
|
|
- assertThat(doc.rootDoc().getFields("point.lat").length, equalTo(4));
|
|
|
- assertThat(doc.rootDoc().getFields("point.lon").length, equalTo(4));
|
|
|
- assertThat(doc.rootDoc().getFields("point.lat")[0].numericValue().doubleValue(), equalTo(1.2));
|
|
|
- assertThat(doc.rootDoc().getFields("point.lat")[1].numericValue().doubleValue(), equalTo(1.2));
|
|
|
- assertThat(doc.rootDoc().getFields("point.lon")[0].numericValue().doubleValue(), equalTo(1.3));
|
|
|
- assertThat(doc.rootDoc().getFields("point.lon")[1].numericValue().doubleValue(), equalTo(1.3));
|
|
|
- assertThat(Long.parseLong(doc.rootDoc().getFields("point")[0].stringValue()), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
|
|
|
- assertThat(doc.rootDoc().getFields("point.lat")[2].numericValue().doubleValue(), equalTo(1.4));
|
|
|
- assertThat(doc.rootDoc().getFields("point.lat")[3].numericValue().doubleValue(), equalTo(1.4));
|
|
|
- assertThat(doc.rootDoc().getFields("point.lon")[2].numericValue().doubleValue(), equalTo(1.5));
|
|
|
- assertThat(doc.rootDoc().getFields("point.lon")[3].numericValue().doubleValue(), equalTo(1.5));
|
|
|
- assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoPointField.encodeLatLon(1.4, 1.5)));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -717,11 +722,35 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
DocumentMapperParser parser = createIndex("test", settings).mapperService().documentMapperParser();
|
|
|
// test deprecation exceptions on newly created indexes
|
|
|
- try {
|
|
|
- String validateMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true)
|
|
|
- .field("validate", true).endObject().endObject()
|
|
|
+ if (version.onOrAfter(Version.V_5_0_0_alpha6)) {
|
|
|
+ try {
|
|
|
+ String normalizeMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
|
|
|
+ .endObject().endObject().string();
|
|
|
+ parser.parse("type", new CompressedXContent(normalizeMapping));
|
|
|
+ } catch (MapperParsingException e) {
|
|
|
+ assertEquals(e.getMessage(), "Mapping definition for [point] has unsupported parameters: [lat_lon : true]");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (version.onOrAfter(Version.V_5_0_0_alpha6)) {
|
|
|
+ try {
|
|
|
+ String normalizeMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point").field("geohash", true).endObject().endObject()
|
|
|
.endObject().endObject().string();
|
|
|
+ parser.parse("type", new CompressedXContent(normalizeMapping));
|
|
|
+ } catch (MapperParsingException e) {
|
|
|
+ assertEquals(e.getMessage(), "Mapping definition for [point] has unsupported parameters: [geohash : true]");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point");
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true).field("geohash", true);
|
|
|
+ }
|
|
|
+ String validateMapping = xContentBuilder.field("validate", true).endObject().endObject().endObject().endObject().string();
|
|
|
parser.parse("type", new CompressedXContent(validateMapping));
|
|
|
fail("process completed successfully when " + MapperParsingException.class.getName() + " expected");
|
|
|
} catch (MapperParsingException e) {
|
|
@@ -729,10 +758,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- String validateMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true)
|
|
|
- .field("validate_lat", true).endObject().endObject()
|
|
|
- .endObject().endObject().string();
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point");
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true).field("geohash", true);
|
|
|
+ }
|
|
|
+ String validateMapping = xContentBuilder.field("validate_lat", true).endObject().endObject().endObject().endObject().string();
|
|
|
parser.parse("type", new CompressedXContent(validateMapping));
|
|
|
fail("process completed successfully when " + MapperParsingException.class.getName() + " expected");
|
|
|
} catch (MapperParsingException e) {
|
|
@@ -740,10 +771,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- String validateMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true)
|
|
|
- .field("validate_lon", true).endObject().endObject()
|
|
|
- .endObject().endObject().string();
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point");
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true).field("geohash", true);
|
|
|
+ }
|
|
|
+ String validateMapping = xContentBuilder.field("validate_lon", true).endObject().endObject().endObject().endObject().string();
|
|
|
parser.parse("type", new CompressedXContent(validateMapping));
|
|
|
fail("process completed successfully when " + MapperParsingException.class.getName() + " expected");
|
|
|
} catch (MapperParsingException e) {
|
|
@@ -752,10 +785,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
|
|
|
// test deprecated normalize
|
|
|
try {
|
|
|
- String normalizeMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true)
|
|
|
- .field("normalize", true).endObject().endObject()
|
|
|
- .endObject().endObject().string();
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point");
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true).field("geohash", true);
|
|
|
+ }
|
|
|
+ String normalizeMapping = xContentBuilder.field("normalize", true).endObject().endObject().endObject().endObject().string();
|
|
|
parser.parse("type", new CompressedXContent(normalizeMapping));
|
|
|
fail("process completed successfully when " + MapperParsingException.class.getName() + " expected");
|
|
|
} catch (MapperParsingException e) {
|
|
@@ -763,10 +798,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- String normalizeMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true)
|
|
|
- .field("normalize_lat", true).endObject().endObject()
|
|
|
- .endObject().endObject().string();
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point");
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true).field("geohash", true);
|
|
|
+ }
|
|
|
+ String normalizeMapping = xContentBuilder.field("normalize_lat", true).endObject().endObject().endObject().endObject().string();
|
|
|
parser.parse("type", new CompressedXContent(normalizeMapping));
|
|
|
fail("process completed successfully when " + MapperParsingException.class.getName() + " expected");
|
|
|
} catch (MapperParsingException e) {
|
|
@@ -774,10 +811,12 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- String normalizeMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true)
|
|
|
- .field("normalize_lon", true).endObject().endObject()
|
|
|
- .endObject().endObject().string();
|
|
|
+ XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("point").field("type", "geo_point");
|
|
|
+ if (version.before(Version.V_5_0_0_alpha6)) {
|
|
|
+ xContentBuilder = xContentBuilder.field("lat_lon", true).field("geohash", true);
|
|
|
+ }
|
|
|
+ String normalizeMapping = xContentBuilder.field("normalize_lon", true).endObject().endObject().endObject().endObject().string();
|
|
|
parser.parse("type", new CompressedXContent(normalizeMapping));
|
|
|
fail("process completed successfully when " + MapperParsingException.class.getName() + " expected");
|
|
|
} catch (MapperParsingException e) {
|
|
@@ -785,8 +824,8 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void testGeoPointMapperMerge() throws Exception {
|
|
|
- Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ public void testLegacyGeoPointMapperMerge() throws Exception {
|
|
|
+ Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_5_0_0_alpha5);
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
String stage1Mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true)
|
|
@@ -812,7 +851,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
mapperService.merge("type", new CompressedXContent(stage2Mapping), MapperService.MergeReason.MAPPING_UPDATE, false);
|
|
|
}
|
|
|
|
|
|
- public void testGeoHashSearch() throws Exception {
|
|
|
+ public void testLegacyGeoHashSearch() throws Exception {
|
|
|
// create a geo_point mapping with geohash enabled and random (between 1 and 12) geohash precision
|
|
|
int precision = randomIntBetween(1, 12);
|
|
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("pin").startObject("properties").startObject("location")
|
|
@@ -820,7 +859,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
.endObject().endObject().endObject().string();
|
|
|
|
|
|
// create index and add a test point (dr5regy6rc6z)
|
|
|
- Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_5_0_0_alpha1);
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
CreateIndexRequestBuilder mappingRequest = client().admin().indices().prepareCreate("test").setSettings(settings)
|
|
|
.addMapping("pin", mapping);
|
|
@@ -837,7 +876,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
assertEquals("dr5regy6rc6y".substring(0, precision), m.get("location.geohash").value());
|
|
|
}
|
|
|
|
|
|
- public void testGeoHashSearchWithPrefix() throws Exception {
|
|
|
+ public void testLegacyGeoHashSearchWithPrefix() throws Exception {
|
|
|
// create a geo_point mapping with geohash enabled and random (between 1 and 12) geohash precision
|
|
|
int precision = randomIntBetween(1, 12);
|
|
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("pin").startObject("properties").startObject("location")
|
|
@@ -845,7 +884,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
.endObject().endObject().endObject().endObject().string();
|
|
|
|
|
|
// create index and add a test point (dr5regy6rc6z)
|
|
|
- Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
|
|
|
+ Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_5_0_0_alpha5);
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
|
|
|
CreateIndexRequestBuilder mappingRequest = client().admin().indices().prepareCreate("test").setSettings(settings)
|
|
|
.addMapping("pin", mapping);
|
|
@@ -870,9 +909,11 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
public void testMultiField() throws Exception {
|
|
|
int numDocs = randomIntBetween(10, 100);
|
|
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("pin").startObject("properties").startObject("location")
|
|
|
- .field("type", "geo_point").startObject("fields")
|
|
|
- .startObject("geohash").field("type", "geo_point").field("geohash_precision", 12).field("geohash_prefix", true).endObject()
|
|
|
- .startObject("latlon").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
|
|
|
+ .field("type", "geo_point")
|
|
|
+ .startObject("fields")
|
|
|
+ .startObject("geohash").field("type", "keyword").endObject() // test geohash as keyword
|
|
|
+ .startObject("latlon").field("type", "string").endObject() // test geohash as string
|
|
|
+ .endObject()
|
|
|
.endObject().endObject().endObject().endObject().string();
|
|
|
CreateIndexRequestBuilder mappingRequest = client().admin().indices().prepareCreate("test")
|
|
|
.addMapping("pin", mapping);
|
|
@@ -886,6 +927,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
.field("lon", pt.lon()).endObject().endObject()).setRefreshPolicy(IMMEDIATE).get();
|
|
|
}
|
|
|
|
|
|
+ // TODO these tests are bogus and need to be Fix
|
|
|
// query by geohash subfield
|
|
|
SearchResponse searchResponse = client().prepareSearch().addStoredField("location.geohash").setQuery(matchAllQuery()).execute().actionGet();
|
|
|
assertEquals(numDocs, searchResponse.getHits().totalHits());
|
|
@@ -899,7 +941,7 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
public void testEmptyName() throws Exception {
|
|
|
// after 5.x
|
|
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
- .startObject("properties").startObject("").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
|
|
|
+ .startObject("properties").startObject("").field("type", "geo_point").endObject().endObject()
|
|
|
.endObject().endObject().string();
|
|
|
|
|
|
Version version = Version.CURRENT;
|