|
19 | 19 |
|
20 | 20 | package org.elasticsearch.search.suggest.completion.context;
|
21 | 21 |
|
| 22 | +import org.apache.logging.log4j.LogManager; |
| 23 | +import org.apache.lucene.document.LatLonDocValuesField; |
| 24 | +import org.apache.lucene.document.LatLonPoint; |
22 | 25 | import org.apache.lucene.document.StringField;
|
23 | 26 | import org.apache.lucene.index.DocValuesType;
|
24 | 27 | import org.apache.lucene.index.IndexableField;
|
25 | 28 | import org.elasticsearch.ElasticsearchParseException;
|
| 29 | +import org.elasticsearch.Version; |
26 | 30 | import org.elasticsearch.common.geo.GeoPoint;
|
27 | 31 | import org.elasticsearch.common.geo.GeoUtils;
|
| 32 | +import org.elasticsearch.common.logging.DeprecationLogger; |
28 | 33 | import org.elasticsearch.common.unit.DistanceUnit;
|
29 | 34 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
30 | 35 | import org.elasticsearch.common.xcontent.XContentParser;
|
|
42 | 47 | import java.util.Map;
|
43 | 48 | import java.util.Objects;
|
44 | 49 | import java.util.Set;
|
| 50 | +import java.util.function.Function; |
45 | 51 | import java.util.stream.Collectors;
|
46 | 52 |
|
47 | 53 | import static org.elasticsearch.common.geo.GeoHashUtils.addNeighbors;
|
@@ -69,6 +75,8 @@ public class GeoContextMapping extends ContextMapping<GeoQueryContext> {
|
69 | 75 | static final String CONTEXT_PRECISION = "precision";
|
70 | 76 | static final String CONTEXT_NEIGHBOURS = "neighbours";
|
71 | 77 |
|
| 78 | + private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(LogManager.getLogger(GeoContextMapping.class)); |
| 79 | + |
72 | 80 | private final int precision;
|
73 | 81 | private final String fieldName;
|
74 | 82 |
|
@@ -205,11 +213,11 @@ public Set<CharSequence> parseContext(Document document) {
|
205 | 213 | for (IndexableField field : fields) {
|
206 | 214 | if (field instanceof StringField) {
|
207 | 215 | spare.resetFromString(field.stringValue());
|
208 |
| - } else { |
209 |
| - // todo return this to .stringValue() once LatLonPoint implements it |
| 216 | + geohashes.add(spare.geohash()); |
| 217 | + } else if (field instanceof LatLonPoint || field instanceof LatLonDocValuesField) { |
210 | 218 | spare.resetFromIndexableField(field);
|
| 219 | + geohashes.add(spare.geohash()); |
211 | 220 | }
|
212 |
| - geohashes.add(spare.geohash()); |
213 | 221 | }
|
214 | 222 | }
|
215 | 223 | }
|
@@ -279,6 +287,21 @@ public List<InternalQueryContext> toInternalQueryContexts(List<GeoQueryContext>
|
279 | 287 | return internalQueryContextList;
|
280 | 288 | }
|
281 | 289 |
|
| 290 | + @Override |
| 291 | + protected void validateReferences(Version indexVersionCreated, Function<String, MappedFieldType> fieldResolver) { |
| 292 | + if (fieldName != null) { |
| 293 | + MappedFieldType mappedFieldType = fieldResolver.apply(fieldName); |
| 294 | + if (mappedFieldType == null) { |
| 295 | + DEPRECATION_LOGGER.deprecatedAndMaybeLog("geo_context_mapping", |
| 296 | + "field [{}] referenced in context [{}] is not defined in the mapping", fieldName, name); |
| 297 | + } else if (GeoPointFieldMapper.CONTENT_TYPE.equals(mappedFieldType.typeName()) == false) { |
| 298 | + DEPRECATION_LOGGER.deprecatedAndMaybeLog("geo_context_mapping", |
| 299 | + "field [{}] referenced in context [{}] must be mapped to geo_point, found [{}]", |
| 300 | + fieldName, name, mappedFieldType.typeName()); |
| 301 | + } |
| 302 | + } |
| 303 | + } |
| 304 | + |
282 | 305 | @Override
|
283 | 306 | public boolean equals(Object o) {
|
284 | 307 | if (this == o) return true;
|
|
0 commit comments