Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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 @@ -79,7 +79,7 @@ public class ScriptScoreBenchmark {
private final ScriptModule scriptModule = new ScriptModule(Settings.EMPTY, pluginsService.filterPlugins(ScriptPlugin.class));

private final Map<String, MappedFieldType> fieldTypes = Map.ofEntries(
Map.entry("n", new NumberFieldType("n", NumberType.LONG, false, false, true, true, null, Map.of(), null))
Map.entry("n", new NumberFieldType("n", NumberType.LONG, false, false, true, true, null, Map.of(), null, false))
);
private final IndexFieldDataCache fieldDataCache = new IndexFieldDataCache.None();
private final CircuitBreakerService breakerService = new NoneCircuitBreakerService();
Expand Down
1 change: 0 additions & 1 deletion docs/reference/mapping/types/keyword.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,3 @@ The following parameters are accepted by `keyword` fields:
include::constant-keyword.asciidoc[]

include::wildcard.asciidoc[]

Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static class TokenCountFieldType extends NumberFieldMapper.NumberFieldType {

TokenCountFieldType(String name, boolean isSearchable, boolean isStored,
boolean hasDocValues, Number nullValue, Map<String, String> meta) {
super(name, NumberFieldMapper.NumberType.INTEGER, isSearchable, isStored, hasDocValues, false, nullValue, meta, null);
super(name, NumberFieldMapper.NumberType.INTEGER, isSearchable, isStored, hasDocValues, false, nullValue, meta, null, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public static class Builder extends FieldMapper.Builder {
private final Parameter<String> onScriptError = Parameter.onScriptErrorParam(m -> toType(m).onScriptError, script);

private final Parameter<Map<String, String>> meta = Parameter.metaParam();
private final Parameter<Boolean> dimension
= Parameter.boolParam("dimension", false, m -> toType(m).dimension, false);

private final boolean ignoreMalformedByDefault;
private final Version indexCreatedVersion;
Expand All @@ -93,6 +95,11 @@ Builder nullValue(String nullValue) {
return this;
}

public Builder dimension(boolean dimension) {
this.dimension.setValue(dimension);
return this;
}

private InetAddress parseNullValue() {
String nullValueAsString = nullValue.getValue();
if (nullValueAsString == null) {
Expand Down Expand Up @@ -124,14 +131,14 @@ private FieldValues<InetAddress> scriptValues() {

@Override
protected List<Parameter<?>> getParameters() {
return List.of(indexed, hasDocValues, stored, ignoreMalformed, nullValue, script, onScriptError, meta);
return List.of(indexed, hasDocValues, stored, ignoreMalformed, nullValue, script, onScriptError, meta, dimension);
}

@Override
public IpFieldMapper build(ContentPath contentPath) {
return new IpFieldMapper(name,
new IpFieldType(buildFullName(contentPath), indexed.getValue(), stored.getValue(),
hasDocValues.getValue(), parseNullValue(), scriptValues(), meta.getValue()),
hasDocValues.getValue(), parseNullValue(), scriptValues(), meta.getValue(), dimension.getValue()),
multiFieldsBuilder.build(this, contentPath), copyTo.build(), this);
}

Expand All @@ -146,16 +153,18 @@ public static final class IpFieldType extends SimpleMappedFieldType {

private final InetAddress nullValue;
private final FieldValues<InetAddress> scriptValues;
private final boolean isDimension;

public IpFieldType(String name, boolean indexed, boolean stored, boolean hasDocValues,
InetAddress nullValue, FieldValues<InetAddress> scriptValues, Map<String, String> meta) {
InetAddress nullValue, FieldValues<InetAddress> scriptValues, Map<String, String> meta, boolean isDimension) {
super(name, indexed, stored, hasDocValues, TextSearchInfo.SIMPLE_MATCH_WITHOUT_TERMS, meta);
this.nullValue = nullValue;
this.scriptValues = scriptValues;
this.isDimension = isDimension;
}

public IpFieldType(String name) {
this(name, true, false, true, null, null, Collections.emptyMap());
this(name, true, false, true, null, null, Collections.emptyMap(), false);
}

@Override
Expand Down Expand Up @@ -364,12 +373,20 @@ public DocValueFormat docValueFormat(@Nullable String format, ZoneId timeZone) {
}
return DocValueFormat.IP;
}

/**
* @return true if field has been marked as a dimension field
*/
public boolean isDimension() {
return isDimension;
}
}

private final boolean indexed;
private final boolean hasDocValues;
private final boolean stored;
private final boolean ignoreMalformed;
private final boolean dimension;

private final InetAddress nullValue;
private final String nullValueAsString;
Expand Down Expand Up @@ -399,6 +416,7 @@ private IpFieldMapper(
this.script = builder.script.get();
this.scriptValues = builder.scriptValues();
this.scriptCompiler = builder.scriptCompiler;
this.dimension = builder.dimension.getValue();
}

boolean ignoreMalformed() {
Expand Down Expand Up @@ -468,7 +486,7 @@ protected void indexScriptValues(SearchLookup searchLookup, LeafReaderContext re

@Override
public FieldMapper.Builder getMergeBuilder() {
return new Builder(simpleName(), scriptCompiler, ignoreMalformedByDefault, indexCreatedVersion).init(this);
return new Builder(simpleName(), scriptCompiler, ignoreMalformedByDefault, indexCreatedVersion).dimension(dimension).init(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public static class Builder extends FieldMapper.Builder {

private final Parameter<Script> script = Parameter.scriptParam(m -> toType(m).script);
private final Parameter<String> onScriptError = Parameter.onScriptErrorParam(m -> toType(m).onScriptError, script);
private final Parameter<Boolean> dimension;

private final IndexAnalyzers indexAnalyzers;
private final ScriptCompiler scriptCompiler;
Expand All @@ -122,6 +123,13 @@ public Builder(String name, IndexAnalyzers indexAnalyzers, ScriptCompiler script
this.scriptCompiler = Objects.requireNonNull(scriptCompiler);
this.script.precludesParameters(nullValue);
addScriptValidation(script, indexed, hasDocValues);

this.dimension = Parameter.boolParam("dimension", false, m -> toType(m).dimension, false)
.setValidator(v -> {
if (v && ignoreAbove.getValue() < ignoreAbove.getDefaultValue()) {
throw new IllegalArgumentException("Field [ignore_above] cannot be set in conjunction with field [dimension]");
}
});
}

public Builder(String name) {
Expand All @@ -148,6 +156,11 @@ public Builder docValues(boolean hasDocValues) {
return this;
}

public Builder dimension(boolean dimension) {
this.dimension.setValue(dimension);
return this;
}

private FieldValues<String> scriptValues() {
if (script.get() == null) {
return null;
Expand All @@ -163,7 +176,7 @@ private FieldValues<String> scriptValues() {
protected List<Parameter<?>> getParameters() {
return List.of(indexed, hasDocValues, stored, nullValue, eagerGlobalOrdinals, ignoreAbove,
indexOptions, hasNorms, similarity, normalizer, splitQueriesOnWhitespace,
script, onScriptError, meta);
script, onScriptError, meta, dimension);
}

private KeywordFieldType buildFieldType(ContentPath contentPath, FieldType fieldType) {
Expand Down Expand Up @@ -209,6 +222,7 @@ public static final class KeywordFieldType extends StringFieldType {
private final NamedAnalyzer normalizer;
private final boolean eagerGlobalOrdinals;
private final FieldValues<String> scriptValues;
private final boolean isDimension;

public KeywordFieldType(String name, FieldType fieldType,
NamedAnalyzer normalizer, NamedAnalyzer searchAnalyzer, NamedAnalyzer quoteAnalyzer,
Expand All @@ -224,6 +238,7 @@ public KeywordFieldType(String name, FieldType fieldType,
this.ignoreAbove = builder.ignoreAbove.getValue();
this.nullValue = builder.nullValue.getValue();
this.scriptValues = builder.scriptValues();
this.isDimension = builder.dimension.getValue();
}

public KeywordFieldType(String name, boolean isSearchable, boolean hasDocValues, Map<String, String> meta) {
Expand All @@ -233,6 +248,7 @@ public KeywordFieldType(String name, boolean isSearchable, boolean hasDocValues,
this.nullValue = null;
this.eagerGlobalOrdinals = false;
this.scriptValues = null;
this.isDimension = false;
}

public KeywordFieldType(String name) {
Expand All @@ -249,6 +265,7 @@ public KeywordFieldType(String name, FieldType fieldType) {
this.nullValue = null;
this.eagerGlobalOrdinals = false;
this.scriptValues = null;
this.isDimension = false;
}

public KeywordFieldType(String name, NamedAnalyzer analyzer) {
Expand All @@ -258,6 +275,7 @@ public KeywordFieldType(String name, NamedAnalyzer analyzer) {
this.nullValue = null;
this.eagerGlobalOrdinals = false;
this.scriptValues = null;
this.isDimension = false;
}

@Override
Expand Down Expand Up @@ -410,6 +428,12 @@ public int ignoreAbove() {
return ignoreAbove;
}

/**
* @return true if field has been marked as a dimension field
*/
public boolean isDimension() {
return isDimension;
}
}

private final boolean indexed;
Expand All @@ -425,7 +449,7 @@ public int ignoreAbove() {
private final Script script;
private final FieldValues<String> scriptValues;
private final ScriptCompiler scriptCompiler;

private final boolean dimension;

private final IndexAnalyzers indexAnalyzers;

Expand All @@ -448,6 +472,7 @@ protected KeywordFieldMapper(String simpleName, FieldType fieldType, KeywordFiel
this.scriptValues = builder.scriptValues();
this.indexAnalyzers = builder.indexAnalyzers;
this.scriptCompiler = builder.scriptCompiler;
this.dimension = builder.dimension.getValue();
}

@Override
Expand Down Expand Up @@ -535,8 +560,7 @@ protected String contentType() {

@Override
public FieldMapper.Builder getMergeBuilder() {
return new Builder(simpleName(), indexAnalyzers, scriptCompiler).init(this);
return new Builder(simpleName(), indexAnalyzers, scriptCompiler).dimension(dimension).init(this);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -81,6 +82,8 @@ public static class Builder extends FieldMapper.Builder {

private final Parameter<Script> script = Parameter.scriptParam(m -> toType(m).builder.script.get());
private final Parameter<String> onScriptError = Parameter.onScriptErrorParam(m -> toType(m).onScriptError, script);
private final Parameter<Boolean> dimension;


private final Parameter<Map<String, String>> meta = Parameter.metaParam();

Expand All @@ -94,6 +97,7 @@ public Builder(String name, NumberType type, ScriptCompiler compiler, Settings s
public static Builder docValuesOnly(String name, NumberType type) {
Builder builder = new Builder(name, type, ScriptCompiler.NONE, false, false);
builder.indexed.setValue(false);
builder.dimension.setValue(false);
return builder;
}

Expand All @@ -109,6 +113,13 @@ public Builder(String name, NumberType type, ScriptCompiler compiler, boolean ig
this.nullValue = new Parameter<>("null_value", false, () -> null,
(n, c, o) -> o == null ? null : type.parse(o, false), m -> toType(m).nullValue).acceptsNull();

this.dimension = Parameter.boolParam("dimension", false, m -> toType(m).dimension, false)
.setValidator(v -> {
if (v && EnumSet.of(NumberType.INTEGER, NumberType.LONG, NumberType.BYTE, NumberType.SHORT).contains(type) == false) {
throw new IllegalArgumentException("Parameter [dimension] cannot be set to numeric type [" + type.name + "]");
}
});

this.script.precludesParameters(ignoreMalformed, coerce, nullValue);
addScriptValidation(script, indexed, hasDocValues);
}
Expand All @@ -130,9 +141,14 @@ private FieldValues<Number> scriptValues() {
return type.compile(name, script.get(), scriptCompiler);
}

public Builder dimension(boolean dimension) {
this.dimension.setValue(dimension);
return this;
}

@Override
protected List<Parameter<?>> getParameters() {
return List.of(indexed, hasDocValues, stored, ignoreMalformed, coerce, nullValue, script, onScriptError, meta);
return List.of(indexed, hasDocValues, stored, ignoreMalformed, coerce, nullValue, script, onScriptError, meta, dimension);
}

@Override
Expand Down Expand Up @@ -944,25 +960,27 @@ public static class NumberFieldType extends SimpleMappedFieldType {
private final boolean coerce;
private final Number nullValue;
private final FieldValues<Number> scriptValues;
private final boolean isDimension;

public NumberFieldType(String name, NumberType type, boolean isSearchable, boolean isStored,
boolean hasDocValues, boolean coerce, Number nullValue, Map<String, String> meta,
FieldValues<Number> script) {
FieldValues<Number> script, boolean isDimension) {
super(name, isSearchable, isStored, hasDocValues, TextSearchInfo.SIMPLE_MATCH_WITHOUT_TERMS, meta);
this.type = Objects.requireNonNull(type);
this.coerce = coerce;
this.nullValue = nullValue;
this.scriptValues = script;
this.isDimension = isDimension;
}

NumberFieldType(String name, Builder builder) {
this(name, builder.type, builder.indexed.getValue(), builder.stored.getValue(), builder.hasDocValues.getValue(),
builder.coerce.getValue().value(), builder.nullValue.getValue(), builder.meta.getValue(),
builder.scriptValues());
builder.scriptValues(), builder.dimension.getValue());
}

public NumberFieldType(String name, NumberType type) {
this(name, type, true, false, true, true, null, Collections.emptyMap(), null);
this(name, type, true, false, true, true, null, Collections.emptyMap(), null, false);
}

@Override
Expand Down Expand Up @@ -1055,6 +1073,13 @@ public Number parsePoint(byte[] value) {
public CollapseType collapseType() {
return CollapseType.NUMERIC;
}

/**
* @return true if field has been marked as a dimension field
*/
public boolean isDimension() {
return isDimension;
}
}

private final Builder builder;
Expand All @@ -1069,6 +1094,7 @@ public CollapseType collapseType() {
private final FieldValues<Number> scriptValues;
private final boolean ignoreMalformedByDefault;
private final boolean coerceByDefault;
private final boolean dimension;

private NumberFieldMapper(
String simpleName,
Expand All @@ -1087,6 +1113,7 @@ private NumberFieldMapper(
this.ignoreMalformedByDefault = builder.ignoreMalformed.getDefaultValue().value();
this.coerceByDefault = builder.coerce.getDefaultValue().value();
this.scriptValues = builder.scriptValues();
this.dimension = builder.dimension.getValue();
this.builder = builder;
}

Expand Down Expand Up @@ -1164,6 +1191,7 @@ protected void indexScriptValues(SearchLookup searchLookup, LeafReaderContext re

@Override
public FieldMapper.Builder getMergeBuilder() {
return new Builder(simpleName(), type, builder.scriptCompiler, ignoreMalformedByDefault, coerceByDefault).init(this);
return new Builder(simpleName(), type, builder.scriptCompiler, ignoreMalformedByDefault, coerceByDefault)
.dimension(dimension).init(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,13 @@ private void doTestRequireDocValues(MappedFieldType ft) {
public void testRequireDocValuesOnLongs() {
doTestRequireDocValues(new NumberFieldMapper.NumberFieldType("field", LONG));
doTestRequireDocValues(new NumberFieldMapper.NumberFieldType("field", LONG,
true, false, false, false, null, Collections.emptyMap(), null));
true, false, false, false, null, Collections.emptyMap(), null, false));
}

public void testRequireDocValuesOnDoubles() {
doTestRequireDocValues(new NumberFieldMapper.NumberFieldType("field", NumberType.DOUBLE));
doTestRequireDocValues(new NumberFieldMapper.NumberFieldType("field", NumberType.DOUBLE,
true, false, false, false, null, Collections.emptyMap(), null));
true, false, false, false, null, Collections.emptyMap(), null, false));
}

public void testRequireDocValuesOnBools() {
Expand Down
Loading