Skip to content

Commit b6a6846

Browse files
committed
poc of template fields in saved object
1 parent 659c01a commit b6a6846

File tree

13 files changed

+148
-7
lines changed

13 files changed

+148
-7
lines changed

x-pack/platform/plugins/shared/cases/server/cases_analytics/cases_index/mappings.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,37 @@
88
import type { MappingTypeMapping } from '@elastic/elasticsearch/lib/api/types';
99

1010
export const CAI_CASES_INDEX_MAPPINGS: MappingTypeMapping = {
11-
dynamic: false,
11+
dynamic: true,
12+
dynamic_templates: [
13+
{
14+
as_keyword: {
15+
match_pattern: 'regex',
16+
match: '.*_as_keyword',
17+
mapping: {
18+
type: 'keyword',
19+
ignore_above: 256,
20+
},
21+
},
22+
},
23+
{
24+
as_integer: {
25+
match_pattern: 'regex',
26+
match: '.*_as_integer',
27+
mapping: {
28+
type: 'integer',
29+
},
30+
},
31+
},
32+
{
33+
as_date: {
34+
match_pattern: 'regex',
35+
match: '.*_as_date',
36+
mapping: {
37+
type: 'date',
38+
},
39+
},
40+
},
41+
],
1242
properties: {
1343
'@timestamp': {
1444
type: 'date',
@@ -133,6 +163,10 @@ export const CAI_CASES_INDEX_MAPPINGS: MappingTypeMapping = {
133163
},
134164
},
135165
},
166+
fields: {
167+
type: 'object',
168+
dynamic: true,
169+
},
136170
observables: {
137171
properties: {
138172
type: {

x-pack/platform/plugins/shared/cases/server/cases_analytics/cases_index/painless_scripts.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ export const CAI_CASES_INDEX_SCRIPT: StoredScript = {
125125
}
126126
}
127127
128+
ctx._source.fields = new HashMap();
129+
if (source.cases.fields != null) {
130+
for (item in source.cases.fields) {
131+
ctx._source.fields[item] = source.cases.fields[item];
132+
}
133+
}
134+
135+
128136
ctx._source.observables = [];
129137
if (source.cases.observables != null) {
130138
for (item in source.cases.observables) {

x-pack/platform/plugins/shared/cases/server/cases_analytics/tasks/scheduler_task/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ export async function scheduleCAISchedulerTask({
7979
id: CAI_SCHEDULER_TASK_ID,
8080
taskType: ANALYTICS_SCHEDULER_TASK_TYPE,
8181
params: {},
82-
runAt: new Date(Date.now() + 60 * 1000),
82+
runAt: new Date(Date.now() + 60 * 1),
8383
schedule: {
84-
interval: '1h',
84+
interval: '1m',
8585
},
8686
state: {},
8787
});

x-pack/platform/plugins/shared/cases/server/cases_analytics/tasks/synchronization_task/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type { Owner } from '../../../../common/constants/types';
1919
import type { CasesServerStartDependencies } from '../../../types';
2020
import { AnalyticsIndexSynchronizationTaskFactory } from './synchronization_task_factory';
2121

22-
const SCHEDULE: IntervalSchedule = { interval: '5m' };
22+
const SCHEDULE: IntervalSchedule = { interval: '1m' };
2323

2424
export function registerCAISynchronizationTask({
2525
taskManager,

x-pack/platform/plugins/shared/cases/server/common/types/case.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface CasePersistedAttributes {
3737
connector: ConnectorPersisted;
3838
description: string;
3939
duration: number | null;
40+
fields: Record<string, unknown>;
4041
external_service: ExternalServicePersisted | null;
4142
owner: string;
4243
settings: { syncAlerts: boolean; extractObservables?: boolean };

x-pack/platform/plugins/shared/cases/server/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export const ConfigSchema = schema.object({
5050
analytics: schema.object({
5151
index: schema.object({
5252
enabled: offeringBasedSchema({
53-
serverless: schema.boolean({ defaultValue: false }),
54-
traditional: schema.boolean({ defaultValue: false }),
53+
serverless: schema.boolean({ defaultValue: true }),
54+
traditional: schema.boolean({ defaultValue: true }),
5555
}),
5656
}),
5757
}),

x-pack/platform/plugins/shared/cases/server/saved_object_types/cases/cases.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
modelVersion6,
2727
modelVersion7,
2828
modelVersion8,
29+
modelVersion9,
2930
} from './model_versions';
3031
import { handleImport } from '../import_export/import';
3132

@@ -38,6 +39,36 @@ export const createCaseSavedObjectType = (
3839
hidden: true,
3940
namespaceType: 'multiple-isolated',
4041
convertToMultiNamespaceTypeVersion: '8.0.0',
42+
dynamic_templates: [
43+
{
44+
as_keyword: {
45+
match_pattern: 'regex',
46+
match: '.*_as_keyword',
47+
mapping: {
48+
type: 'keyword',
49+
ignore_above: 256,
50+
},
51+
},
52+
},
53+
{
54+
as_integer: {
55+
match_pattern: 'regex',
56+
match: '.*_as_integer',
57+
mapping: {
58+
type: 'integer',
59+
},
60+
},
61+
},
62+
{
63+
as_date: {
64+
match_pattern: 'regex',
65+
match: '.*_as_date',
66+
mapping: {
67+
type: 'date',
68+
},
69+
},
70+
},
71+
],
4172
mappings: {
4273
dynamic: false,
4374
properties: {
@@ -271,6 +302,11 @@ export const createCaseSavedObjectType = (
271302
},
272303
},
273304
},
305+
fields: {
306+
// @ts-expect-error - only protected by the typescript type
307+
dynamic: true,
308+
type: 'object',
309+
},
274310
},
275311
},
276312
migrations: caseMigrations,
@@ -283,6 +319,7 @@ export const createCaseSavedObjectType = (
283319
6: modelVersion6,
284320
7: modelVersion7,
285321
8: modelVersion8,
322+
9: modelVersion9,
286323
},
287324
management: {
288325
importableAndExportable: true,

x-pack/platform/plugins/shared/cases/server/saved_object_types/cases/model_versions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export { modelVersion5 } from './model_version_5';
1313
export { modelVersion6 } from './model_version_6';
1414
export { modelVersion7 } from './model_version_7';
1515
export { modelVersion8 } from './model_version_8';
16+
export { modelVersion9 } from './model_version_9';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import type { SavedObjectsModelVersion } from '@kbn/core-saved-objects-server';
9+
import { casesSchemaV9 } from '../schemas';
10+
11+
export const modelVersion9: SavedObjectsModelVersion = {
12+
changes: [
13+
{
14+
type: 'mappings_addition',
15+
addedMappings: {
16+
fields: {
17+
// @ts-expect-error
18+
dynamic: true,
19+
type: 'object',
20+
},
21+
},
22+
},
23+
],
24+
schemas: {
25+
forwardCompatibility: casesSchemaV9.extends({}, { unknowns: 'ignore' }),
26+
},
27+
};

x-pack/platform/plugins/shared/cases/server/saved_object_types/cases/schemas/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export { casesSchema as casesSchemaV5 } from './v5';
1515
export { casesSchema as casesSchemaV6 } from './v6';
1616
export { casesSchema as casesSchemaV7 } from './v7';
1717
export { casesSchema as casesSchemaV8 } from './v8';
18+
export { casesSchema as casesSchemaV9 } from './v9';

0 commit comments

Comments
 (0)