@@ -26,15 +26,18 @@ type QuickwitDatasource struct {
26
26
dsInfo es.DatasourceInfo
27
27
}
28
28
29
+ type FieldMappings struct {
30
+ Name string `json:"name"`
31
+ Type string `json:"type"`
32
+ OutputFormat * string `json:"output_format,omitempty"`
33
+ FieldMappings []FieldMappings `json:"field_mappings,omitempty"`
34
+ }
35
+
29
36
type QuickwitMapping struct {
30
37
IndexConfig struct {
31
38
DocMapping struct {
32
- TimestampField string `json:"timestamp_field"`
33
- FieldMappings []struct {
34
- Name string `json:"name"`
35
- Type string `json:"type"`
36
- OutputFormat * string `json:"output_format,omitempty"`
37
- } `json:"field_mappings"`
39
+ TimestampField string `json:"timestamp_field"`
40
+ FieldMappings []FieldMappings `json:"field_mappings"`
38
41
} `json:"doc_mapping"`
39
42
} `json:"index_config"`
40
43
}
@@ -56,6 +59,27 @@ func newErrorCreationPayload(statusCode int, message string) error {
56
59
return errors .New (string (json ))
57
60
}
58
61
62
+ func findTimeStampFormat (timestampFieldName string , parentName * string , fieldMappings []FieldMappings ) * string {
63
+ if nil == fieldMappings {
64
+ return nil
65
+ }
66
+
67
+ for _ , field := range fieldMappings {
68
+ fieldName := field .Name
69
+ if nil != parentName {
70
+ fieldName = fmt .Sprintf ("%s.%s" , * parentName , fieldName )
71
+ }
72
+
73
+ if field .Type == "datetime" && fieldName == timestampFieldName && nil != field .OutputFormat {
74
+ return field .OutputFormat
75
+ } else if field .Type == "object" && nil != field .FieldMappings {
76
+ return findTimeStampFormat (timestampFieldName , & field .Name , field .FieldMappings )
77
+ }
78
+ }
79
+
80
+ return nil
81
+ }
82
+
59
83
func getTimestampFieldInfos (index string , qwUrl string , cli * http.Client ) (string , string , error ) {
60
84
mappingEndpointUrl := qwUrl + "/indexes/" + index
61
85
qwlog .Info ("Calling quickwit endpoint: " + mappingEndpointUrl )
@@ -91,22 +115,16 @@ func getTimestampFieldInfos(index string, qwUrl string, cli *http.Client) (strin
91
115
}
92
116
93
117
timestampFieldName := payload .IndexConfig .DocMapping .TimestampField
94
- timestampFieldFormat := "undef"
95
- for _ , field := range payload .IndexConfig .DocMapping .FieldMappings {
96
- if field .Type == "datetime" && field .Name == timestampFieldName && nil != field .OutputFormat {
97
- timestampFieldFormat = * field .OutputFormat
98
- break
99
- }
100
- }
118
+ timestampFieldFormat := findTimeStampFormat (timestampFieldName , nil , payload .IndexConfig .DocMapping .FieldMappings )
101
119
102
- if timestampFieldFormat == "undef" {
120
+ if nil == timestampFieldFormat {
103
121
errMsg := fmt .Sprintf ("No format found for field: %s" , string (timestampFieldName ))
104
122
qwlog .Error (errMsg )
105
123
return timestampFieldName , "" , newErrorCreationPayload (statusCode , errMsg )
106
124
}
107
125
108
- qwlog .Info (fmt .Sprintf ("Found timestampFieldName = %s, timestampFieldFormat = %s" , timestampFieldName , timestampFieldFormat ))
109
- return timestampFieldName , timestampFieldFormat , nil
126
+ qwlog .Info (fmt .Sprintf ("Found timestampFieldName = %s, timestampFieldFormat = %s" , timestampFieldName , * timestampFieldFormat ))
127
+ return timestampFieldName , * timestampFieldFormat , nil
110
128
}
111
129
112
130
// Creates a Quickwit datasource.
0 commit comments