|
@@ -21,7 +21,6 @@ package org.elasticsearch.index.mapper;
|
|
|
import org.apache.lucene.index.IndexOptions;
|
|
|
import org.apache.lucene.index.IndexableField;
|
|
|
import org.apache.lucene.index.Term;
|
|
|
-import org.apache.lucene.search.DocValuesFieldExistsQuery;
|
|
|
import org.apache.lucene.search.Query;
|
|
|
import org.apache.lucene.search.TermQuery;
|
|
|
import org.apache.lucene.spatial.prefix.PrefixTreeStrategy;
|
|
@@ -54,6 +53,8 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
+import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.IGNORE_MALFORMED;
|
|
|
+
|
|
|
/**
|
|
|
* FieldMapper for indexing {@link org.locationtech.spatial4j.shape.Shape}s.
|
|
|
* <p>
|
|
@@ -96,6 +97,7 @@ public class GeoShapeFieldMapper extends FieldMapper {
|
|
|
public static final Orientation ORIENTATION = Orientation.RIGHT;
|
|
|
public static final double LEGACY_DISTANCE_ERROR_PCT = 0.025d;
|
|
|
public static final Explicit<Boolean> COERCE = new Explicit<>(false, false);
|
|
|
+ public static final Explicit<Boolean> IGNORE_MALFORMED = new Explicit<>(false, false);
|
|
|
|
|
|
public static final MappedFieldType FIELD_TYPE = new GeoShapeFieldType();
|
|
|
|
|
@@ -115,6 +117,7 @@ public class GeoShapeFieldMapper extends FieldMapper {
|
|
|
public static class Builder extends FieldMapper.Builder<Builder, GeoShapeFieldMapper> {
|
|
|
|
|
|
private Boolean coerce;
|
|
|
+ private Boolean ignoreMalformed;
|
|
|
|
|
|
public Builder(String name) {
|
|
|
super(name, Defaults.FIELD_TYPE, Defaults.FIELD_TYPE);
|
|
@@ -145,6 +148,21 @@ public class GeoShapeFieldMapper extends FieldMapper {
|
|
|
return Defaults.COERCE;
|
|
|
}
|
|
|
|
|
|
+ public Builder ignoreMalformed(boolean ignoreMalformed) {
|
|
|
+ this.ignoreMalformed = ignoreMalformed;
|
|
|
+ return builder;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Explicit<Boolean> ignoreMalformed(BuilderContext context) {
|
|
|
+ if (ignoreMalformed != null) {
|
|
|
+ return new Explicit<>(ignoreMalformed, true);
|
|
|
+ }
|
|
|
+ if (context.indexSettings() != null) {
|
|
|
+ return new Explicit<>(IGNORE_MALFORMED_SETTING.get(context.indexSettings()), false);
|
|
|
+ }
|
|
|
+ return Defaults.IGNORE_MALFORMED;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public GeoShapeFieldMapper build(BuilderContext context) {
|
|
|
GeoShapeFieldType geoShapeFieldType = (GeoShapeFieldType)fieldType;
|
|
@@ -154,8 +172,8 @@ public class GeoShapeFieldMapper extends FieldMapper {
|
|
|
}
|
|
|
setupFieldType(context);
|
|
|
|
|
|
- return new GeoShapeFieldMapper(name, fieldType, coerce(context), context.indexSettings(), multiFieldsBuilder.build(this,
|
|
|
- context), copyTo);
|
|
|
+ return new GeoShapeFieldMapper(name, fieldType, ignoreMalformed(context), coerce(context), context.indexSettings(),
|
|
|
+ multiFieldsBuilder.build(this, context), copyTo);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -186,6 +204,9 @@ public class GeoShapeFieldMapper extends FieldMapper {
|
|
|
} else if (Names.STRATEGY.equals(fieldName)) {
|
|
|
builder.fieldType().setStrategyName(fieldNode.toString());
|
|
|
iterator.remove();
|
|
|
+ } else if (IGNORE_MALFORMED.equals(fieldName)) {
|
|
|
+ builder.ignoreMalformed(TypeParsers.nodeBooleanValue(fieldName, "ignore_malformed", fieldNode, parserContext));
|
|
|
+ iterator.remove();
|
|
|
} else if (Names.COERCE.equals(fieldName)) {
|
|
|
builder.coerce(TypeParsers.nodeBooleanValue(fieldName, Names.COERCE, fieldNode, parserContext));
|
|
|
iterator.remove();
|
|
@@ -428,11 +449,13 @@ public class GeoShapeFieldMapper extends FieldMapper {
|
|
|
}
|
|
|
|
|
|
protected Explicit<Boolean> coerce;
|
|
|
+ protected Explicit<Boolean> ignoreMalformed;
|
|
|
|
|
|
- public GeoShapeFieldMapper(String simpleName, MappedFieldType fieldType, Explicit<Boolean> coerce, Settings indexSettings,
|
|
|
- MultiFields multiFields, CopyTo copyTo) {
|
|
|
+ public GeoShapeFieldMapper(String simpleName, MappedFieldType fieldType, Explicit<Boolean> ignoreMalformed,
|
|
|
+ Explicit<Boolean> coerce, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
|
|
|
super(simpleName, fieldType, Defaults.FIELD_TYPE, indexSettings, multiFields, copyTo);
|
|
|
this.coerce = coerce;
|
|
|
+ this.ignoreMalformed = ignoreMalformed;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -461,7 +484,9 @@ public class GeoShapeFieldMapper extends FieldMapper {
|
|
|
context.doc().add(field);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- throw new MapperParsingException("failed to parse [" + fieldType().name() + "]", e);
|
|
|
+ if (ignoreMalformed.value() == false) {
|
|
|
+ throw new MapperParsingException("failed to parse [" + fieldType().name() + "]", e);
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
@@ -478,6 +503,9 @@ public class GeoShapeFieldMapper extends FieldMapper {
|
|
|
if (gsfm.coerce.explicit()) {
|
|
|
this.coerce = gsfm.coerce;
|
|
|
}
|
|
|
+ if (gsfm.ignoreMalformed.explicit()) {
|
|
|
+ this.ignoreMalformed = gsfm.ignoreMalformed;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -506,7 +534,10 @@ public class GeoShapeFieldMapper extends FieldMapper {
|
|
|
builder.field(Names.STRATEGY_POINTS_ONLY, fieldType().pointsOnly());
|
|
|
}
|
|
|
if (includeDefaults || coerce.explicit()) {
|
|
|
- builder.field("coerce", coerce.value());
|
|
|
+ builder.field(Names.COERCE, coerce.value());
|
|
|
+ }
|
|
|
+ if (includeDefaults || ignoreMalformed.explicit()) {
|
|
|
+ builder.field(IGNORE_MALFORMED, ignoreMalformed.value());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -514,6 +545,10 @@ public class GeoShapeFieldMapper extends FieldMapper {
|
|
|
return coerce;
|
|
|
}
|
|
|
|
|
|
+ public Explicit<Boolean> ignoreMalformed() {
|
|
|
+ return ignoreMalformed;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected String contentType() {
|
|
|
return CONTENT_TYPE;
|