-
Notifications
You must be signed in to change notification settings - Fork 37
/
structs.go
161 lines (131 loc) · 3.69 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright 2013 Belogik. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goes
import (
"net/url"
)
// Represents a Connection object to elasticsearch
type Connection struct {
// The host to connect to
Host string
// The port to use
Port string
}
// Represents a Request to elasticsearch
type Request struct {
// Which connection will be used
Conn *Connection
// A search query
Query interface{}
// Which index to search into
IndexList []string
// Which type to search into
TypeList []string
// HTTP Method to user (GET, POST ...)
method string
// Which api keyword (_search, _bulk, etc) to use
api string
// Bulk data
bulkData []byte
// A list of extra URL arguments
ExtraArgs url.Values
// Used for the id field when indexing a document
id string
}
// Represents a Response from elasticsearch
type Response struct {
Ok bool
Acknowledged bool
Error string
Status uint64
Took uint64
TimedOut bool `json:"timed_out"`
Shards Shard `json:"_shards"`
Hits Hits
Index string `json:"_index"`
Id string `json:"_id"`
Type string `json:"_type"`
Version int `json:"_version"`
Found bool
// Used by the _stats API
All All `json:"_all"`
// Used by the _bulk API
Items []map[string]Item `json:"items,omitempty"`
// Used by the GET API
Exists bool
Source map[string]interface{} `json:"_source"`
Fields map[string]interface{} `json:"fields"`
// Used by the _status API
Indices map[string]IndexStatus
}
// Represents a document to send to elasticsearch
type Document struct {
// XXX : interface as we can support nil values
Index interface{}
Type string
Id interface{}
BulkCommand string
Fields map[string]interface{}
}
// Represents the "items" field in a _bulk response
type Item struct {
Ok bool `json:"ok"`
Type string `json:"_type"`
Id string `json:"_id"`
Index string `json:"_index"`
Version int `json:"_version"`
}
// Represents the "_all" field when calling the _stats API
// This is minimal but this is what I only need
type All struct {
Indices map[string]StatIndex `json:"indices"`
Primaries map[string]StatPrimary `json:"primaries"`
}
type StatIndex struct {
Primaries map[string]StatPrimary `json:"primaries"`
}
type StatPrimary struct {
// primary/docs:
Count int
Deleted int
}
// Represents the "shard" struct as returned by elasticsearch
type Shard struct {
Total uint64
Successful uint64
Failed uint64
}
// Represent a hit returned by a search
type Hit struct {
Index string `json:"_index"`
Type string `json:"_type"`
Id string `json:"_id"`
Score float64 `json:"_score"`
Source map[string]interface{} `json:"_source"`
Fields map[string]interface{} `json:"fields"`
}
// Represent the hits structure as returned by elasticsearch
type Hits struct {
Total uint64
// max_score may contain the "null" value
MaxScore interface{} `json:"max_score"`
Hits []Hit
}
type SearchError struct {
Msg string
StatusCode uint64
}
// Represent the status for a given index for the _status command
type IndexStatus struct {
// XXX : problem, int will be marshaled to a float64 which seems logical
// XXX : is it better to use strings even for int values or to keep
// XXX : interfaces and deal with float64 ?
Index map[string]interface{}
Translog map[string]uint64
Docs map[string]uint64
Merges map[string]interface{}
Refresh map[string]interface{}
Flush map[string]interface{}
// TODO: add shards support later, we do not need it for the moment
}