/
structs.go
59 lines (55 loc) · 1.72 KB
/
structs.go
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
package instance
// Response is the structure of successful Elasticsearch API call.
type Response struct {
ScrollID string `json:"_scroll_id"`
Took int64 `json:"took"`
TimedOut bool `json:"timed_out"`
Shards struct {
Total int64 `json:"total"`
Successful int64 `json:"successful"`
Skipped int64 `json:"skipped"`
Failed int64 `json:"failed"`
} `json:"_shards"`
Hits struct {
Total struct {
Value int64 `json:"value"`
Relation string `json:"relation"`
} `json:"total"`
Hits []map[string]any `json:"hits"`
} `json:"hits"`
Aggregations struct {
LogCount struct {
Buckets []Bucket `json:"buckets"`
} `json:"logcount"`
} `json:"aggregations"`
}
// Bucket is the structure of a bucket returned by the Elasticsearch API.
type Bucket struct {
KeyAsString string `json:"key_as_string"`
Key int64 `json:"key"`
DocCount int64 `json:"doc_count"`
}
// ResponseError is the structure of failed Elasticsearch API call.
type ResponseError struct {
Error struct {
RootCause []struct {
Type string `json:"type"`
Reason string `json:"reason"`
} `json:"root_cause"`
Type string `json:"type"`
Reason string `json:"reason"`
CausedBy struct {
Type string `json:"type"`
Reason string `json:"reason"`
} `json:"caused_by"`
} `json:"error"`
Status int `json:"status"`
}
// Data is the transformed Response result, which is passed to the React UI. It contains only the important fields, like
// the time a request took, the number of hits, the documents and the buckets.
type Data struct {
Took int64 `json:"took"`
Hits int64 `json:"hits"`
Documents []map[string]any `json:"documents"`
Buckets []Bucket `json:"buckets"`
}