Skip to content

Commit 6e91021

Browse files
committed
Read the mappings from a file
1 parent 71046d6 commit 6e91021

File tree

2 files changed

+177
-159
lines changed

2 files changed

+177
-159
lines changed

modules/kibana/src/main/java/org/elasticsearch/kibana/KibanaPlugin.java

Lines changed: 19 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.elasticsearch.plugins.SystemIndexPlugin;
2323

2424
import java.io.IOException;
25+
import java.io.InputStream;
26+
import java.nio.charset.StandardCharsets;
2527
import java.util.Collection;
2628
import java.util.List;
2729
import java.util.Map;
@@ -43,8 +45,20 @@ public class KibanaPlugin extends Plugin implements SystemIndexPlugin {
4345

4446
public static final SystemDataStreamDescriptor KIBANA_REPORTING_DS_DESCRIPTOR;
4547

48+
private static String loadTemplateSource() throws IOException {
49+
try (InputStream is = KibanaPlugin.class.getResourceAsStream("/kibana-reporting-template.json")) {
50+
if (is == null) {
51+
throw new IOException(
52+
"Kibana reporting template [/kibana-reporting-template.json] not found in kibana template resources."
53+
);
54+
}
55+
return new String(is.readAllBytes(), StandardCharsets.UTF_8);
56+
}
57+
}
58+
4659
static {
4760
try {
61+
final String source = loadTemplateSource();
4862
KIBANA_REPORTING_DS_DESCRIPTOR = new SystemDataStreamDescriptor(
4963
".kibana-reporting",
5064
"system data stream for reporting",
@@ -59,165 +73,11 @@ public class KibanaPlugin extends Plugin implements SystemIndexPlugin {
5973
.dataStreamTemplate(new ComposableIndexTemplate.DataStreamTemplate(true, false))
6074
.metadata(Map.of("managed", "true", "description", "default kibana reporting template installed by elasticsearch"))
6175
.componentTemplates(List.of("kibana-reporting@settings", "kibana-reporting@custom"))
62-
.template(Template.builder().mappings(CompressedXContent.fromJSON("""
63-
{
64-
"properties" : {
65-
"kibana_name" : {
66-
"type" : "keyword"
67-
},
68-
"created_at" : {
69-
"type" : "date"
70-
},
71-
"priority" : {
72-
"type" : "byte"
73-
},
74-
"jobtype" : {
75-
"type" : "keyword"
76-
},
77-
"created_by" : {
78-
"type" : "keyword"
79-
},
80-
"migration_version" : {
81-
"type" : "keyword"
82-
},
83-
"timeout" : {
84-
"type" : "long"
85-
},
86-
"kibana_id" : {
87-
"type" : "keyword"
88-
},
89-
"output" : {
90-
"type" : "object",
91-
"properties" : {
92-
"content_type" : {
93-
"type" : "keyword"
94-
},
95-
"size" : {
96-
"type" : "long"
97-
},
98-
"csv_contains_formulas" : {
99-
"type" : "boolean"
100-
},
101-
"warnings" : {
102-
"type" : "text"
103-
},
104-
"chunk" : {
105-
"type" : "long"
106-
},
107-
"error_code" : {
108-
"type" : "keyword"
109-
},
110-
"max_size_reached" : {
111-
"type" : "boolean"
112-
},
113-
"content" : {
114-
"type" : "object",
115-
"enabled" : false
116-
}
117-
}
118-
},
119-
"process_expiration" : {
120-
"type" : "date"
121-
},
122-
"completed_at" : {
123-
"type" : "date"
124-
},
125-
"payload" : {
126-
"type" : "object",
127-
"enabled" : false
128-
},
129-
"meta" : {
130-
"properties" : {
131-
"layout" : {
132-
"type" : "text",
133-
"fields" : {
134-
"keyword" : {
135-
"ignore_above" : 256,
136-
"type" : "keyword"
137-
}
138-
}
139-
},
140-
"isDeprecated" : {
141-
"type" : "boolean"
142-
},
143-
"objectType" : {
144-
"type" : "text",
145-
"fields" : {
146-
"keyword" : {
147-
"ignore_above" : 256,
148-
"type" : "keyword"
149-
}
150-
}
151-
}
152-
}
153-
},
154-
"parent_id" : {
155-
"type" : "keyword"
156-
},
157-
"max_attempts" : {
158-
"type" : "short"
159-
},
160-
"started_at" : {
161-
"type" : "date"
162-
},
163-
"metrics" : {
164-
"type" : "object",
165-
"properties" : {
166-
"pdf" : {
167-
"type" : "object",
168-
"properties" : {
169-
"pages" : {
170-
"type" : "long"
171-
},
172-
"memory" : {
173-
"type" : "long"
174-
},
175-
"cpuInPercentage" : {
176-
"type" : "double"
177-
},
178-
"cpu" : {
179-
"type" : "double"
180-
},
181-
"memoryInMegabytes" : {
182-
"type" : "double"
183-
}
184-
}
185-
},
186-
"csv" : {
187-
"type" : "object",
188-
"properties" : {
189-
"rows" : {
190-
"type" : "long"
191-
}
192-
}
193-
},
194-
"png" : {
195-
"type" : "object",
196-
"properties" : {
197-
"memory" : {
198-
"type" : "long"
199-
},
200-
"cpuInPercentage" : {
201-
"type" : "double"
202-
},
203-
"cpu" : {
204-
"type" : "double"
205-
},
206-
"memoryInMegabytes" : {
207-
"type" : "double"
208-
}
209-
}
210-
}
211-
}
212-
},
213-
"attempts" : {
214-
"type" : "short"
215-
},
216-
"status" : {
217-
"type" : "keyword"
218-
}
219-
}
220-
}""")).lifecycle(DataStreamLifecycle.dataLifecycleBuilder().enabled(true)))
76+
.template(
77+
Template.builder()
78+
.mappings(CompressedXContent.fromJSON(source))
79+
.lifecycle(DataStreamLifecycle.dataLifecycleBuilder().enabled(true))
80+
)
22181
.build(),
22282
Map.of(
22383
"kibana-reporting@settings",
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
{
2+
"properties" : {
3+
"kibana_name" : {
4+
"type" : "keyword"
5+
},
6+
"created_at" : {
7+
"type" : "date"
8+
},
9+
"priority" : {
10+
"type" : "byte"
11+
},
12+
"jobtype" : {
13+
"type" : "keyword"
14+
},
15+
"created_by" : {
16+
"type" : "keyword"
17+
},
18+
"migration_version" : {
19+
"type" : "keyword"
20+
},
21+
"timeout" : {
22+
"type" : "long"
23+
},
24+
"kibana_id" : {
25+
"type" : "keyword"
26+
},
27+
"output" : {
28+
"type" : "object",
29+
"properties" : {
30+
"content_type" : {
31+
"type" : "keyword"
32+
},
33+
"size" : {
34+
"type" : "long"
35+
},
36+
"csv_contains_formulas" : {
37+
"type" : "boolean"
38+
},
39+
"warnings" : {
40+
"type" : "text"
41+
},
42+
"chunk" : {
43+
"type" : "long"
44+
},
45+
"error_code" : {
46+
"type" : "keyword"
47+
},
48+
"max_size_reached" : {
49+
"type" : "boolean"
50+
},
51+
"content" : {
52+
"type" : "object",
53+
"enabled" : false
54+
}
55+
}
56+
},
57+
"process_expiration" : {
58+
"type" : "date"
59+
},
60+
"completed_at" : {
61+
"type" : "date"
62+
},
63+
"payload" : {
64+
"type" : "object",
65+
"enabled" : false
66+
},
67+
"meta" : {
68+
"properties" : {
69+
"layout" : {
70+
"type" : "text",
71+
"fields" : {
72+
"keyword" : {
73+
"ignore_above" : 256,
74+
"type" : "keyword"
75+
}
76+
}
77+
},
78+
"isDeprecated" : {
79+
"type" : "boolean"
80+
},
81+
"objectType" : {
82+
"type" : "text",
83+
"fields" : {
84+
"keyword" : {
85+
"ignore_above" : 256,
86+
"type" : "keyword"
87+
}
88+
}
89+
}
90+
}
91+
},
92+
"parent_id" : {
93+
"type" : "keyword"
94+
},
95+
"max_attempts" : {
96+
"type" : "short"
97+
},
98+
"started_at" : {
99+
"type" : "date"
100+
},
101+
"metrics" : {
102+
"type" : "object",
103+
"properties" : {
104+
"pdf" : {
105+
"type" : "object",
106+
"properties" : {
107+
"pages" : {
108+
"type" : "long"
109+
},
110+
"memory" : {
111+
"type" : "long"
112+
},
113+
"cpuInPercentage" : {
114+
"type" : "double"
115+
},
116+
"cpu" : {
117+
"type" : "double"
118+
},
119+
"memoryInMegabytes" : {
120+
"type" : "double"
121+
}
122+
}
123+
},
124+
"csv" : {
125+
"type" : "object",
126+
"properties" : {
127+
"rows" : {
128+
"type" : "long"
129+
}
130+
}
131+
},
132+
"png" : {
133+
"type" : "object",
134+
"properties" : {
135+
"memory" : {
136+
"type" : "long"
137+
},
138+
"cpuInPercentage" : {
139+
"type" : "double"
140+
},
141+
"cpu" : {
142+
"type" : "double"
143+
},
144+
"memoryInMegabytes" : {
145+
"type" : "double"
146+
}
147+
}
148+
}
149+
}
150+
},
151+
"attempts" : {
152+
"type" : "short"
153+
},
154+
"status" : {
155+
"type" : "keyword"
156+
}
157+
}
158+
}

0 commit comments

Comments
 (0)