@@ -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,22 @@ func newErrorCreationPayload(statusCode int, message string) error {
56
59
return errors .New (string (json ))
57
60
}
58
61
62
+ func findTimeStampFormat (timestampFieldName string , fieldMappings []FieldMappings ) * string {
63
+ if nil == fieldMappings {
64
+ return nil
65
+ }
66
+
67
+ for _ , field := range fieldMappings {
68
+ if field .Type == "datetime" && field .Name == timestampFieldName && nil != field .OutputFormat {
69
+ return field .OutputFormat
70
+ } else if field .Type == "object" && nil != field .FieldMappings {
71
+ return findTimeStampFormat (timestampFieldName , field .FieldMappings )
72
+ }
73
+ }
74
+
75
+ return nil
76
+ }
77
+
59
78
func getTimestampFieldInfos (index string , qwUrl string , cli * http.Client ) (string , string , error ) {
60
79
mappingEndpointUrl := qwUrl + "/indexes/" + index
61
80
qwlog .Info ("Calling quickwit endpoint: " + mappingEndpointUrl )
@@ -91,22 +110,16 @@ func getTimestampFieldInfos(index string, qwUrl string, cli *http.Client) (strin
91
110
}
92
111
93
112
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
- }
113
+ timestampFieldFormat := findTimeStampFormat (timestampFieldName , payload .IndexConfig .DocMapping .FieldMappings )
101
114
102
- if timestampFieldFormat == "undef" {
115
+ if nil == timestampFieldFormat {
103
116
errMsg := fmt .Sprintf ("No format found for field: %s" , string (timestampFieldName ))
104
117
qwlog .Error (errMsg )
105
118
return timestampFieldName , "" , newErrorCreationPayload (statusCode , errMsg )
106
119
}
107
120
108
- qwlog .Info (fmt .Sprintf ("Found timestampFieldName = %s, timestampFieldFormat = %s" , timestampFieldName , timestampFieldFormat ))
109
- return timestampFieldName , timestampFieldFormat , nil
121
+ qwlog .Info (fmt .Sprintf ("Found timestampFieldName = %s, timestampFieldFormat = %s" , timestampFieldName , * timestampFieldFormat ))
122
+ return timestampFieldName , * timestampFieldFormat , nil
110
123
}
111
124
112
125
// Creates a Quickwit datasource.
0 commit comments