Skip to content

Commit d3eff03

Browse files
[8.x] Natively store synthetic source array offsets for numeric fields (#124594) | Fix ignores malformed testcase (#125337) | Fix offsets not recording duplicate values (#125354) (#125440)
* Natively store synthetic source array offsets for numeric fields (#124594) This patch builds on the work in #122999 and #113757 to natively store array offsets for numeric fields instead of falling back to ignored source when `source_keep_mode: arrays`. (cherry picked from commit 376abfe) # Conflicts: # server/src/main/java/org/elasticsearch/index/IndexVersions.java # server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java * Fix ignores malformed testcase (#125337) Fix and unmute testSynthesizeArrayRandomIgnoresMalformed (cherry picked from commit 2ff03ac) # Conflicts: # muted-tests.yml * Fix offsets not recording duplicate values (#125354) Previously, when calculating the offsets, we just compared the values as-is without any loss of precision. However, when the values were saved into doc values and loaded in the doc values loader, they could have lost precision. This meant that values that were not duplicates when calculating the offsets could now be duplicates in the doc values loader. This interfered with the de-duplication logic, causing incorrect values to be returned. My solution is to apply the precision loss before calculating the offsets, so that both the offsets calculation and the SortedNumericDocValues de-duplication see the same values as duplicates. (cherry picked from commit db73175)
1 parent 89140ea commit d3eff03

File tree

44 files changed

+1191
-156
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1191
-156
lines changed

docs/changelog/124594.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 124594
2+
summary: Store arrays offsets for numeric 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
@@ -126,6 +126,7 @@ private static IndexVersion def(int id, Version luceneVersion) {
126126
public static final IndexVersion LOGSB_OPTIONAL_SORTING_ON_HOST_NAME_BACKPORT = def(8_525_0_00, Version.LUCENE_9_12_1);
127127
public static final IndexVersion USE_SYNTHETIC_SOURCE_FOR_RECOVERY_BY_DEFAULT_BACKPORT = def(8_526_0_00, Version.LUCENE_9_12_1);
128128
public static final IndexVersion SYNTHETIC_SOURCE_STORE_ARRAYS_NATIVELY_KEYWORD = def(8_527_0_00, Version.LUCENE_9_12_1);
129+
public static final IndexVersion SYNTHETIC_SOURCE_STORE_ARRAYS_NATIVELY_NUMBER = def(8_528_0_00, Version.LUCENE_9_12_1);
129130
/*
130131
* STOP! READ THIS FIRST! No, really,
131132
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ public boolean newDynamicLongField(DocumentParserContext context, String name) t
352352
ScriptCompiler.NONE,
353353
context.indexSettings().getSettings(),
354354
context.indexSettings().getIndexVersionCreated(),
355-
context.indexSettings().getMode()
355+
context.indexSettings().getMode(),
356+
context.indexSettings().sourceKeepMode()
356357
),
357358
context
358359
);
@@ -370,7 +371,8 @@ public boolean newDynamicDoubleField(DocumentParserContext context, String name)
370371
ScriptCompiler.NONE,
371372
context.indexSettings().getSettings(),
372373
context.indexSettings().getIndexVersionCreated(),
373-
context.indexSettings().getMode()
374+
context.indexSettings().getMode(),
375+
context.indexSettings().sourceKeepMode()
374376
),
375377
context
376378
);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.elasticsearch.common.io.stream.BytesStreamOutput;
1515
import org.elasticsearch.common.io.stream.StreamInput;
1616
import org.elasticsearch.index.IndexVersion;
17-
import org.elasticsearch.index.IndexVersions;
1817

1918
import java.io.IOException;
2019
import java.util.ArrayList;
@@ -89,16 +88,18 @@ static String getOffsetsFieldName(
8988
boolean hasDocValues,
9089
boolean isStored,
9190
FieldMapper.Builder fieldMapperBuilder,
92-
IndexVersion indexCreatedVersion
91+
IndexVersion indexCreatedVersion,
92+
IndexVersion minSupportedVersion
9393
) {
9494
var sourceKeepMode = fieldMapperBuilder.sourceKeepMode.orElse(indexSourceKeepMode);
9595
if (context.isSourceSynthetic()
9696
&& sourceKeepMode == Mapper.SourceKeepMode.ARRAYS
9797
&& hasDocValues
9898
&& isStored == false
99+
&& context.isInNestedContext() == false
99100
&& fieldMapperBuilder.copyTo.copyToFields().isEmpty()
100101
&& fieldMapperBuilder.multiFieldsBuilder.hasMultiFields() == false
101-
&& indexCreatedVersion.onOrAfter(IndexVersions.SYNTHETIC_SOURCE_STORE_ARRAYS_NATIVELY_KEYWORD)) {
102+
&& indexCreatedVersion.onOrAfter(minSupportedVersion)) {
102103
// Skip stored, we will be synthesizing from stored fields, no point to keep track of the offsets
103104
// Skip copy_to and multi fields, supporting that requires more work. However, copy_to usage is rare in metrics and
104105
// logging use cases

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ public IpFieldMapper build(MapperBuilderContext context) {
200200
hasDocValues.getValue(),
201201
stored.getValue(),
202202
this,
203-
indexCreatedVersion
203+
indexCreatedVersion,
204+
IndexVersions.SYNTHETIC_SOURCE_STORE_ARRAYS_NATIVELY_KEYWORD
204205
);
205206
return new IpFieldMapper(
206207
leafName(),

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.elasticsearch.core.Nullable;
4242
import org.elasticsearch.features.NodeFeature;
4343
import org.elasticsearch.index.IndexVersion;
44+
import org.elasticsearch.index.IndexVersions;
4445
import org.elasticsearch.index.analysis.IndexAnalyzers;
4546
import org.elasticsearch.index.analysis.NamedAnalyzer;
4647
import org.elasticsearch.index.fielddata.FieldData;
@@ -389,7 +390,8 @@ public KeywordFieldMapper build(MapperBuilderContext context) {
389390
hasDocValues.getValue(),
390391
stored.getValue(),
391392
this,
392-
indexCreatedVersion
393+
indexCreatedVersion,
394+
IndexVersions.SYNTHETIC_SOURCE_STORE_ARRAYS_NATIVELY_KEYWORD
393395
);
394396
return new KeywordFieldMapper(
395397
leafName(),

0 commit comments

Comments
 (0)