Added ignore_malformed mapping parameter for all number like types. Issue #2120
This commit is contained in:
parent
08ba05e713
commit
0e3c825501
|
@ -74,7 +74,8 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
@Override
|
||||
public ByteFieldMapper build(BuilderContext context) {
|
||||
ByteFieldMapper fieldMapper = new ByteFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue);
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms,
|
||||
omitTermFreqAndPositions, nullValue, ignoreMalformed);
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
}
|
||||
|
@ -102,9 +103,9 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
|
||||
protected ByteFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, boolean omitTermFreqAndPositions,
|
||||
Byte nullValue) {
|
||||
Byte nullValue, boolean ignoreMalformed) {
|
||||
super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions,
|
||||
new NamedAnalyzer("_byte/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)),
|
||||
ignoreMalformed, new NamedAnalyzer("_byte/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_byte/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
this.nullValueAsString = nullValue == null ? null : nullValue.toString();
|
||||
|
@ -214,7 +215,7 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
byte value;
|
||||
float boost = this.boost;
|
||||
if (context.externalValueSet()) {
|
||||
|
|
|
@ -102,7 +102,8 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
parseUpperInclusive = context.indexSettings().getAsBoolean("index.mapping.date.parse_upper_inclusive", Defaults.PARSE_UPPER_INCLUSIVE);
|
||||
}
|
||||
DateFieldMapper fieldMapper = new DateFieldMapper(buildNames(context), dateTimeFormatter,
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue, timeUnit, parseUpperInclusive);
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue,
|
||||
timeUnit, parseUpperInclusive, ignoreMalformed);
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
}
|
||||
|
@ -141,9 +142,10 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
protected DateFieldMapper(Names names, FormatDateTimeFormatter dateTimeFormatter, int precisionStep, String fuzzyFactor,
|
||||
Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, boolean omitTermFreqAndPositions,
|
||||
String nullValue, TimeUnit timeUnit, boolean parseUpperInclusive) {
|
||||
String nullValue, TimeUnit timeUnit, boolean parseUpperInclusive, boolean ignoreMalformed) {
|
||||
super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions,
|
||||
new NamedAnalyzer("_date/" + precisionStep, new NumericDateAnalyzer(precisionStep, dateTimeFormatter.parser())),
|
||||
ignoreMalformed, new NamedAnalyzer("_date/" + precisionStep,
|
||||
new NumericDateAnalyzer(precisionStep, dateTimeFormatter.parser())),
|
||||
new NamedAnalyzer("_date/max", new NumericDateAnalyzer(Integer.MAX_VALUE, dateTimeFormatter.parser())));
|
||||
this.dateTimeFormatter = dateTimeFormatter;
|
||||
this.nullValue = nullValue;
|
||||
|
@ -293,7 +295,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
String dateAsString = null;
|
||||
Long value = null;
|
||||
float boost = this.boost;
|
||||
|
|
|
@ -74,7 +74,8 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
@Override
|
||||
public DoubleFieldMapper build(BuilderContext context) {
|
||||
DoubleFieldMapper fieldMapper = new DoubleFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue);
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue,
|
||||
ignoreMalformed);
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
}
|
||||
|
@ -104,9 +105,9 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
protected DoubleFieldMapper(Names names, int precisionStep, String fuzzyFactor,
|
||||
Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, boolean omitTermFreqAndPositions,
|
||||
Double nullValue) {
|
||||
Double nullValue, boolean ignoreMalformed) {
|
||||
super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions,
|
||||
new NamedAnalyzer("_double/" + precisionStep, new NumericDoubleAnalyzer(precisionStep)),
|
||||
ignoreMalformed, new NamedAnalyzer("_double/" + precisionStep, new NumericDoubleAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_double/max", new NumericDoubleAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
this.nullValueAsString = nullValue == null ? null : nullValue.toString();
|
||||
|
@ -215,7 +216,7 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
double value;
|
||||
float boost = this.boost;
|
||||
if (context.externalValueSet()) {
|
||||
|
|
|
@ -75,7 +75,8 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
@Override
|
||||
public FloatFieldMapper build(BuilderContext context) {
|
||||
FloatFieldMapper fieldMapper = new FloatFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue);
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue,
|
||||
ignoreMalformed);
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
}
|
||||
|
@ -103,9 +104,9 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
|
||||
protected FloatFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, boolean omitTermFreqAndPositions,
|
||||
Float nullValue) {
|
||||
Float nullValue, boolean ignoreMalformed) {
|
||||
super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions,
|
||||
new NamedAnalyzer("_float/" + precisionStep, new NumericFloatAnalyzer(precisionStep)),
|
||||
ignoreMalformed, new NamedAnalyzer("_float/" + precisionStep, new NumericFloatAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_float/max", new NumericFloatAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
this.nullValueAsString = nullValue == null ? null : nullValue.toString();
|
||||
|
@ -210,7 +211,7 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
float value;
|
||||
float boost = this.boost;
|
||||
if (context.externalValueSet()) {
|
||||
|
|
|
@ -75,7 +75,8 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
@Override
|
||||
public IntegerFieldMapper build(BuilderContext context) {
|
||||
IntegerFieldMapper fieldMapper = new IntegerFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue);
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions,
|
||||
nullValue, ignoreMalformed);
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
}
|
||||
|
@ -103,9 +104,9 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
|
||||
protected IntegerFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, boolean omitTermFreqAndPositions,
|
||||
Integer nullValue) {
|
||||
Integer nullValue, boolean ignoreMalformed) {
|
||||
super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions,
|
||||
new NamedAnalyzer("_int/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)),
|
||||
ignoreMalformed, new NamedAnalyzer("_int/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_int/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
this.nullValueAsString = nullValue == null ? null : nullValue.toString();
|
||||
|
@ -215,7 +216,7 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
int value;
|
||||
float boost = this.boost;
|
||||
if (context.externalValueSet()) {
|
||||
|
|
|
@ -75,7 +75,8 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
@Override
|
||||
public LongFieldMapper build(BuilderContext context) {
|
||||
LongFieldMapper fieldMapper = new LongFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue);
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue,
|
||||
ignoreMalformed);
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
}
|
||||
|
@ -103,9 +104,9 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
|
||||
protected LongFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, boolean omitTermFreqAndPositions,
|
||||
Long nullValue) {
|
||||
Long nullValue, boolean ignoreMalformed) {
|
||||
super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions,
|
||||
new NamedAnalyzer("_long/" + precisionStep, new NumericLongAnalyzer(precisionStep)),
|
||||
ignoreMalformed, new NamedAnalyzer("_long/" + precisionStep, new NumericLongAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_long/max", new NumericLongAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
this.nullValueAsString = nullValue == null ? null : nullValue.toString();
|
||||
|
@ -215,7 +216,7 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
long value;
|
||||
float boost = this.boost;
|
||||
if (context.externalValueSet()) {
|
||||
|
|
|
@ -28,15 +28,15 @@ import org.apache.lucene.search.Filter;
|
|||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.index.analysis.NamedAnalyzer;
|
||||
import org.elasticsearch.index.cache.field.data.FieldDataCache;
|
||||
import org.elasticsearch.index.field.data.FieldDataType;
|
||||
import org.elasticsearch.index.mapper.Mapper;
|
||||
import org.elasticsearch.index.mapper.MergeContext;
|
||||
import org.elasticsearch.index.mapper.MergeMappingException;
|
||||
import org.elasticsearch.index.mapper.*;
|
||||
import org.elasticsearch.index.mapper.internal.AllFieldMapper;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
/**
|
||||
|
@ -50,6 +50,7 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
public static final boolean OMIT_NORMS = true;
|
||||
public static final boolean OMIT_TERM_FREQ_AND_POSITIONS = true;
|
||||
public static final String FUZZY_FACTOR = null;
|
||||
public static final boolean IGNORE_MALFORMED = false;
|
||||
}
|
||||
|
||||
public abstract static class Builder<T extends Builder, Y extends NumberFieldMapper> extends AbstractFieldMapper.Builder<T, Y> {
|
||||
|
@ -58,6 +59,8 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
|
||||
protected String fuzzyFactor = Defaults.FUZZY_FACTOR;
|
||||
|
||||
protected boolean ignoreMalformed = Defaults.IGNORE_MALFORMED;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
this.index = Defaults.INDEX;
|
||||
|
@ -94,6 +97,12 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
this.fuzzyFactor = fuzzyFactor;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public T ignoreMalformed(boolean ignoreMalformed) {
|
||||
this.ignoreMalformed = ignoreMalformed;
|
||||
return builder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected int precisionStep;
|
||||
|
@ -104,6 +113,8 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
|
||||
protected Boolean includeInAll;
|
||||
|
||||
protected boolean ignoreMalformed;
|
||||
|
||||
private ThreadLocal<NumericTokenStream> tokenStream = new ThreadLocal<NumericTokenStream>() {
|
||||
@Override
|
||||
protected NumericTokenStream initialValue() {
|
||||
|
@ -114,7 +125,7 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
protected NumberFieldMapper(Names names, int precisionStep, @Nullable String fuzzyFactor,
|
||||
Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, boolean omitTermFreqAndPositions,
|
||||
NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) {
|
||||
boolean ignoreMalformed, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) {
|
||||
super(names, index, store, Field.TermVector.NO, boost, boost != 1.0f || omitNorms, omitTermFreqAndPositions, indexAnalyzer, searchAnalyzer);
|
||||
if (precisionStep <= 0 || precisionStep >= maxPrecisionStep()) {
|
||||
this.precisionStep = Integer.MAX_VALUE;
|
||||
|
@ -123,6 +134,7 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
}
|
||||
this.fuzzyFactor = fuzzyFactor;
|
||||
this.dFuzzyFactor = parseFuzzyFactor(fuzzyFactor);
|
||||
this.ignoreMalformed = ignoreMalformed;
|
||||
}
|
||||
|
||||
protected double parseFuzzyFactor(String fuzzyFactor) {
|
||||
|
@ -152,6 +164,26 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
return this.precisionStep;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
RuntimeException e;
|
||||
try {
|
||||
return innerParseCreateField(context);
|
||||
} catch (IllegalArgumentException e1) {
|
||||
e = e1;
|
||||
} catch (MapperParsingException e2) {
|
||||
e = e2;
|
||||
}
|
||||
|
||||
if (ignoreMalformed) {
|
||||
return null;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Fieldable innerParseCreateField(ParseContext context) throws IOException;
|
||||
|
||||
/**
|
||||
* Use the field query created here when matching on numbers.
|
||||
*/
|
||||
|
@ -216,10 +248,12 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
return;
|
||||
}
|
||||
if (!mergeContext.mergeFlags().simulate()) {
|
||||
this.precisionStep = ((NumberFieldMapper) mergeWith).precisionStep;
|
||||
this.includeInAll = ((NumberFieldMapper) mergeWith).includeInAll;
|
||||
this.fuzzyFactor = ((NumberFieldMapper) mergeWith).fuzzyFactor;
|
||||
this.dFuzzyFactor = parseFuzzyFactor(this.fuzzyFactor);
|
||||
NumberFieldMapper nfmMergeWith = (NumberFieldMapper) mergeWith;
|
||||
this.precisionStep = nfmMergeWith.precisionStep;
|
||||
this.includeInAll = nfmMergeWith.includeInAll;
|
||||
this.fuzzyFactor = nfmMergeWith.fuzzyFactor;
|
||||
this.dFuzzyFactor = parseFuzzyFactor(nfmMergeWith.fuzzyFactor);
|
||||
this.ignoreMalformed = nfmMergeWith.ignoreMalformed;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -272,4 +306,10 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
|
||||
public abstract String numericAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doXContentBody(XContentBuilder builder) throws IOException {
|
||||
super.doXContentBody(builder);
|
||||
builder.field("ignore_malformed", ignoreMalformed);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,8 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
@Override
|
||||
public ShortFieldMapper build(BuilderContext context) {
|
||||
ShortFieldMapper fieldMapper = new ShortFieldMapper(buildNames(context),
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue);
|
||||
precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions, nullValue,
|
||||
ignoreMalformed);
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
}
|
||||
|
@ -103,9 +104,9 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
|
||||
protected ShortFieldMapper(Names names, int precisionStep, String fuzzyFactor, Field.Index index, Field.Store store,
|
||||
float boost, boolean omitNorms, boolean omitTermFreqAndPositions,
|
||||
Short nullValue) {
|
||||
Short nullValue, boolean ignoreMalformed) {
|
||||
super(names, precisionStep, fuzzyFactor, index, store, boost, omitNorms, omitTermFreqAndPositions,
|
||||
new NamedAnalyzer("_short/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)),
|
||||
ignoreMalformed, new NamedAnalyzer("_short/" + precisionStep, new NumericIntegerAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_short/max", new NumericIntegerAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
this.nullValueAsString = nullValue == null ? null : nullValue.toString();
|
||||
|
@ -215,7 +216,7 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
short value;
|
||||
float boost = this.boost;
|
||||
if (context.externalValueSet()) {
|
||||
|
|
|
@ -46,6 +46,8 @@ public class TypeParsers {
|
|||
builder.precisionStep(nodeIntegerValue(propNode));
|
||||
} else if (propName.equals("fuzzy_factor")) {
|
||||
builder.fuzzyFactor(propNode.toString());
|
||||
} else if (propName.equals("ignore_malformed")) {
|
||||
builder.ignoreMalformed(nodeBooleanValue(propNode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ public class BoostFieldMapper extends NumberFieldMapper<Float> implements Intern
|
|||
float boost, boolean omitNorms, boolean omitTermFreqAndPositions,
|
||||
Float nullValue) {
|
||||
super(new Names(name, indexName, indexName, name), precisionStep, null, index, store, boost, omitNorms, omitTermFreqAndPositions,
|
||||
new NamedAnalyzer("_float/" + precisionStep, new NumericFloatAnalyzer(precisionStep)),
|
||||
false, new NamedAnalyzer("_float/" + precisionStep, new NumericFloatAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_float/max", new NumericFloatAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ public class BoostFieldMapper extends NumberFieldMapper<Float> implements Intern
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
final float value = parseFloatValue(context);
|
||||
if (Float.isNaN(value)) {
|
||||
return null;
|
||||
|
|
|
@ -93,7 +93,9 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
|
|||
}
|
||||
|
||||
public SizeFieldMapper(boolean enabled, Field.Store store) {
|
||||
super(new Names(Defaults.NAME), Defaults.PRECISION_STEP, Defaults.FUZZY_FACTOR, Defaults.INDEX, store, Defaults.BOOST, Defaults.OMIT_NORMS, Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Defaults.NULL_VALUE);
|
||||
super(new Names(Defaults.NAME), Defaults.PRECISION_STEP, Defaults.FUZZY_FACTOR, Defaults.INDEX, store,
|
||||
Defaults.BOOST, Defaults.OMIT_NORMS, Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Defaults.NULL_VALUE,
|
||||
Defaults.IGNORE_MALFORMED);
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
|
@ -131,7 +133,7 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
if (!enabled) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R
|
|||
protected TTLFieldMapper(Field.Store store, Field.Index index, boolean enabled, long defaultTTL) {
|
||||
super(new Names(Defaults.NAME, Defaults.NAME, Defaults.NAME, Defaults.NAME), Defaults.PRECISION_STEP,
|
||||
Defaults.FUZZY_FACTOR, index, store, Defaults.BOOST, Defaults.OMIT_NORMS,
|
||||
Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Defaults.NULL_VALUE);
|
||||
Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Defaults.NULL_VALUE, Defaults.IGNORE_MALFORMED);
|
||||
this.enabled = enabled;
|
||||
this.defaultTTL = defaultTTL;
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ public class TTLFieldMapper extends LongFieldMapper implements InternalMapper, R
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException, AlreadyExpiredException {
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException, AlreadyExpiredException {
|
||||
if (enabled) {
|
||||
long ttl = context.sourceToParse().ttl();
|
||||
if (ttl <= 0 && defaultTTL > 0) { // no ttl provided so we use the default value
|
||||
|
|
|
@ -125,7 +125,8 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
|
|||
protected TimestampFieldMapper(Field.Store store, Field.Index index, boolean enabled, String path, FormatDateTimeFormatter dateTimeFormatter, boolean parseUpperInclusive) {
|
||||
super(new Names(Defaults.NAME, Defaults.NAME, Defaults.NAME, Defaults.NAME), dateTimeFormatter,
|
||||
Defaults.PRECISION_STEP, Defaults.FUZZY_FACTOR, index, store, Defaults.BOOST, Defaults.OMIT_NORMS,
|
||||
Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Defaults.NULL_VALUE, TimeUnit.MILLISECONDS /*always milliseconds*/, parseUpperInclusive);
|
||||
Defaults.OMIT_TERM_FREQ_AND_POSITIONS, Defaults.NULL_VALUE, TimeUnit.MILLISECONDS /*always milliseconds*/,
|
||||
parseUpperInclusive, Defaults.IGNORE_MALFORMED);
|
||||
this.enabled = enabled;
|
||||
this.path = path;
|
||||
}
|
||||
|
@ -183,7 +184,7 @@ public class TimestampFieldMapper extends DateFieldMapper implements InternalMap
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
if (enabled) {
|
||||
long timestamp = context.sourceToParse().timestamp();
|
||||
if (!indexed() && !stored()) {
|
||||
|
|
|
@ -132,7 +132,7 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
|
|||
float boost, boolean omitNorms, boolean omitTermFreqAndPositions,
|
||||
String nullValue) {
|
||||
super(names, precisionStep, null, index, store, boost, omitNorms, omitTermFreqAndPositions,
|
||||
new NamedAnalyzer("_ip/" + precisionStep, new NumericIpAnalyzer(precisionStep)),
|
||||
false, new NamedAnalyzer("_ip/" + precisionStep, new NumericIpAnalyzer(precisionStep)),
|
||||
new NamedAnalyzer("_ip/max", new NumericIpAnalyzer(Integer.MAX_VALUE)));
|
||||
this.nullValue = nullValue;
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
protected Fieldable innerParseCreateField(ParseContext context) throws IOException {
|
||||
String ipAsString;
|
||||
if (context.externalValueSet()) {
|
||||
ipAsString = (String) context.externalValue();
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.test.unit.index.mapper.numeric;
|
|||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||
import org.elasticsearch.index.mapper.core.DoubleFieldMapper;
|
||||
import org.elasticsearch.index.mapper.core.LongFieldMapper;
|
||||
|
@ -30,7 +31,7 @@ import org.elasticsearch.test.unit.index.mapper.MapperTests;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -77,4 +78,47 @@ public class SimpleNumericTests {
|
|||
mapper = defaultMapper.mappers().smartNameFieldMapper("s_double");
|
||||
assertThat(mapper, instanceOf(StringFieldMapper.class));
|
||||
}
|
||||
|
||||
public void testIgnoreMalformedEnabled() throws Exception {
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||
.startObject("properties")
|
||||
.startObject("field1").field("type", "integer").field("ignore_malformed", true).endObject()
|
||||
.startObject("field2").field("type", "integer").field("ignore_malformed", false).endObject()
|
||||
.startObject("field3").field("type", "integer").endObject()
|
||||
.endObject()
|
||||
.endObject().endObject().string();
|
||||
|
||||
DocumentMapper defaultMapper = MapperTests.newParser().parse(mapping);
|
||||
|
||||
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field1", "a")
|
||||
.field("field2", "1")
|
||||
.endObject()
|
||||
.bytes());
|
||||
assertThat(doc.rootDoc().getFieldable("field1"), nullValue());
|
||||
assertThat(doc.rootDoc().getFieldable("field2"), notNullValue());
|
||||
|
||||
try {
|
||||
defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field2", "a")
|
||||
.endObject()
|
||||
.bytes());
|
||||
} catch (MapperParsingException e) {
|
||||
assertThat(e.getCause(), instanceOf(NumberFormatException.class));
|
||||
}
|
||||
|
||||
// Verify that the default is false
|
||||
try {
|
||||
defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("field3", "a")
|
||||
.endObject()
|
||||
.bytes());
|
||||
} catch (MapperParsingException e) {
|
||||
assertThat(e.getCause(), instanceOf(NumberFormatException.class));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue