Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
import org.apache.lucene.search.Query;
import org.elasticsearch.common.Explicit;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.fielddata.FieldData;
import org.elasticsearch.index.fielddata.FieldDataContext;
Expand Down Expand Up @@ -133,46 +131,24 @@ public static class Builder extends FieldMapper.Builder {
*/
private final Parameter<TimeSeriesParams.MetricType> metric;

private final IndexMode indexMode;
private final IndexVersion indexCreatedVersion;
private final SourceKeepMode indexSourceKeepMode;

public Builder(
String name,
Settings settings,
IndexMode indexMode,
IndexVersion indexCreatedVersion,
SourceKeepMode indexSourceKeepMode
) {
this(
name,
IGNORE_MALFORMED_SETTING.get(settings),
COERCE_SETTING.get(settings),
indexMode,
indexCreatedVersion,
indexSourceKeepMode
);
}
private final IndexSettings indexSettings;

public Builder(
String name,
boolean ignoreMalformedByDefault,
boolean coerceByDefault,
IndexMode indexMode,
IndexVersion indexCreatedVersion,
SourceKeepMode indexSourceKeepMode
) {
public Builder(String name, IndexSettings indexSettings) {
super(name);
this.ignoreMalformed = Parameter.explicitBoolParam(
"ignore_malformed",
true,
m -> toType(m).ignoreMalformed,
ignoreMalformedByDefault
IGNORE_MALFORMED_SETTING.get(indexSettings.getSettings())
);
this.coerce = Parameter.explicitBoolParam(
"coerce",
true,
m -> toType(m).coerce,
COERCE_SETTING.get(indexSettings.getSettings())
);
this.coerce = Parameter.explicitBoolParam("coerce", true, m -> toType(m).coerce, coerceByDefault);
this.indexMode = indexMode;
this.indexed = Parameter.indexParam(m -> toType(m).indexed, () -> {
if (indexMode == IndexMode.TIME_SERIES) {
if (indexSettings.getMode() == IndexMode.TIME_SERIES) {
var metricType = getMetric().getValue();
return metricType != TimeSeriesParams.MetricType.COUNTER && metricType != TimeSeriesParams.MetricType.GAUGE;
} else {
Expand All @@ -190,8 +166,7 @@ public Builder(
);
}
});
this.indexCreatedVersion = indexCreatedVersion;
this.indexSourceKeepMode = indexSourceKeepMode;
this.indexSettings = indexSettings;
}

Builder scalingFactor(double scalingFactor) {
Expand Down Expand Up @@ -229,17 +204,17 @@ public ScaledFloatFieldMapper build(MapperBuilderContext context) {
scalingFactor.getValue(),
nullValue.getValue(),
metric.getValue(),
indexMode,
indexSettings.getMode(),
coerce.getValue().value(),
context.isSourceSynthetic()
);
String offsetsFieldName = getOffsetsFieldName(
context,
indexSourceKeepMode,
indexSettings.sourceKeepMode(),
hasDocValues.getValue(),
stored.getValue(),
this,
indexCreatedVersion,
indexSettings.getIndexVersionCreated(),
IndexVersions.SYNTHETIC_SOURCE_STORE_ARRAYS_NATIVELY_SCALED_FLOAT
);
return new ScaledFloatFieldMapper(
Expand All @@ -253,15 +228,7 @@ public ScaledFloatFieldMapper build(MapperBuilderContext context) {
}
}

public static final TypeParser PARSER = new TypeParser(
(n, c) -> new Builder(
n,
c.getSettings(),
c.getIndexSettings().getMode(),
c.indexVersionCreated(),
c.getIndexSettings().sourceKeepMode()
)
);
public static final TypeParser PARSER = new TypeParser((n, c) -> new Builder(n, c.getIndexSettings()));

public static final class ScaledFloatFieldType extends SimpleMappedFieldType {

Expand Down Expand Up @@ -595,15 +562,10 @@ public String toString() {
private final Double nullValue;
private final double scalingFactor;
private final boolean isSourceSynthetic;

private final boolean ignoreMalformedByDefault;
private final boolean coerceByDefault;
private final TimeSeriesParams.MetricType metricType;
private final IndexMode indexMode;

private final IndexVersion indexCreatedVersion;
private final String offsetsFieldName;
private final SourceKeepMode indexSourceKeepMode;

private final IndexSettings indexSettings;

private ScaledFloatFieldMapper(
String simpleName,
Expand All @@ -622,13 +584,9 @@ private ScaledFloatFieldMapper(
this.nullValue = builder.nullValue.getValue();
this.ignoreMalformed = builder.ignoreMalformed.getValue();
this.coerce = builder.coerce.getValue();
this.ignoreMalformedByDefault = builder.ignoreMalformed.getDefaultValue().value();
this.coerceByDefault = builder.coerce.getDefaultValue().value();
this.indexSettings = builder.indexSettings;
this.metricType = builder.metric.getValue();
this.indexMode = builder.indexMode;
this.indexCreatedVersion = builder.indexCreatedVersion;
this.offsetsFieldName = offsetsFieldName;
this.indexSourceKeepMode = builder.indexSourceKeepMode;
}

boolean coerce() {
Expand Down Expand Up @@ -657,9 +615,7 @@ protected String contentType() {

@Override
public FieldMapper.Builder getMergeBuilder() {
return new Builder(leafName(), ignoreMalformedByDefault, coerceByDefault, indexMode, indexCreatedVersion, indexSourceKeepMode)
.metric(metricType)
.init(this);
return new Builder(leafName(), indexSettings).metric(metricType).init(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ public void testFieldData() throws IOException {
}

public void testFetchSourceValue() throws IOException {
MappedFieldType mapper = new ScaledFloatFieldMapper.Builder("field", false, false, null, null, null).scalingFactor(100)
MappedFieldType mapper = new ScaledFloatFieldMapper.Builder("field", defaultIndexSettings()).scalingFactor(100)
.build(MapperBuilderContext.root(false, false))
.fieldType();
assertEquals(List.of(3.14), fetchSourceValue(mapper, 3.1415926));
assertEquals(List.of(3.14), fetchSourceValue(mapper, "3.1415"));
assertEquals(List.of(), fetchSourceValue(mapper, ""));

MappedFieldType nullValueMapper = new ScaledFloatFieldMapper.Builder("field", false, false, null, null, null).scalingFactor(100)
MappedFieldType nullValueMapper = new ScaledFloatFieldMapper.Builder("field", defaultIndexSettings()).scalingFactor(100)
.nullValue(2.71)
.build(MapperBuilderContext.root(false, false))
.fieldType();
Expand Down