Skip to content

Commit 2818cdd

Browse files
jordan-powersomricohenn
authored andcommitted
Store arrays offsets for unsigned long fields natively with synthetic source (elastic#125709)
This patch builds on the work in elastic#113757, elastic#122999, elastic#124594, and elastic#125529 to natively store array offsets for unsigned long fields instead of falling back to ignored source when synthetic_source_keep: arrays.
1 parent 9282524 commit 2818cdd

File tree

15 files changed

+230
-48
lines changed

15 files changed

+230
-48
lines changed

docs/changelog/125709.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 125709
2+
summary: Store arrays offsets for unsigned long fields natively with synthetic source
3+
area: Mapping
4+
type: enhancement
5+
issues: []

server/src/main/java/org/elasticsearch/index/IndexVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ private static Version parseUnchecked(String version) {
156156
public static final IndexVersion SYNTHETIC_SOURCE_STORE_ARRAYS_NATIVELY_NUMBER = def(9_016_0_00, Version.LUCENE_10_1_0);
157157
public static final IndexVersion SYNTHETIC_SOURCE_STORE_ARRAYS_NATIVELY_BOOLEAN = def(9_017_0_00, Version.LUCENE_10_1_0);
158158
public static final IndexVersion RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS = def(9_018_0_00, Version.LUCENE_10_1_0);
159+
public static final IndexVersion SYNTHETIC_SOURCE_STORE_ARRAYS_NATIVELY_UNSIGNED_LONG = def(9_019_0_00, Version.LUCENE_10_1_0);
159160
/*
160161
* STOP! READ THIS FIRST! No, really,
161162
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

server/src/main/java/org/elasticsearch/index/mapper/BooleanFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ protected String contentType() {
659659

660660
private SourceLoader.SyntheticFieldLoader docValuesSyntheticFieldLoader() {
661661
if (offsetsFieldName != null) {
662-
var layers = new ArrayList<CompositeSyntheticFieldLoader.Layer>();
662+
var layers = new ArrayList<CompositeSyntheticFieldLoader.Layer>(2);
663663
layers.add(
664664
new SortedNumericWithOffsetsDocValuesSyntheticFieldLoaderLayer(
665665
fullPath(),

server/src/main/java/org/elasticsearch/index/mapper/FieldArrayContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public class FieldArrayContext {
2828
private static final String OFFSETS_FIELD_NAME_SUFFIX = ".offsets";
2929
private final Map<String, Offsets> offsetsPerField = new HashMap<>();
3030

31-
void recordOffset(String field, Comparable<?> value) {
31+
public void recordOffset(String field, Comparable<?> value) {
3232
Offsets arrayOffsets = offsetsPerField.computeIfAbsent(field, k -> new Offsets());
3333
int nextOffset = arrayOffsets.currentOffset++;
3434
var offsets = arrayOffsets.valueToOffsets.computeIfAbsent(value, s -> new ArrayList<>(2));
3535
offsets.add(nextOffset);
3636
}
3737

38-
void recordNull(String field) {
38+
public void recordNull(String field) {
3939
Offsets arrayOffsets = offsetsPerField.computeIfAbsent(field, k -> new Offsets());
4040
int nextOffset = arrayOffsets.currentOffset++;
4141
arrayOffsets.nullValueOffsets.add(nextOffset);
@@ -83,7 +83,7 @@ static int[] parseOffsetArray(StreamInput in) throws IOException {
8383
return offsetToOrd;
8484
}
8585

86-
static String getOffsetsFieldName(
86+
public static String getOffsetsFieldName(
8787
MapperBuilderContext context,
8888
Mapper.SourceKeepMode indexSourceKeepMode,
8989
boolean hasDocValues,

server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ public void doValidate(MappingLookup lookup) {
644644
protected SyntheticSourceSupport syntheticSourceSupport() {
645645
if (hasDocValues) {
646646
return new SyntheticSourceSupport.Native(() -> {
647-
var layers = new ArrayList<CompositeSyntheticFieldLoader.Layer>();
647+
var layers = new ArrayList<CompositeSyntheticFieldLoader.Layer>(2);
648648
if (offsetsFieldName != null) {
649649
layers.add(
650650
new SortedSetWithOffsetsDocValuesSyntheticFieldLoaderLayer(fullPath(), offsetsFieldName, IpFieldMapper::convert)

server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ protected SyntheticSourceSupport syntheticSourceSupport() {
12791279
public SourceLoader.SyntheticFieldLoader syntheticFieldLoader(String fullFieldName, String leafFieldName) {
12801280
assert fieldType.stored() || hasDocValues;
12811281

1282-
var layers = new ArrayList<CompositeSyntheticFieldLoader.Layer>();
1282+
var layers = new ArrayList<CompositeSyntheticFieldLoader.Layer>(2);
12831283
if (fieldType.stored()) {
12841284
layers.add(new CompositeSyntheticFieldLoader.StoredFieldLayer(fullPath()) {
12851285
@Override

server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,7 @@ public void doValidate(MappingLookup lookup) {
22742274

22752275
private SourceLoader.SyntheticFieldLoader docValuesSyntheticFieldLoader() {
22762276
if (offsetsFieldName != null) {
2277-
var layers = new ArrayList<CompositeSyntheticFieldLoader.Layer>();
2277+
var layers = new ArrayList<CompositeSyntheticFieldLoader.Layer>(2);
22782278
layers.add(new SortedNumericWithOffsetsDocValuesSyntheticFieldLoaderLayer(fullPath(), offsetsFieldName, type::writeValue));
22792279
if (ignoreMalformed.value()) {
22802280
layers.add(new CompositeSyntheticFieldLoader.MalformedValuesLayer(fullPath()));

server/src/main/java/org/elasticsearch/index/mapper/SortedNumericWithOffsetsDocValuesSyntheticFieldLoaderLayer.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
import java.io.IOException;
2020

21-
class SortedNumericWithOffsetsDocValuesSyntheticFieldLoaderLayer implements CompositeSyntheticFieldLoader.DocValuesLayer {
21+
public class SortedNumericWithOffsetsDocValuesSyntheticFieldLoaderLayer implements CompositeSyntheticFieldLoader.DocValuesLayer {
2222
@FunctionalInterface
23-
interface NumericValueWriter {
23+
public interface NumericValueWriter {
2424
void writeLongValue(XContentBuilder b, long value) throws IOException;
2525
}
2626

@@ -29,7 +29,11 @@ interface NumericValueWriter {
2929
private final NumericValueWriter valueWriter;
3030
private NumericDocValuesWithOffsetsLoader docValuesLoader;
3131

32-
SortedNumericWithOffsetsDocValuesSyntheticFieldLoaderLayer(String fullPath, String offsetsFieldName, NumericValueWriter valueWriter) {
32+
public SortedNumericWithOffsetsDocValuesSyntheticFieldLoaderLayer(
33+
String fullPath,
34+
String offsetsFieldName,
35+
NumericValueWriter valueWriter
36+
) {
3337
this.fullPath = fullPath;
3438
this.offsetsFieldName = offsetsFieldName;
3539
this.valueWriter = valueWriter;

0 commit comments

Comments
 (0)