Skip to content

Commit 1a60e1c

Browse files
committed
Update docs for LatLonPoint cut over
This commit removes documentation for: * geohash cell query * lat_lon parameter * geohash parameter * geohash_precision parameter * geohash_prefix parameter It also updates failing tests that reference these parameters for backcompat.
1 parent ef92689 commit 1a60e1c

30 files changed

+111
-494
lines changed

core/src/main/java/org/elasticsearch/common/geo/GeoPoint.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import org.apache.lucene.index.IndexableField;
2626
import org.apache.lucene.spatial.geopoint.document.GeoPointField;
2727
import org.apache.lucene.util.BitUtil;
28-
import org.apache.lucene.util.NumericUtils;
28+
import org.apache.lucene.util.BytesRef;
29+
30+
import java.util.Arrays;
2931

3032
import static org.elasticsearch.common.geo.GeoHashUtils.mortonEncode;
3133
import static org.elasticsearch.common.geo.GeoHashUtils.stringEncode;
@@ -97,7 +99,8 @@ public GeoPoint resetFromIndexHash(long hash) {
9799
// todo remove with next release of lucene
98100
public GeoPoint resetFromIndexableField(IndexableField field) {
99101
if (field instanceof LatLonPoint) {
100-
byte[] bytes = field.binaryValue().bytes;
102+
BytesRef br = field.binaryValue();
103+
byte[] bytes = Arrays.copyOfRange(br.bytes, br.offset, br.length);
101104
return this.reset(
102105
GeoEncodingUtils.decodeLatitude(bytes, 0),
103106
GeoEncodingUtils.decodeLongitude(bytes, Integer.BYTES));

core/src/main/java/org/elasticsearch/index/fielddata/plain/AbstractLatLonPointDVIndexFieldData.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.lucene.index.FieldInfo;
2525
import org.apache.lucene.index.LeafReader;
2626
import org.apache.lucene.index.LeafReaderContext;
27+
import org.elasticsearch.ElasticsearchException;
2728
import org.elasticsearch.common.Nullable;
2829
import org.elasticsearch.index.Index;
2930
import org.elasticsearch.index.IndexSettings;
@@ -38,9 +39,6 @@
3839

3940
import java.io.IOException;
4041

41-
/**
42-
* Created by nknize on 8/23/16.
43-
*/
4442
public abstract class AbstractLatLonPointDVIndexFieldData extends DocValuesIndexFieldData
4543
implements IndexGeoPointFieldData {
4644
AbstractLatLonPointDVIndexFieldData(Index index, String fieldName) {

core/src/main/java/org/elasticsearch/index/fielddata/plain/LatLonPointDVAtomicFieldData.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
import java.util.Collection;
3131
import java.util.Collections;
3232

33-
/**
34-
* Created by nknize on 8/23/16.
35-
*/
3633
final class LatLonPointDVAtomicFieldData extends AbstractAtomicGeoPointFieldData {
3734
private final SortedNumericDocValues values;
3835

core/src/main/java/org/elasticsearch/index/mapper/BaseGeoPointFieldMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public abstract Y build(BuilderContext context, String simpleName, MappedFieldTy
144144

145145
public Y build(Mapper.BuilderContext context) {
146146
// version 5.0 cuts over to LatLonPoint and no longer indexes geohash, or lat/lon separately
147-
if (context.indexCreatedVersion().before(Version.V_5_0_0_alpha6)) {
147+
if (context.indexCreatedVersion().before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
148148
return buildLegacy(context);
149149
}
150150
return build(context, name, fieldType, defaultFieldType, context.indexSettings(),
@@ -203,7 +203,7 @@ public abstract static class TypeParser implements Mapper.TypeParser {
203203
Version indexVersionCreated = parserContext.indexVersionCreated();
204204
if (indexVersionCreated.before(Version.V_2_2_0)) {
205205
builder = new LegacyGeoPointFieldMapper.Builder(name);
206-
} else if (indexVersionCreated.onOrAfter(Version.V_5_0_0_alpha6)) {
206+
} else if (indexVersionCreated.onOrAfter(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
207207
builder = new LatLonPointFieldMapper.Builder(name);
208208
} else {
209209
builder = new GeoPointFieldMapper.Builder(name);
@@ -214,7 +214,7 @@ public abstract static class TypeParser implements Mapper.TypeParser {
214214
Map.Entry<String, Object> entry = iterator.next();
215215
String propName = entry.getKey();
216216
Object propNode = entry.getValue();
217-
if (indexVersionCreated.before(Version.V_5_0_0_alpha6)) {
217+
if (indexVersionCreated.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
218218
if (propName.equals("lat_lon")) {
219219
deprecationLogger.deprecated(CONTENT_TYPE + " lat_lon parameter is deprecated and will be removed "
220220
+ "in the next major release");

core/src/main/java/org/elasticsearch/index/mapper/LatLonPointFieldMapper.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020

2121
import org.apache.lucene.document.LatLonDocValuesField;
2222
import org.apache.lucene.document.LatLonPoint;
23+
import org.apache.lucene.document.StoredField;
2324
import org.apache.lucene.index.IndexOptions;
2425
import org.apache.lucene.search.Query;
26+
import org.elasticsearch.Version;
2527
import org.elasticsearch.common.Explicit;
2628
import org.elasticsearch.common.geo.GeoPoint;
2729
import org.elasticsearch.common.geo.GeoUtils;
@@ -36,10 +38,13 @@
3638
import java.util.Map;
3739

3840
/**
39-
* Created by nknize on 8/23/16.
41+
* Field Mapper for geo_point types.
42+
*
43+
* Uses lucene 6 LatLonPoint encoding
4044
*/
4145
public class LatLonPointFieldMapper extends BaseGeoPointFieldMapper {
4246
public static final String CONTENT_TYPE = "geo_point";
47+
public static final Version LAT_LON_FIELD_VERSION = Version.V_5_0_0_alpha6;
4348

4449
public static class Defaults extends BaseGeoPointFieldMapper.Defaults {
4550
public static final LatLonPointFieldType FIELD_TYPE = new LatLonPointFieldType();
@@ -134,9 +139,12 @@ protected void parse(ParseContext originalContext, GeoPoint point, String geoHas
134139
} else {
135140
GeoUtils.normalizePoint(point);
136141
}
137-
if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
142+
if (fieldType().indexOptions() != IndexOptions.NONE) {
138143
context.doc().add(new LatLonPoint(fieldType().name(), point.lat(), point.lon()));
139144
}
145+
if (fieldType().stored()) {
146+
context.doc().add(new StoredField(fieldType().name(), point.toString()));
147+
}
140148
if (fieldType.hasDocValues()) {
141149
context.doc().add(new LatLonDocValuesField(fieldType().name(), point.lat(), point.lon()));
142150
}

core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
4141
import org.elasticsearch.index.mapper.BaseGeoPointFieldMapper;
4242
import org.elasticsearch.index.mapper.BaseGeoPointFieldMapper.LegacyGeoPointFieldType;
43+
import org.elasticsearch.index.mapper.LatLonPointFieldMapper;
4344
import org.elasticsearch.index.mapper.MappedFieldType;
4445
import org.elasticsearch.index.search.geo.LegacyInMemoryGeoBoundingBoxQuery;
4546
import org.elasticsearch.index.search.geo.LegacyIndexedGeoBoundingBoxQuery;
@@ -360,7 +361,7 @@ public Query doToQuery(QueryShardContext context) {
360361
}
361362
}
362363

363-
if (indexVersionCreated.onOrAfter(Version.V_5_0_0_alpha6)) {
364+
if (indexVersionCreated.onOrAfter(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
364365
return LatLonPoint.newBoxQuery(fieldType.name(), luceneBottomRight.getLat(), luceneTopLeft.getLat(),
365366
luceneTopLeft.getLon(), luceneBottomRight.getLon());
366367
} else if (indexVersionCreated.onOrAfter(Version.V_2_2_0)) {

core/src/main/java/org/elasticsearch/index/query/GeoDistanceQueryBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
4040
import org.elasticsearch.index.mapper.BaseGeoPointFieldMapper;
4141
import org.elasticsearch.index.mapper.GeoPointFieldMapper;
42+
import org.elasticsearch.index.mapper.LatLonPointFieldMapper;
4243
import org.elasticsearch.index.mapper.LegacyGeoPointFieldMapper;
4344
import org.elasticsearch.index.mapper.MappedFieldType;
4445
import org.elasticsearch.index.search.geo.GeoDistanceRangeQuery;
@@ -298,7 +299,7 @@ protected Query doToQuery(QueryShardContext shardContext) throws IOException {
298299

299300
double normDistance = geoDistance.normalize(this.distance, DistanceUnit.DEFAULT);
300301

301-
if (indexVersionCreated.onOrAfter(Version.V_5_0_0_alpha6)) {
302+
if (indexVersionCreated.onOrAfter(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
302303
return LatLonPoint.newDistanceQuery(fieldType.name(), center.lat(), center.lon(), normDistance);
303304
} else if (indexVersionCreated.before(Version.V_2_2_0)) {
304305
LegacyGeoPointFieldMapper.LegacyGeoPointFieldType geoFieldType = (LegacyGeoPointFieldMapper.LegacyGeoPointFieldType) fieldType;

core/src/main/java/org/elasticsearch/index/query/GeoDistanceRangeQueryBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.elasticsearch.index.mapper.BaseGeoPointFieldMapper;
4040
import org.elasticsearch.index.mapper.BaseGeoPointFieldMapper.LegacyGeoPointFieldType;
4141
import org.elasticsearch.index.mapper.GeoPointFieldMapper;
42+
import org.elasticsearch.index.mapper.LatLonPointFieldMapper;
4243
import org.elasticsearch.index.mapper.MappedFieldType;
4344
import org.elasticsearch.index.search.geo.GeoDistanceRangeQuery;
4445

@@ -347,7 +348,7 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
347348
}
348349

349350
final Version indexVersionCreated = context.indexVersionCreated();
350-
if (indexVersionCreated.onOrAfter(Version.V_5_0_0_alpha6)) {
351+
if (indexVersionCreated.onOrAfter(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
351352
throw new QueryShardException(context, "[{}] queries are no longer supported for geo_point field types. "
352353
+ "Use geo_distance sort or aggregations", NAME);
353354
} else if (indexVersionCreated.before(Version.V_2_2_0)) {

core/src/main/java/org/elasticsearch/index/query/GeoPolygonQueryBuilder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.elasticsearch.index.query;
2121

22+
import org.apache.lucene.document.LatLonPoint;
23+
import org.apache.lucene.geo.Polygon;
2224
import org.apache.lucene.search.MatchNoDocsQuery;
2325
import org.apache.lucene.search.Query;
2426
import org.apache.lucene.spatial.geopoint.document.GeoPointField;
@@ -36,6 +38,7 @@
3638
import org.elasticsearch.common.xcontent.XContentParser.Token;
3739
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
3840
import org.elasticsearch.index.mapper.BaseGeoPointFieldMapper;
41+
import org.elasticsearch.index.mapper.LatLonPointFieldMapper;
3942
import org.elasticsearch.index.mapper.MappedFieldType;
4043
import org.elasticsearch.index.search.geo.GeoPolygonQuery;
4144

@@ -210,10 +213,14 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
210213
double[] lons = new double[shellSize];
211214
GeoPoint p;
212215
for (int i=0; i<shellSize; ++i) {
213-
p = new GeoPoint(shell.get(i));
216+
p = shell.get(i);
214217
lats[i] = p.lat();
215218
lons[i] = p.lon();
216219
}
220+
221+
if (indexVersionCreated.onOrAfter(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
222+
return LatLonPoint.newPolygonQuery(fieldType.name(), new Polygon(lats, lons));
223+
}
217224
// if index created V_2_2 use (soon to be legacy) numeric encoding postings format
218225
// if index created V_2_3 > use prefix encoded postings format
219226
final GeoPointField.TermEncoding encoding = (indexVersionCreated.before(Version.V_2_3_0)) ?

core/src/test/java/org/elasticsearch/index/mapper/ExternalFieldMapperTests.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.cluster.metadata.IndexMetaData;
2727
import org.elasticsearch.common.compress.CompressedXContent;
2828
import org.elasticsearch.common.geo.GeoHashUtils;
29+
import org.elasticsearch.common.geo.GeoPoint;
2930
import org.elasticsearch.common.settings.Settings;
3031
import org.elasticsearch.common.xcontent.XContentFactory;
3132
import org.elasticsearch.index.IndexService;
@@ -40,6 +41,7 @@
4041
import java.util.HashMap;
4142
import java.util.Map;
4243

44+
import static org.hamcrest.Matchers.closeTo;
4345
import static org.hamcrest.Matchers.is;
4446
import static org.hamcrest.Matchers.notNullValue;
4547

@@ -84,7 +86,7 @@ public void testExternalValues() throws Exception {
8486
assertThat(doc.rootDoc().getField("field.point"), notNullValue());
8587
if (version.before(Version.V_2_2_0)) {
8688
assertThat(doc.rootDoc().getField("field.point").stringValue(), is("42.0,51.0"));
87-
} else if (version.after(Version.V_5_0_0_alpha6)) {
89+
} else if (version.after(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
8890
assertThat(Long.parseLong(doc.rootDoc().getField("field.point").stringValue()), is(GeoPointField.encodeLatLon(42.0, 51.0)));
8991
}
9092

@@ -142,8 +144,12 @@ public void testExternalValuesWithMultifield() throws Exception {
142144
assertThat(doc.rootDoc().getField("field.point"), notNullValue());
143145
if (version.before(Version.V_2_2_0)) {
144146
assertThat(doc.rootDoc().getField("field.point").stringValue(), is("42.0,51.0"));
145-
} else if (version.after(Version.V_5_0_0_alpha6)) {
147+
} else if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
146148
assertThat(Long.parseLong(doc.rootDoc().getField("field.point").stringValue()), is(GeoPointField.encodeLatLon(42.0, 51.0)));
149+
} else {
150+
GeoPoint point = new GeoPoint().resetFromIndexableField(doc.rootDoc().getField("field.point"));
151+
assertThat(point.lat(), closeTo(42.0, 1E-5));
152+
assertThat(point.lon(), closeTo(51.0, 1E-5));
147153
}
148154

149155
IndexableField shape = doc.rootDoc().getField("field.shape");
@@ -212,7 +218,7 @@ public void testExternalValuesWithMultifieldTwoLevels() throws Exception {
212218
assertThat(doc.rootDoc().getField("field.point"), notNullValue());
213219
if (version.before(Version.V_2_2_0)) {
214220
assertThat(doc.rootDoc().getField("field.point").stringValue(), is("42.0,51.0"));
215-
} else if (version.before(Version.V_5_0_0_alpha6)) {
221+
} else if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
216222
assertThat(Long.parseLong(doc.rootDoc().getField("field.point").stringValue()), is(GeoPointField.encodeLatLon(42.0, 51.0)));
217223
}
218224

core/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public ExternalMapper build(BuilderContext context) {
8686
BaseGeoPointFieldMapper pointMapper;
8787
if (context.indexCreatedVersion().before(Version.V_2_2_0)) {
8888
pointMapper = legacyPointBuilder.build(context);
89-
} else if (context.indexCreatedVersion().onOrAfter(Version.V_5_0_0_alpha6)) {
89+
} else if (context.indexCreatedVersion().onOrAfter(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
9090
pointMapper = latLonPointBuilder.build(context);
9191
} else {
9292
pointMapper = pointBuilder.build(context);

0 commit comments

Comments
 (0)