Skip to content

Commit ed1d11d

Browse files
committed
Add dynamic templates
1 parent e0b7b04 commit ed1d11d

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleAction.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
import org.elasticsearch.tasks.TaskId;
7474
import org.elasticsearch.threadpool.ThreadPool;
7575
import org.elasticsearch.transport.TransportService;
76-
import org.elasticsearch.xcontent.XContentBuilder;
7776
import org.elasticsearch.xpack.aggregatemetric.mapper.AggregateMetricDoubleFieldMapper;
7877
import org.elasticsearch.xpack.core.ClientHelper;
7978
import org.elasticsearch.xpack.core.downsample.DownsampleShardPersistentTaskState;
@@ -683,6 +682,7 @@ static String createDownsampleIndexMapping(
683682
final String dateIntervalType = config.getIntervalType();
684683
final String dateInterval = config.getInterval().toString();
685684
final String timezone = config.getTimeZone();
685+
addDynamicTemplates(sourceIndexMappings);
686686
MappingVisitor.visitMapping(sourceIndexMappings, (field, mapping) -> {
687687
@SuppressWarnings("unchecked")
688688
Map<String, Object> updatedMapping = (Map<String, Object>) mapping;
@@ -834,17 +834,11 @@ static IndexMetadata.Builder copyIndexMetadata(
834834
/**
835835
* Configure the dynamic templates to always map strings to the keyword field type.
836836
*/
837-
private static void addDynamicTemplates(final XContentBuilder builder) throws IOException {
838-
builder.startArray("dynamic_templates")
839-
.startObject()
840-
.startObject("strings")
841-
.field("match_mapping_type", "string")
842-
.startObject("mapping")
843-
.field("type", "keyword")
844-
.endObject()
845-
.endObject()
846-
.endObject()
847-
.endArray();
837+
private static void addDynamicTemplates(Map<String, Object> mapping) throws IOException {
838+
mapping.put(
839+
"dynamic_templates",
840+
List.of(Map.of("strings", Map.of("match_mapping_type", "string", "mapping", Map.of("type", "keyword"))))
841+
);
848842
}
849843

850844
private void createDownsampleIndex(

0 commit comments

Comments
 (0)