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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [Derived Source] Add integration of derived source feature across various paths like get/search/recovery ([#18565](https://github.com/opensearch-project/OpenSearch/pull/18565))
- Supporting Scripted Metric Aggregation when reducing aggregations in InternalValueCount and InternalAvg ([18411](https://github.com/opensearch-project/OpenSearch/pull18411)))
- Support `search_after` numeric queries with Approximation Framework ([#18896](https://github.com/opensearch-project/OpenSearch/pull/18896))
- Add skip_list parameter to Numeric Field Mappers (default false) ([#18889](https://github.com/opensearch-project/OpenSearch/pull/18889))

### Changed
- Update Subject interface to use CheckedRunnable ([#18570](https://github.com/opensearch-project/OpenSearch/issues/18570))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,14 @@ protected void parseCreateField(ParseContext context) throws IOException {
}
long scaledValue = Math.round(doubleValue * scalingFactor);

List<Field> fields = NumberFieldMapper.NumberType.LONG.createFields(fieldType().name(), scaledValue, indexed, hasDocValues, stored);
List<Field> fields = NumberFieldMapper.NumberType.LONG.createFields(
fieldType().name(),
scaledValue,
indexed,
hasDocValues,
false,
stored
);
context.doc().addAll(fields);

if (hasDocValues == false && (indexed || stored)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ protected void parseCreateField(ParseContext context) throws IOException {
tokenCount = countPositions(analyzer, name(), value, enablePositionIncrements);
}

context.doc().addAll(NumberFieldMapper.NumberType.INTEGER.createFields(fieldType().name(), tokenCount, index, hasDocValues, store));
context.doc()
.addAll(NumberFieldMapper.NumberType.INTEGER.createFields(fieldType().name(), tokenCount, index, hasDocValues, false, store));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public void testDuel() throws Exception {
document.add(new TextField(entry.getKey(), value, Field.Store.NO));
}
for (Integer intValue : intValues) {
List<Field> numberFields = NumberFieldMapper.NumberType.INTEGER.createFields("int_field", intValue, true, true, false);
List<Field> numberFields = NumberFieldMapper.NumberType.INTEGER.createFields("int_field", intValue, true, true, false, false);
for (Field numberField : numberFields) {
document.add(numberField);
}
Expand Down Expand Up @@ -449,6 +449,7 @@ public void testDuel2() throws Exception {
between(range[0], range[1]),
true,
true,
false,
false
);
for (Field numberField : numberFields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void postParse(ParseContext context) throws IOException {
return;
}
final int value = context.sourceToParse().source().length();
context.doc().addAll(NumberType.INTEGER.createFields(name(), value, true, true, true));
context.doc().addAll(NumberType.INTEGER.createFields(name(), value, true, true, false, true));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Setting.Property;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.support.XContentMapValues;
import org.opensearch.core.common.bytes.BytesArray;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
Expand Down Expand Up @@ -118,6 +119,13 @@ public static class Builder extends ParametrizedFieldMapper.Builder {
private final Parameter<Boolean> indexed = Parameter.indexParam(m -> toType(m).indexed, true);
private final Parameter<Boolean> hasDocValues = Parameter.docValuesParam(m -> toType(m).hasDocValues, true);
private final Parameter<Boolean> stored = Parameter.storeParam(m -> toType(m).stored, false);
private final Parameter<Boolean> skiplist = new Parameter<>(
"skip_list",
false,
() -> false,
(n, c, o) -> XContentMapValues.nodeBooleanValue(o),
m -> toType(m).skiplist
);

private final Parameter<Explicit<Boolean>> ignoreMalformed;
private final Parameter<Explicit<Boolean>> coerce;
Expand Down Expand Up @@ -169,7 +177,7 @@ public Builder docValues(boolean hasDocValues) {

@Override
protected List<Parameter<?>> getParameters() {
return Arrays.asList(indexed, hasDocValues, stored, ignoreMalformed, coerce, nullValue, meta);
return Arrays.asList(indexed, hasDocValues, stored, skiplist, ignoreMalformed, coerce, nullValue, meta);
}

@Override
Expand Down Expand Up @@ -416,13 +424,26 @@ public Query rangeQuery(
}

@Override
public List<Field> createFields(String name, Number value, boolean indexed, boolean docValued, boolean stored) {
public List<Field> createFields(
String name,
Number value,
boolean indexed,
boolean docValued,
boolean skiplist,
boolean stored
) {
List<Field> fields = new ArrayList<>();
if (indexed) {
fields.add(new HalfFloatPoint(name, value.floatValue()));
}
if (docValued) {
fields.add(new SortedNumericDocValuesField(name, HalfFloatPoint.halfFloatToSortableShort(value.floatValue())));
if (skiplist) {
fields.add(
SortedNumericDocValuesField.indexedField(name, HalfFloatPoint.halfFloatToSortableShort(value.floatValue()))
);
} else {
fields.add(new SortedNumericDocValuesField(name, HalfFloatPoint.halfFloatToSortableShort(value.floatValue())));
}
}
if (stored) {
fields.add(new StoredField(name, value.floatValue()));
Expand Down Expand Up @@ -603,13 +624,24 @@ public Query rangeQuery(
}

@Override
public List<Field> createFields(String name, Number value, boolean indexed, boolean docValued, boolean stored) {
public List<Field> createFields(
String name,
Number value,
boolean indexed,
boolean docValued,
boolean skiplist,
boolean stored
) {
List<Field> fields = new ArrayList<>();
if (indexed) {
fields.add(new FloatPoint(name, value.floatValue()));
}
if (docValued) {
fields.add(new SortedNumericDocValuesField(name, NumericUtils.floatToSortableInt(value.floatValue())));
if (skiplist) {
fields.add(SortedNumericDocValuesField.indexedField(name, NumericUtils.floatToSortableInt(value.floatValue())));
} else {
fields.add(new SortedNumericDocValuesField(name, NumericUtils.floatToSortableInt(value.floatValue())));
}
}
if (stored) {
fields.add(new StoredField(name, value.floatValue()));
Expand Down Expand Up @@ -766,13 +798,24 @@ public Query rangeQuery(
}

@Override
public List<Field> createFields(String name, Number value, boolean indexed, boolean docValued, boolean stored) {
public List<Field> createFields(
String name,
Number value,
boolean indexed,
boolean docValued,
boolean skiplist,
boolean stored
) {
List<Field> fields = new ArrayList<>();
if (indexed) {
fields.add(new DoublePoint(name, value.doubleValue()));
}
if (docValued) {
fields.add(new SortedNumericDocValuesField(name, NumericUtils.doubleToSortableLong(value.doubleValue())));
if (skiplist) {
fields.add(SortedNumericDocValuesField.indexedField(name, NumericUtils.doubleToSortableLong(value.doubleValue())));
} else {
fields.add(new SortedNumericDocValuesField(name, NumericUtils.doubleToSortableLong(value.doubleValue())));
}
}
if (stored) {
fields.add(new StoredField(name, value.doubleValue()));
Expand Down Expand Up @@ -878,8 +921,15 @@ public Query rangeQuery(
}

@Override
public List<Field> createFields(String name, Number value, boolean indexed, boolean docValued, boolean stored) {
return INTEGER.createFields(name, value, indexed, docValued, stored);
public List<Field> createFields(
String name,
Number value,
boolean indexed,
boolean docValued,
boolean skiplist,
boolean stored
) {
return INTEGER.createFields(name, value, indexed, docValued, skiplist, stored);
}

@Override
Expand Down Expand Up @@ -974,8 +1024,15 @@ public Query rangeQuery(
}

@Override
public List<Field> createFields(String name, Number value, boolean indexed, boolean docValued, boolean stored) {
return INTEGER.createFields(name, value, indexed, docValued, stored);
public List<Field> createFields(
String name,
Number value,
boolean indexed,
boolean docValued,
boolean skiplist,
boolean stored
) {
return INTEGER.createFields(name, value, indexed, docValued, skiplist, stored);
}

@Override
Expand Down Expand Up @@ -1185,13 +1242,24 @@ public Query rangeQuery(
}

@Override
public List<Field> createFields(String name, Number value, boolean indexed, boolean docValued, boolean stored) {
public List<Field> createFields(
String name,
Number value,
boolean indexed,
boolean docValued,
boolean skiplist,
boolean stored
) {
List<Field> fields = new ArrayList<>();
if (indexed) {
fields.add(new IntPoint(name, value.intValue()));
}
if (docValued) {
fields.add(new SortedNumericDocValuesField(name, value.intValue()));
if (skiplist) {
fields.add(SortedNumericDocValuesField.indexedField(name, value.intValue()));
} else {
fields.add(new SortedNumericDocValuesField(name, value.intValue()));
}
}
if (stored) {
fields.add(new StoredField(name, value.intValue()));
Expand Down Expand Up @@ -1344,13 +1412,24 @@ public Query rangeQuery(
}

@Override
public List<Field> createFields(String name, Number value, boolean indexed, boolean docValued, boolean stored) {
public List<Field> createFields(
String name,
Number value,
boolean indexed,
boolean docValued,
boolean skiplist,
boolean stored
) {
List<Field> fields = new ArrayList<>();
if (indexed) {
fields.add(new LongPoint(name, value.longValue()));
}
if (docValued) {
fields.add(new SortedNumericDocValuesField(name, value.longValue()));
if (skiplist) {
fields.add(SortedNumericDocValuesField.indexedField(name, value.longValue()));
} else {
fields.add(new SortedNumericDocValuesField(name, value.longValue()));
}
}
if (stored) {
fields.add(new StoredField(name, value.longValue()));
Expand Down Expand Up @@ -1491,7 +1570,14 @@ public Query rangeQuery(
}

@Override
public List<Field> createFields(String name, Number value, boolean indexed, boolean docValued, boolean stored) {
public List<Field> createFields(
String name,
Number value,
boolean indexed,
boolean docValued,
boolean skiplist,
boolean stored
) {
List<Field> fields = new ArrayList<>();
final BigInteger v = Numbers.toUnsignedLongExact(value);

Expand All @@ -1500,7 +1586,11 @@ public List<Field> createFields(String name, Number value, boolean indexed, bool
}

if (docValued) {
fields.add(new SortedNumericDocValuesField(name, v.longValue()));
if (skiplist) {
fields.add(SortedNumericDocValuesField.indexedField(name, v.longValue()));
} else {
fields.add(new SortedNumericDocValuesField(name, v.longValue()));
}
}

if (stored) {
Expand Down Expand Up @@ -1569,7 +1659,14 @@ public abstract Query rangeQuery(

public abstract Number parsePoint(byte[] value);

public abstract List<Field> createFields(String name, Number value, boolean indexed, boolean docValued, boolean stored);
public abstract List<Field> createFields(
String name,
Number value,
boolean indexed,
boolean docValued,
boolean skiplist,
boolean stored
);

abstract Number valueForSearch(String value);

Expand Down Expand Up @@ -1987,6 +2084,7 @@ public Number parse(Object value) {
private final boolean indexed;
private final boolean hasDocValues;
private final boolean stored;
private final boolean skiplist;
private final Explicit<Boolean> ignoreMalformed;
private final Explicit<Boolean> coerce;
private final Number nullValue;
Expand All @@ -2000,6 +2098,7 @@ private NumberFieldMapper(String simpleName, MappedFieldType mappedFieldType, Mu
this.indexed = builder.indexed.getValue();
this.hasDocValues = builder.hasDocValues.getValue();
this.stored = builder.stored.getValue();
this.skiplist = builder.skiplist.getValue();
this.ignoreMalformed = builder.ignoreMalformed.getValue();
this.coerce = builder.coerce.getValue();
this.nullValue = builder.nullValue.getValue();
Expand Down Expand Up @@ -2068,7 +2167,7 @@ protected void parseCreateField(ParseContext context) throws IOException {
numericValue = fieldType().type.parse(value, coerce.value());
}

context.doc().addAll(fieldType().type.createFields(fieldType().name(), numericValue, indexed, hasDocValues, stored));
context.doc().addAll(fieldType().type.createFields(fieldType().name(), numericValue, indexed, hasDocValues, skiplist, stored));

if (hasDocValues == false && (stored || indexed)) {
createFieldNamesField(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testSingleValued() throws IOException {
// we need the default codec to check for singletons
IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(null).setCodec(TestUtil.getDefaultCodec()));
Document doc = new Document();
for (IndexableField f : NumberFieldMapper.NumberType.HALF_FLOAT.createFields("half_float", 3f, false, true, false)) {
for (IndexableField f : NumberFieldMapper.NumberType.HALF_FLOAT.createFields("half_float", 3f, false, true, false, false)) {
doc.add(f);
}
w.addDocument(doc);
Expand All @@ -74,10 +74,10 @@ public void testMultiValued() throws IOException {
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(null));
Document doc = new Document();
for (IndexableField f : NumberFieldMapper.NumberType.HALF_FLOAT.createFields("half_float", 3f, false, true, false)) {
for (IndexableField f : NumberFieldMapper.NumberType.HALF_FLOAT.createFields("half_float", 3f, false, true, false, false)) {
doc.add(f);
}
for (IndexableField f : NumberFieldMapper.NumberType.HALF_FLOAT.createFields("half_float", 2f, false, true, false)) {
for (IndexableField f : NumberFieldMapper.NumberType.HALF_FLOAT.createFields("half_float", 2f, false, true, false, false)) {
doc.add(f);
}
w.addDocument(doc);
Expand Down
Loading
Loading