|
@@ -19,12 +19,17 @@
|
|
|
|
|
|
package org.elasticsearch.search.suggest.completion.context;
|
|
package org.elasticsearch.search.suggest.completion.context;
|
|
|
|
|
|
|
|
+import org.apache.logging.log4j.LogManager;
|
|
|
|
+import org.apache.lucene.document.LatLonDocValuesField;
|
|
|
|
+import org.apache.lucene.document.LatLonPoint;
|
|
import org.apache.lucene.document.StringField;
|
|
import org.apache.lucene.document.StringField;
|
|
import org.apache.lucene.index.DocValuesType;
|
|
import org.apache.lucene.index.DocValuesType;
|
|
import org.apache.lucene.index.IndexableField;
|
|
import org.apache.lucene.index.IndexableField;
|
|
import org.elasticsearch.ElasticsearchParseException;
|
|
import org.elasticsearch.ElasticsearchParseException;
|
|
|
|
+import org.elasticsearch.Version;
|
|
import org.elasticsearch.common.geo.GeoPoint;
|
|
import org.elasticsearch.common.geo.GeoPoint;
|
|
import org.elasticsearch.common.geo.GeoUtils;
|
|
import org.elasticsearch.common.geo.GeoUtils;
|
|
|
|
+import org.elasticsearch.common.logging.DeprecationLogger;
|
|
import org.elasticsearch.common.unit.DistanceUnit;
|
|
import org.elasticsearch.common.unit.DistanceUnit;
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
@@ -42,6 +47,7 @@ import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
+import java.util.function.Function;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static org.elasticsearch.common.geo.GeoHashUtils.addNeighbors;
|
|
import static org.elasticsearch.common.geo.GeoHashUtils.addNeighbors;
|
|
@@ -69,6 +75,8 @@ public class GeoContextMapping extends ContextMapping<GeoQueryContext> {
|
|
static final String CONTEXT_PRECISION = "precision";
|
|
static final String CONTEXT_PRECISION = "precision";
|
|
static final String CONTEXT_NEIGHBOURS = "neighbours";
|
|
static final String CONTEXT_NEIGHBOURS = "neighbours";
|
|
|
|
|
|
|
|
+ private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(LogManager.getLogger(GeoContextMapping.class));
|
|
|
|
+
|
|
private final int precision;
|
|
private final int precision;
|
|
private final String fieldName;
|
|
private final String fieldName;
|
|
|
|
|
|
@@ -205,11 +213,11 @@ public class GeoContextMapping extends ContextMapping<GeoQueryContext> {
|
|
for (IndexableField field : fields) {
|
|
for (IndexableField field : fields) {
|
|
if (field instanceof StringField) {
|
|
if (field instanceof StringField) {
|
|
spare.resetFromString(field.stringValue());
|
|
spare.resetFromString(field.stringValue());
|
|
- } else {
|
|
|
|
- // todo return this to .stringValue() once LatLonPoint implements it
|
|
|
|
|
|
+ geohashes.add(spare.geohash());
|
|
|
|
+ } else if (field instanceof LatLonPoint || field instanceof LatLonDocValuesField) {
|
|
spare.resetFromIndexableField(field);
|
|
spare.resetFromIndexableField(field);
|
|
|
|
+ geohashes.add(spare.geohash());
|
|
}
|
|
}
|
|
- geohashes.add(spare.geohash());
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -279,6 +287,32 @@ public class GeoContextMapping extends ContextMapping<GeoQueryContext> {
|
|
return internalQueryContextList;
|
|
return internalQueryContextList;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ protected void validateReferences(Version indexVersionCreated, Function<String, MappedFieldType> fieldResolver) {
|
|
|
|
+ if (fieldName != null) {
|
|
|
|
+ MappedFieldType mappedFieldType = fieldResolver.apply(fieldName);
|
|
|
|
+ if (mappedFieldType == null) {
|
|
|
|
+ if (indexVersionCreated.before(Version.V_7_0_0_alpha1)) {
|
|
|
|
+ DEPRECATION_LOGGER.deprecatedAndMaybeLog("geo_context_mapping",
|
|
|
|
+ "field [{}] referenced in context [{}] is not defined in the mapping", fieldName, name);
|
|
|
|
+ } else {
|
|
|
|
+ throw new ElasticsearchParseException(
|
|
|
|
+ "field [{}] referenced in context [{}] is not defined in the mapping", fieldName, name);
|
|
|
|
+ }
|
|
|
|
+ } else if (GeoPointFieldMapper.CONTENT_TYPE.equals(mappedFieldType.typeName()) == false) {
|
|
|
|
+ if (indexVersionCreated.before(Version.V_7_0_0_alpha1)) {
|
|
|
|
+ DEPRECATION_LOGGER.deprecatedAndMaybeLog("geo_context_mapping",
|
|
|
|
+ "field [{}] referenced in context [{}] must be mapped to geo_point, found [{}]",
|
|
|
|
+ fieldName, name, mappedFieldType.typeName());
|
|
|
|
+ } else {
|
|
|
|
+ throw new ElasticsearchParseException(
|
|
|
|
+ "field [{}] referenced in context [{}] must be mapped to geo_point, found [{}]",
|
|
|
|
+ fieldName, name, mappedFieldType.typeName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
public boolean equals(Object o) {
|
|
if (this == o) return true;
|
|
if (this == o) return true;
|