-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathmappings.ts
73 lines (59 loc) · 1.84 KB
/
mappings.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { Field } from '../../fields/field';
const DEFAULT_SCALING_FACTOR = 1000;
const DEFAULT_IGNORE_ABOVE = 1024;
interface Properties {
[key: string]: any;
}
export function getDefaultProperties(field: Field): Properties {
const properties: Properties = {};
if (field.index !== undefined) {
properties.index = field.index;
}
if (field.doc_values !== undefined) {
properties.doc_values = field.doc_values;
}
if (field.copy_to) {
properties.copy_to = field.copy_to;
}
return properties;
}
export function scaledFloat(field: Field): Properties {
const fieldProps = getDefaultProperties(field);
fieldProps.type = 'scaled_float';
fieldProps.scaling_factor = field.scaling_factor || DEFAULT_SCALING_FACTOR;
if (field.metric_type) {
fieldProps.time_series_metric = field.metric_type;
}
return fieldProps;
}
export function histogram(field: Field): Properties {
const fieldProps = getDefaultProperties(field);
fieldProps.type = 'histogram';
return fieldProps;
}
export function keyword(field: Field): Properties {
const fieldProps = getDefaultProperties(field);
fieldProps.type = 'keyword';
if (field.ignore_above) {
fieldProps.ignore_above = field.ignore_above;
} else {
fieldProps.ignore_above = DEFAULT_IGNORE_ABOVE;
}
if (field.normalizer) {
fieldProps.normalizer = field.normalizer;
}
if (field.dimension) {
fieldProps.time_series_dimension = field.dimension;
delete fieldProps.ignore_above;
}
if (field.index === false || field.doc_values === false) {
delete fieldProps.ignore_above;
}
return fieldProps;
}