-
Notifications
You must be signed in to change notification settings - Fork 626
/
Copy pathrequest.go
executable file
·247 lines (206 loc) · 8.86 KB
/
request.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// Code generated from the elasticsearch-specification DO NOT EDIT.
// https://github.com/elastic/elasticsearch-specification/tree/93ed2b29c9e75f49cd340f06286d6ead5965f900
package putdatafeed
import (
"encoding/json"
"fmt"
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
)
// Request holds the request body struct for the package putdatafeed
//
// https://github.com/elastic/elasticsearch-specification/blob/93ed2b29c9e75f49cd340f06286d6ead5965f900/specification/ml/put_datafeed/MlPutDatafeedRequest.ts#L37-L171
type Request struct {
// Aggregations If set, the datafeed performs aggregation searches.
// Support for aggregations is limited and should be used only with low
// cardinality data.
Aggregations map[string]types.AggregationContainer `json:"aggregations,omitempty"`
// ChunkingConfig Datafeeds might be required to search over long time periods, for several
// months or years.
// This search is split into time chunks in order to ensure the load on
// Elasticsearch is managed.
// Chunking configuration controls how the size of these time chunks are
// calculated;
// it is an advanced configuration option.
ChunkingConfig *types.ChunkingConfig `json:"chunking_config,omitempty"`
// DelayedDataCheckConfig Specifies whether the datafeed checks for missing data and the size of the
// window.
// The datafeed can optionally search over indices that have already been read
// in an effort to determine whether
// any data has subsequently been added to the index. If missing data is found,
// it is a good indication that the
// `query_delay` is set too low and the data is being indexed after the datafeed
// has passed that moment in time.
// This check runs only on real-time datafeeds.
DelayedDataCheckConfig *types.DelayedDataCheckConfig `json:"delayed_data_check_config,omitempty"`
// Frequency The interval at which scheduled queries are made while the datafeed runs in
// real time.
// The default value is either the bucket span for short bucket spans, or, for
// longer bucket spans, a sensible
// fraction of the bucket span. When `frequency` is shorter than the bucket
// span, interim results for the last
// (partial) bucket are written then eventually overwritten by the full bucket
// results. If the datafeed uses
// aggregations, this value must be divisible by the interval of the date
// histogram aggregation.
Frequency *types.Duration `json:"frequency,omitempty"`
Headers *types.HttpHeaders `json:"headers,omitempty"`
// Indices An array of index names. Wildcards are supported. If any of the indices are
// in remote clusters, the machine
// learning nodes must have the `remote_cluster_client` role.
Indices *types.Indices `json:"indices,omitempty"`
// IndicesOptions Specifies index expansion options that are used during search
IndicesOptions *types.IndicesOptions `json:"indices_options,omitempty"`
// JobId Identifier for the anomaly detection job.
JobId *types.Id `json:"job_id,omitempty"`
// MaxEmptySearches If a real-time datafeed has never seen any data (including during any initial
// training period), it automatically
// stops and closes the associated job after this many real-time searches return
// no documents. In other words,
// it stops after `frequency` times `max_empty_searches` of real-time operation.
// If not set, a datafeed with no
// end time that sees no data remains started until it is explicitly stopped. By
// default, it is not set.
MaxEmptySearches *int `json:"max_empty_searches,omitempty"`
// Query The Elasticsearch query domain-specific language (DSL). This value
// corresponds to the query object in an
// Elasticsearch search POST body. All the options that are supported by
// Elasticsearch can be used, as this
// object is passed verbatim to Elasticsearch.
Query *types.QueryContainer `json:"query,omitempty"`
// QueryDelay The number of seconds behind real time that data is queried. For example, if
// data from 10:04 a.m. might
// not be searchable in Elasticsearch until 10:06 a.m., set this property to 120
// seconds. The default
// value is randomly selected between `60s` and `120s`. This randomness improves
// the query performance
// when there are multiple jobs running on the same node.
QueryDelay *types.Duration `json:"query_delay,omitempty"`
// RuntimeMappings Specifies runtime fields for the datafeed search.
RuntimeMappings *types.RuntimeFields `json:"runtime_mappings,omitempty"`
// ScriptFields Specifies scripts that evaluate custom expressions and returns script fields
// to the datafeed.
// The detector configuration objects in a job can contain functions that use
// these script fields.
ScriptFields map[string]types.ScriptField `json:"script_fields,omitempty"`
// ScrollSize The size parameter that is used in Elasticsearch searches when the datafeed
// does not use aggregations.
// The maximum value is the value of `index.max_result_window`, which is 10,000
// by default.
ScrollSize *int `json:"scroll_size,omitempty"`
}
// RequestBuilder is the builder API for the putdatafeed.Request
type RequestBuilder struct {
v *Request
}
// NewRequest returns a RequestBuilder which can be chained and built to retrieve a RequestBuilder
func NewRequestBuilder() *RequestBuilder {
r := RequestBuilder{
&Request{
Aggregations: make(map[string]types.AggregationContainer, 0),
ScriptFields: make(map[string]types.ScriptField, 0),
},
}
return &r
}
// FromJSON allows to load an arbitrary json into the request structure
func (rb *RequestBuilder) FromJSON(data string) (*Request, error) {
var req Request
err := json.Unmarshal([]byte(data), &req)
if err != nil {
return nil, fmt.Errorf("could not deserialise json into Putdatafeed request: %w", err)
}
return &req, nil
}
// Build finalize the chain and returns the Request struct.
func (rb *RequestBuilder) Build() *Request {
return rb.v
}
func (rb *RequestBuilder) Aggregations(values map[string]*types.AggregationContainerBuilder) *RequestBuilder {
tmp := make(map[string]types.AggregationContainer, len(values))
for key, builder := range values {
tmp[key] = builder.Build()
}
rb.v.Aggregations = tmp
return rb
}
func (rb *RequestBuilder) ChunkingConfig(chunkingconfig *types.ChunkingConfigBuilder) *RequestBuilder {
v := chunkingconfig.Build()
rb.v.ChunkingConfig = &v
return rb
}
func (rb *RequestBuilder) DelayedDataCheckConfig(delayeddatacheckconfig *types.DelayedDataCheckConfigBuilder) *RequestBuilder {
v := delayeddatacheckconfig.Build()
rb.v.DelayedDataCheckConfig = &v
return rb
}
func (rb *RequestBuilder) Frequency(frequency *types.DurationBuilder) *RequestBuilder {
v := frequency.Build()
rb.v.Frequency = &v
return rb
}
func (rb *RequestBuilder) Headers(headers *types.HttpHeadersBuilder) *RequestBuilder {
v := headers.Build()
rb.v.Headers = &v
return rb
}
func (rb *RequestBuilder) Indices(indices *types.IndicesBuilder) *RequestBuilder {
v := indices.Build()
rb.v.Indices = &v
return rb
}
func (rb *RequestBuilder) IndicesOptions(indicesoptions *types.IndicesOptionsBuilder) *RequestBuilder {
v := indicesoptions.Build()
rb.v.IndicesOptions = &v
return rb
}
func (rb *RequestBuilder) JobId(jobid types.Id) *RequestBuilder {
rb.v.JobId = &jobid
return rb
}
func (rb *RequestBuilder) MaxEmptySearches(maxemptysearches int) *RequestBuilder {
rb.v.MaxEmptySearches = &maxemptysearches
return rb
}
func (rb *RequestBuilder) Query(query *types.QueryContainerBuilder) *RequestBuilder {
v := query.Build()
rb.v.Query = &v
return rb
}
func (rb *RequestBuilder) QueryDelay(querydelay *types.DurationBuilder) *RequestBuilder {
v := querydelay.Build()
rb.v.QueryDelay = &v
return rb
}
func (rb *RequestBuilder) RuntimeMappings(runtimemappings *types.RuntimeFieldsBuilder) *RequestBuilder {
v := runtimemappings.Build()
rb.v.RuntimeMappings = &v
return rb
}
func (rb *RequestBuilder) ScriptFields(values map[string]*types.ScriptFieldBuilder) *RequestBuilder {
tmp := make(map[string]types.ScriptField, len(values))
for key, builder := range values {
tmp[key] = builder.Build()
}
rb.v.ScriptFields = tmp
return rb
}
func (rb *RequestBuilder) ScrollSize(scrollsize int) *RequestBuilder {
rb.v.ScrollSize = &scrollsize
return rb
}