Skip to content

Commit e4d08c5

Browse files
authored
Merge branch 'main' into esql-verifiers
2 parents 0d76655 + e59e98e commit e4d08c5

File tree

10 files changed

+371
-26
lines changed

10 files changed

+371
-26
lines changed

modules/data-streams/src/main/java/org/elasticsearch/datastreams/action/TransportGetDataStreamsAction.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.elasticsearch.threadpool.ThreadPool;
5555
import org.elasticsearch.transport.TransportService;
5656

57+
import java.io.IOException;
5758
import java.time.Instant;
5859
import java.util.ArrayList;
5960
import java.util.Arrays;
@@ -261,13 +262,17 @@ static GetDataStreamAction.Response innerOperation(
261262
Settings settings = dataStream.getEffectiveSettings(state.metadata());
262263
ilmPolicyName = settings.get(IndexMetadata.LIFECYCLE_NAME);
263264
if (indexMode == null && state.metadata().templatesV2().get(indexTemplate) != null) {
264-
indexMode = resolveMode(
265-
state,
266-
indexSettingProviders,
267-
dataStream,
268-
settings,
269-
dataStream.getEffectiveIndexTemplate(state.metadata())
270-
);
265+
try {
266+
indexMode = resolveMode(
267+
state,
268+
indexSettingProviders,
269+
dataStream,
270+
settings,
271+
dataStream.getEffectiveIndexTemplate(state.metadata())
272+
);
273+
} catch (IOException e) {
274+
throw new RuntimeException(e);
275+
}
271276
}
272277
indexTemplatePreferIlmValue = PREFER_ILM_SETTING.get(settings);
273278
} else {

modules/data-streams/src/test/java/org/elasticsearch/datastreams/UpdateTimeSeriesRangeServiceTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ public void testUpdateTimeSeriesTemporalOneBadDataStream() {
258258
2,
259259
ds2.getMetadata(),
260260
ds2.getSettings(),
261+
ds2.getMappings(),
261262
ds2.isHidden(),
262263
ds2.isReplicated(),
263264
ds2.isSystem(),

muted-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ tests:
567567
- class: org.elasticsearch.xpack.inference.qa.mixed.CohereServiceMixedIT
568568
method: testCohereEmbeddings
569569
issue: https://github.com/elastic/elasticsearch/issues/130010
570+
- class: org.elasticsearch.xpack.esql.qa.mixed.MixedClusterEsqlSpecIT
571+
issue: https://github.com/elastic/elasticsearch/issues/128224
570572

571573
# Examples:
572574
#

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ static TransportVersion def(int id) {
323323
public static final TransportVersion ML_INFERENCE_ELASTIC_DENSE_TEXT_EMBEDDINGS_ADDED = def(9_109_00_0);
324324
public static final TransportVersion ML_INFERENCE_COHERE_API_VERSION = def(9_110_0_00);
325325
public static final TransportVersion ESQL_PROFILE_INCLUDE_PLAN = def(9_111_0_00);
326+
public static final TransportVersion MAPPINGS_IN_DATA_STREAMS = def(9_112_0_00);
326327

327328
/*
328329
* STOP! READ THIS FIRST! No, really,

server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplate.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,24 @@
1919
import org.elasticsearch.common.io.stream.StreamOutput;
2020
import org.elasticsearch.common.io.stream.Writeable;
2121
import org.elasticsearch.common.settings.Settings;
22+
import org.elasticsearch.common.xcontent.XContentHelper;
2223
import org.elasticsearch.core.Nullable;
2324
import org.elasticsearch.index.mapper.DataStreamTimestampFieldMapper;
2425
import org.elasticsearch.index.mapper.MapperService;
26+
import org.elasticsearch.index.mapper.Mapping;
2527
import org.elasticsearch.xcontent.ConstructingObjectParser;
2628
import org.elasticsearch.xcontent.ParseField;
2729
import org.elasticsearch.xcontent.ToXContentObject;
2830
import org.elasticsearch.xcontent.XContentBuilder;
31+
import org.elasticsearch.xcontent.XContentFactory;
2932
import org.elasticsearch.xcontent.XContentParser;
33+
import org.elasticsearch.xcontent.XContentParserConfiguration;
34+
import org.elasticsearch.xcontent.XContentType;
3035

3136
import java.io.IOException;
3237
import java.util.ArrayList;
3338
import java.util.Collections;
39+
import java.util.HashMap;
3440
import java.util.List;
3541
import java.util.Map;
3642
import java.util.Objects;
@@ -51,6 +57,14 @@ public class ComposableIndexTemplate implements SimpleDiffable<ComposableIndexTe
5157
private static final ParseField ALLOW_AUTO_CREATE = new ParseField("allow_auto_create");
5258
private static final ParseField IGNORE_MISSING_COMPONENT_TEMPLATES = new ParseField("ignore_missing_component_templates");
5359
private static final ParseField DEPRECATED = new ParseField("deprecated");
60+
public static final CompressedXContent EMPTY_MAPPINGS;
61+
static {
62+
try {
63+
EMPTY_MAPPINGS = new CompressedXContent(Map.of());
64+
} catch (IOException e) {
65+
throw new RuntimeException(e);
66+
}
67+
}
5468

5569
@SuppressWarnings("unchecked")
5670
public static final ConstructingObjectParser<ComposableIndexTemplate, Void> PARSER = new ConstructingObjectParser<>(
@@ -338,6 +352,64 @@ public ComposableIndexTemplate mergeSettings(Settings settings) {
338352
return mergedIndexTemplateBuilder.build();
339353
}
340354

355+
public ComposableIndexTemplate mergeMappings(CompressedXContent mappings) throws IOException {
356+
Objects.requireNonNull(mappings);
357+
if (Mapping.EMPTY.toCompressedXContent().equals(mappings) && this.template() != null && this.template().mappings() != null) {
358+
return this;
359+
}
360+
ComposableIndexTemplate.Builder mergedIndexTemplateBuilder = this.toBuilder();
361+
Template.Builder mergedTemplateBuilder;
362+
CompressedXContent templateMappings;
363+
if (this.template() == null) {
364+
mergedTemplateBuilder = Template.builder();
365+
templateMappings = null;
366+
} else {
367+
mergedTemplateBuilder = Template.builder(this.template());
368+
templateMappings = this.template().mappings();
369+
}
370+
mergedTemplateBuilder.mappings(templateMappings == null ? mappings : merge(templateMappings, mappings));
371+
mergedIndexTemplateBuilder.template(mergedTemplateBuilder);
372+
return mergedIndexTemplateBuilder.build();
373+
}
374+
375+
@SuppressWarnings("unchecked")
376+
private CompressedXContent merge(CompressedXContent originalMapping, CompressedXContent mappingAddition) throws IOException {
377+
Map<String, Object> mappingAdditionMap = XContentHelper.convertToMap(mappingAddition.uncompressed(), true, XContentType.JSON).v2();
378+
Map<String, Object> combinedMappingMap = new HashMap<>();
379+
if (originalMapping != null) {
380+
Map<String, Object> originalMappingMap = XContentHelper.convertToMap(originalMapping.uncompressed(), true, XContentType.JSON)
381+
.v2();
382+
if (originalMappingMap.containsKey(MapperService.SINGLE_MAPPING_NAME)) {
383+
combinedMappingMap.putAll((Map<String, ?>) originalMappingMap.get(MapperService.SINGLE_MAPPING_NAME));
384+
} else {
385+
combinedMappingMap.putAll(originalMappingMap);
386+
}
387+
}
388+
XContentHelper.update(combinedMappingMap, mappingAdditionMap, true);
389+
return convertMappingMapToXContent(combinedMappingMap);
390+
}
391+
392+
private static CompressedXContent convertMappingMapToXContent(Map<String, Object> rawAdditionalMapping) throws IOException {
393+
CompressedXContent compressedXContent;
394+
if (rawAdditionalMapping.isEmpty()) {
395+
compressedXContent = EMPTY_MAPPINGS;
396+
} else {
397+
try (var parser = XContentHelper.mapToXContentParser(XContentParserConfiguration.EMPTY, rawAdditionalMapping)) {
398+
compressedXContent = mappingFromXContent(parser);
399+
}
400+
}
401+
return compressedXContent;
402+
}
403+
404+
private static CompressedXContent mappingFromXContent(XContentParser parser) throws IOException {
405+
XContentParser.Token token = parser.nextToken();
406+
if (token == XContentParser.Token.START_OBJECT) {
407+
return new CompressedXContent(Strings.toString(XContentFactory.jsonBuilder().map(parser.mapOrdered())));
408+
} else {
409+
throw new IllegalArgumentException("Unexpected token: " + token);
410+
}
411+
}
412+
341413
@Override
342414
public int hashCode() {
343415
return Objects.hash(

0 commit comments

Comments
 (0)