|
73 | 73 | import org.elasticsearch.tasks.TaskId; |
74 | 74 | import org.elasticsearch.threadpool.ThreadPool; |
75 | 75 | import org.elasticsearch.transport.TransportService; |
76 | | -import org.elasticsearch.xcontent.XContentBuilder; |
77 | 76 | import org.elasticsearch.xpack.aggregatemetric.mapper.AggregateMetricDoubleFieldMapper; |
78 | 77 | import org.elasticsearch.xpack.core.ClientHelper; |
79 | 78 | import org.elasticsearch.xpack.core.downsample.DownsampleShardPersistentTaskState; |
@@ -683,6 +682,7 @@ static String createDownsampleIndexMapping( |
683 | 682 | final String dateIntervalType = config.getIntervalType(); |
684 | 683 | final String dateInterval = config.getInterval().toString(); |
685 | 684 | final String timezone = config.getTimeZone(); |
| 685 | + addDynamicTemplates(sourceIndexMappings); |
686 | 686 | MappingVisitor.visitMapping(sourceIndexMappings, (field, mapping) -> { |
687 | 687 | @SuppressWarnings("unchecked") |
688 | 688 | Map<String, Object> updatedMapping = (Map<String, Object>) mapping; |
@@ -834,17 +834,11 @@ static IndexMetadata.Builder copyIndexMetadata( |
834 | 834 | /** |
835 | 835 | * Configure the dynamic templates to always map strings to the keyword field type. |
836 | 836 | */ |
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 | + ); |
848 | 842 | } |
849 | 843 |
|
850 | 844 | private void createDownsampleIndex( |
|
0 commit comments