| 1 |
// Copyright 2012-present Oliver Eilhard. All rights reserved. |
| 2 |
// Use of this source code is governed by a MIT-license. |
| 3 |
// See http://olivere.mit-license.org/license.txt for details. |
| 4 |
|
| 5 |
package elastic |
| 6 |
|
| 7 |
import ( |
| 8 |
"bytes" |
| 9 |
"encoding/json" |
| 10 |
) |
| 11 |
|
| 12 |
// Aggregations can be seen as a unit-of-work that build |
| 13 |
// analytic information over a set of documents. It is |
| 14 |
// (in many senses) the follow-up of facets in Elasticsearch. |
| 15 |
// For more details about aggregations, visit: |
| 16 |
// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations.html |
| 17 |
type Aggregation interface { |
| 18 |
// Source returns a JSON-serializable aggregation that is a fragment |
| 19 |
// of the request sent to Elasticsearch. |
| 20 |
Source() (interface{}, error) |
| 21 |
} |
| 22 |
|
| 23 |
// Aggregations is a list of aggregations that are part of a search result. |
| 24 |
type Aggregations map[string]*json.RawMessage |
| 25 |
|
| 26 |
// Min returns min aggregation results. |
| 27 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-min-aggregation.html |
| 28 |
func (a Aggregations) Min(name string) (*AggregationValueMetric, bool) { |
| 29 |
if raw, found := a[name]; found { |
| 30 |
agg := new(AggregationValueMetric) |
| 31 |
if raw == nil { |
| 32 |
return agg, true |
| 33 |
} |
| 34 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 35 |
return agg, true |
| 36 |
} |
| 37 |
} |
| 38 |
return nil, false |
| 39 |
} |
| 40 |
|
| 41 |
// Max returns max aggregation results. |
| 42 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-max-aggregation.html |
| 43 |
func (a Aggregations) Max(name string) (*AggregationValueMetric, bool) { |
| 44 |
if raw, found := a[name]; found { |
| 45 |
agg := new(AggregationValueMetric) |
| 46 |
if raw == nil { |
| 47 |
return agg, true |
| 48 |
} |
| 49 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 50 |
return agg, true |
| 51 |
} |
| 52 |
} |
| 53 |
return nil, false |
| 54 |
} |
| 55 |
|
| 56 |
// Sum returns sum aggregation results. |
| 57 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-sum-aggregation.html |
| 58 |
func (a Aggregations) Sum(name string) (*AggregationValueMetric, bool) { |
| 59 |
if raw, found := a[name]; found { |
| 60 |
agg := new(AggregationValueMetric) |
| 61 |
if raw == nil { |
| 62 |
return agg, true |
| 63 |
} |
| 64 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 65 |
return agg, true |
| 66 |
} |
| 67 |
} |
| 68 |
return nil, false |
| 69 |
} |
| 70 |
|
| 71 |
// Avg returns average aggregation results. |
| 72 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-avg-aggregation.html |
| 73 |
func (a Aggregations) Avg(name string) (*AggregationValueMetric, bool) { |
| 74 |
if raw, found := a[name]; found { |
| 75 |
agg := new(AggregationValueMetric) |
| 76 |
if raw == nil { |
| 77 |
return agg, true |
| 78 |
} |
| 79 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 80 |
return agg, true |
| 81 |
} |
| 82 |
} |
| 83 |
return nil, false |
| 84 |
} |
| 85 |
|
| 86 |
// ValueCount returns value-count aggregation results. |
| 87 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-valuecount-aggregation.html |
| 88 |
func (a Aggregations) ValueCount(name string) (*AggregationValueMetric, bool) { |
| 89 |
if raw, found := a[name]; found { |
| 90 |
agg := new(AggregationValueMetric) |
| 91 |
if raw == nil { |
| 92 |
return agg, true |
| 93 |
} |
| 94 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 95 |
return agg, true |
| 96 |
} |
| 97 |
} |
| 98 |
return nil, false |
| 99 |
} |
| 100 |
|
| 101 |
// Cardinality returns cardinality aggregation results. |
| 102 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-cardinality-aggregation.html |
| 103 |
func (a Aggregations) Cardinality(name string) (*AggregationValueMetric, bool) { |
| 104 |
if raw, found := a[name]; found { |
| 105 |
agg := new(AggregationValueMetric) |
| 106 |
if raw == nil { |
| 107 |
return agg, true |
| 108 |
} |
| 109 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 110 |
return agg, true |
| 111 |
} |
| 112 |
} |
| 113 |
return nil, false |
| 114 |
} |
| 115 |
|
| 116 |
// Stats returns stats aggregation results. |
| 117 |
// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-stats-aggregation.html |
| 118 |
func (a Aggregations) Stats(name string) (*AggregationStatsMetric, bool) { |
| 119 |
if raw, found := a[name]; found { |
| 120 |
agg := new(AggregationStatsMetric) |
| 121 |
if raw == nil { |
| 122 |
return agg, true |
| 123 |
} |
| 124 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 125 |
return agg, true |
| 126 |
} |
| 127 |
} |
| 128 |
return nil, false |
| 129 |
} |
| 130 |
|
| 131 |
// ExtendedStats returns extended stats aggregation results. |
| 132 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-extendedstats-aggregation.html |
| 133 |
func (a Aggregations) ExtendedStats(name string) (*AggregationExtendedStatsMetric, bool) { |
| 134 |
if raw, found := a[name]; found { |
| 135 |
agg := new(AggregationExtendedStatsMetric) |
| 136 |
if raw == nil { |
| 137 |
return agg, true |
| 138 |
} |
| 139 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 140 |
return agg, true |
| 141 |
} |
| 142 |
} |
| 143 |
return nil, false |
| 144 |
} |
| 145 |
|
| 146 |
// MatrixStats returns matrix stats aggregation results. |
| 147 |
// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-matrix-stats-aggregation.html |
| 148 |
func (a Aggregations) MatrixStats(name string) (*AggregationMatrixStats, bool) { |
| 149 |
if raw, found := a[name]; found { |
| 150 |
agg := new(AggregationMatrixStats) |
| 151 |
if raw == nil { |
| 152 |
return agg, true |
| 153 |
} |
| 154 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 155 |
return agg, true |
| 156 |
} |
| 157 |
} |
| 158 |
return nil, false |
| 159 |
} |
| 160 |
|
| 161 |
// Percentiles returns percentiles results. |
| 162 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-percentile-aggregation.html |
| 163 |
func (a Aggregations) Percentiles(name string) (*AggregationPercentilesMetric, bool) { |
| 164 |
if raw, found := a[name]; found { |
| 165 |
agg := new(AggregationPercentilesMetric) |
| 166 |
if raw == nil { |
| 167 |
return agg, true |
| 168 |
} |
| 169 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 170 |
return agg, true |
| 171 |
} |
| 172 |
} |
| 173 |
return nil, false |
| 174 |
} |
| 175 |
|
| 176 |
// PercentileRanks returns percentile ranks results. |
| 177 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-percentile-rank-aggregation.html |
| 178 |
func (a Aggregations) PercentileRanks(name string) (*AggregationPercentilesMetric, bool) { |
| 179 |
if raw, found := a[name]; found { |
| 180 |
agg := new(AggregationPercentilesMetric) |
| 181 |
if raw == nil { |
| 182 |
return agg, true |
| 183 |
} |
| 184 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 185 |
return agg, true |
| 186 |
} |
| 187 |
} |
| 188 |
return nil, false |
| 189 |
} |
| 190 |
|
| 191 |
// TopHits returns top-hits aggregation results. |
| 192 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-top-hits-aggregation.html |
| 193 |
func (a Aggregations) TopHits(name string) (*AggregationTopHitsMetric, bool) { |
| 194 |
if raw, found := a[name]; found { |
| 195 |
agg := new(AggregationTopHitsMetric) |
| 196 |
if raw == nil { |
| 197 |
return agg, true |
| 198 |
} |
| 199 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 200 |
return agg, true |
| 201 |
} |
| 202 |
} |
| 203 |
return nil, false |
| 204 |
} |
| 205 |
|
| 206 |
// Global returns global results. |
| 207 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-global-aggregation.html |
| 208 |
func (a Aggregations) Global(name string) (*AggregationSingleBucket, bool) { |
| 209 |
if raw, found := a[name]; found { |
| 210 |
agg := new(AggregationSingleBucket) |
| 211 |
if raw == nil { |
| 212 |
return agg, true |
| 213 |
} |
| 214 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 215 |
return agg, true |
| 216 |
} |
| 217 |
} |
| 218 |
return nil, false |
| 219 |
} |
| 220 |
|
| 221 |
// Filter returns filter results. |
| 222 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-filter-aggregation.html |
| 223 |
func (a Aggregations) Filter(name string) (*AggregationSingleBucket, bool) { |
| 224 |
if raw, found := a[name]; found { |
| 225 |
agg := new(AggregationSingleBucket) |
| 226 |
if raw == nil { |
| 227 |
return agg, true |
| 228 |
} |
| 229 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 230 |
return agg, true |
| 231 |
} |
| 232 |
} |
| 233 |
return nil, false |
| 234 |
} |
| 235 |
|
| 236 |
// Filters returns filters results. |
| 237 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-filters-aggregation.html |
| 238 |
func (a Aggregations) Filters(name string) (*AggregationBucketFilters, bool) { |
| 239 |
if raw, found := a[name]; found { |
| 240 |
agg := new(AggregationBucketFilters) |
| 241 |
if raw == nil { |
| 242 |
return agg, true |
| 243 |
} |
| 244 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 245 |
return agg, true |
| 246 |
} |
| 247 |
} |
| 248 |
return nil, false |
| 249 |
} |
| 250 |
|
| 251 |
// AdjacencyMatrix returning a form of adjacency matrix. |
| 252 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-adjacency-matrix-aggregation.html |
| 253 |
func (a Aggregations) AdjacencyMatrix(name string) (*AggregationBucketAdjacencyMatrix, bool) { |
| 254 |
if raw, found := a[name]; found { |
| 255 |
agg := new(AggregationBucketAdjacencyMatrix) |
| 256 |
if raw == nil { |
| 257 |
return agg, true |
| 258 |
} |
| 259 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 260 |
return agg, true |
| 261 |
} |
| 262 |
} |
| 263 |
return nil, false |
| 264 |
} |
| 265 |
|
| 266 |
// Missing returns missing results. |
| 267 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-missing-aggregation.html |
| 268 |
func (a Aggregations) Missing(name string) (*AggregationSingleBucket, bool) { |
| 269 |
if raw, found := a[name]; found { |
| 270 |
agg := new(AggregationSingleBucket) |
| 271 |
if raw == nil { |
| 272 |
return agg, true |
| 273 |
} |
| 274 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 275 |
return agg, true |
| 276 |
} |
| 277 |
} |
| 278 |
return nil, false |
| 279 |
} |
| 280 |
|
| 281 |
// Nested returns nested results. |
| 282 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-nested-aggregation.html |
| 283 |
func (a Aggregations) Nested(name string) (*AggregationSingleBucket, bool) { |
| 284 |
if raw, found := a[name]; found { |
| 285 |
agg := new(AggregationSingleBucket) |
| 286 |
if raw == nil { |
| 287 |
return agg, true |
| 288 |
} |
| 289 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 290 |
return agg, true |
| 291 |
} |
| 292 |
} |
| 293 |
return nil, false |
| 294 |
} |
| 295 |
|
| 296 |
// ReverseNested returns reverse-nested results. |
| 297 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-reverse-nested-aggregation.html |
| 298 |
func (a Aggregations) ReverseNested(name string) (*AggregationSingleBucket, bool) { |
| 299 |
if raw, found := a[name]; found { |
| 300 |
agg := new(AggregationSingleBucket) |
| 301 |
if raw == nil { |
| 302 |
return agg, true |
| 303 |
} |
| 304 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 305 |
return agg, true |
| 306 |
} |
| 307 |
} |
| 308 |
return nil, false |
| 309 |
} |
| 310 |
|
| 311 |
// Children returns children results. |
| 312 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-children-aggregation.html |
| 313 |
func (a Aggregations) Children(name string) (*AggregationSingleBucket, bool) { |
| 314 |
if raw, found := a[name]; found { |
| 315 |
agg := new(AggregationSingleBucket) |
| 316 |
if raw == nil { |
| 317 |
return agg, true |
| 318 |
} |
| 319 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 320 |
return agg, true |
| 321 |
} |
| 322 |
} |
| 323 |
return nil, false |
| 324 |
} |
| 325 |
|
| 326 |
// Terms returns terms aggregation results. |
| 327 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-terms-aggregation.html |
| 328 |
func (a Aggregations) Terms(name string) (*AggregationBucketKeyItems, bool) { |
| 329 |
if raw, found := a[name]; found { |
| 330 |
agg := new(AggregationBucketKeyItems) |
| 331 |
if raw == nil { |
| 332 |
return agg, true |
| 333 |
} |
| 334 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 335 |
return agg, true |
| 336 |
} |
| 337 |
} |
| 338 |
return nil, false |
| 339 |
} |
| 340 |
|
| 341 |
// SignificantTerms returns significant terms aggregation results. |
| 342 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-significantterms-aggregation.html |
| 343 |
func (a Aggregations) SignificantTerms(name string) (*AggregationBucketSignificantTerms, bool) { |
| 344 |
if raw, found := a[name]; found { |
| 345 |
agg := new(AggregationBucketSignificantTerms) |
| 346 |
if raw == nil { |
| 347 |
return agg, true |
| 348 |
} |
| 349 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 350 |
return agg, true |
| 351 |
} |
| 352 |
} |
| 353 |
return nil, false |
| 354 |
} |
| 355 |
|
| 356 |
// Sampler returns sampler aggregation results. |
| 357 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-sampler-aggregation.html |
| 358 |
func (a Aggregations) Sampler(name string) (*AggregationSingleBucket, bool) { |
| 359 |
if raw, found := a[name]; found { |
| 360 |
agg := new(AggregationSingleBucket) |
| 361 |
if raw == nil { |
| 362 |
return agg, true |
| 363 |
} |
| 364 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 365 |
return agg, true |
| 366 |
} |
| 367 |
} |
| 368 |
return nil, false |
| 369 |
} |
| 370 |
|
| 371 |
// DiversifiedSampler returns diversified_sampler aggregation results. |
| 372 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-diversified-sampler-aggregation.html |
| 373 |
func (a Aggregations) DiversifiedSampler(name string) (*AggregationSingleBucket, bool) { |
| 374 |
if raw, found := a[name]; found { |
| 375 |
agg := new(AggregationSingleBucket) |
| 376 |
if raw == nil { |
| 377 |
return agg, true |
| 378 |
} |
| 379 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 380 |
return agg, true |
| 381 |
} |
| 382 |
} |
| 383 |
return nil, false |
| 384 |
} |
| 385 |
|
| 386 |
// Range returns range aggregation results. |
| 387 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-range-aggregation.html |
| 388 |
func (a Aggregations) Range(name string) (*AggregationBucketRangeItems, bool) { |
| 389 |
if raw, found := a[name]; found { |
| 390 |
agg := new(AggregationBucketRangeItems) |
| 391 |
if raw == nil { |
| 392 |
return agg, true |
| 393 |
} |
| 394 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 395 |
return agg, true |
| 396 |
} |
| 397 |
} |
| 398 |
return nil, false |
| 399 |
} |
| 400 |
|
| 401 |
// KeyedRange returns keyed range aggregation results. |
| 402 |
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-range-aggregation.html. |
| 403 |
func (a Aggregations) KeyedRange(name string) (*AggregationBucketKeyedRangeItems, bool) { |
| 404 |
if raw, found := a[name]; found { |
| 405 |
agg := new(AggregationBucketKeyedRangeItems) |
| 406 |
if raw == nil { |
| 407 |
return agg, true |
| 408 |
} |
| 409 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 410 |
return agg, true |
| 411 |
} |
| 412 |
} |
| 413 |
return nil, false |
| 414 |
} |
| 415 |
|
| 416 |
// DateRange returns date range aggregation results. |
| 417 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-daterange-aggregation.html |
| 418 |
func (a Aggregations) DateRange(name string) (*AggregationBucketRangeItems, bool) { |
| 419 |
if raw, found := a[name]; found { |
| 420 |
agg := new(AggregationBucketRangeItems) |
| 421 |
if raw == nil { |
| 422 |
return agg, true |
| 423 |
} |
| 424 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 425 |
return agg, true |
| 426 |
} |
| 427 |
} |
| 428 |
return nil, false |
| 429 |
} |
| 430 |
|
| 431 |
// IPRange returns IP range aggregation results. |
| 432 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-iprange-aggregation.html |
| 433 |
func (a Aggregations) IPRange(name string) (*AggregationBucketRangeItems, bool) { |
| 434 |
if raw, found := a[name]; found { |
| 435 |
agg := new(AggregationBucketRangeItems) |
| 436 |
if raw == nil { |
| 437 |
return agg, true |
| 438 |
} |
| 439 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 440 |
return agg, true |
| 441 |
} |
| 442 |
} |
| 443 |
return nil, false |
| 444 |
} |
| 445 |
|
| 446 |
// Histogram returns histogram aggregation results. |
| 447 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-histogram-aggregation.html |
| 448 |
func (a Aggregations) Histogram(name string) (*AggregationBucketHistogramItems, bool) { |
| 449 |
if raw, found := a[name]; found { |
| 450 |
agg := new(AggregationBucketHistogramItems) |
| 451 |
if raw == nil { |
| 452 |
return agg, true |
| 453 |
} |
| 454 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 455 |
return agg, true |
| 456 |
} |
| 457 |
} |
| 458 |
return nil, false |
| 459 |
} |
| 460 |
|
| 461 |
// DateHistogram returns date histogram aggregation results. |
| 462 |
// |
| 463 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-datehistogram-aggregation.html |
| 464 |
func (a Aggregations) DateHistogram(name string) (*AggregationBucketHistogramItems, bool) { |
| 465 |
if raw, found := a[name]; found { |
| 466 |
agg := new(AggregationBucketHistogramItems) |
| 467 |
if raw == nil { |
| 468 |
return agg, true |
| 469 |
} |
| 470 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 471 |
return agg, true |
| 472 |
} |
| 473 |
} |
| 474 |
return nil, false |
| 475 |
} |
| 476 |
|
| 477 |
// KeyedDateHistogram returns date histogram aggregation results for keyed responses. |
| 478 |
// |
| 479 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-datehistogram-aggregation.html#_keyed_response_3 |
| 480 |
func (a Aggregations) KeyedDateHistogram(name string) (*AggregationBucketKeyedHistogramItems, bool) { |
| 481 |
if raw, found := a[name]; found { |
| 482 |
agg := new(AggregationBucketKeyedHistogramItems) |
| 483 |
if raw == nil { |
| 484 |
return agg, true |
| 485 |
} |
| 486 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 487 |
return agg, true |
| 488 |
} |
| 489 |
} |
| 490 |
return nil, false |
| 491 |
} |
| 492 |
|
| 493 |
// GeoBounds returns geo-bounds aggregation results. |
| 494 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-geobounds-aggregation.html |
| 495 |
func (a Aggregations) GeoBounds(name string) (*AggregationGeoBoundsMetric, bool) { |
| 496 |
if raw, found := a[name]; found { |
| 497 |
agg := new(AggregationGeoBoundsMetric) |
| 498 |
if raw == nil { |
| 499 |
return agg, true |
| 500 |
} |
| 501 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 502 |
return agg, true |
| 503 |
} |
| 504 |
} |
| 505 |
return nil, false |
| 506 |
} |
| 507 |
|
| 508 |
// GeoHash returns geo-hash aggregation results. |
| 509 |
// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-geohashgrid-aggregation.html |
| 510 |
func (a Aggregations) GeoHash(name string) (*AggregationBucketKeyItems, bool) { |
| 511 |
if raw, found := a[name]; found { |
| 512 |
agg := new(AggregationBucketKeyItems) |
| 513 |
if raw == nil { |
| 514 |
return agg, true |
| 515 |
} |
| 516 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 517 |
return agg, true |
| 518 |
} |
| 519 |
} |
| 520 |
return nil, false |
| 521 |
} |
| 522 |
|
| 523 |
// GeoCentroid returns geo-centroid aggregation results. |
| 524 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-geocentroid-aggregation.html |
| 525 |
func (a Aggregations) GeoCentroid(name string) (*AggregationGeoCentroidMetric, bool) { |
| 526 |
if raw, found := a[name]; found { |
| 527 |
agg := new(AggregationGeoCentroidMetric) |
| 528 |
if raw == nil { |
| 529 |
return agg, true |
| 530 |
} |
| 531 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 532 |
return agg, true |
| 533 |
} |
| 534 |
} |
| 535 |
return nil, false |
| 536 |
} |
| 537 |
|
| 538 |
// GeoDistance returns geo distance aggregation results. |
| 539 |
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-geodistance-aggregation.html |
| 540 |
func (a Aggregations) GeoDistance(name string) (*AggregationBucketRangeItems, bool) { |
| 541 |
if raw, found := a[name]; found { |
| 542 |
agg := new(AggregationBucketRangeItems) |
| 543 |
if raw == nil { |
| 544 |
return agg, true |
| 545 |
} |
| 546 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 547 |
return agg, true |
| 548 |
} |
| 549 |
} |
| 550 |
return nil, false |
| 551 |
} |
| 552 |
|
| 553 |
// AvgBucket returns average bucket pipeline aggregation results. |
| 554 |
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-avg-bucket-aggregation.html |
| 555 |
func (a Aggregations) AvgBucket(name string) (*AggregationPipelineSimpleValue, bool) { |
| 556 |
if raw, found := a[name]; found { |
| 557 |
agg := new(AggregationPipelineSimpleValue) |
| 558 |
if raw == nil { |
| 559 |
return agg, true |
| 560 |
} |
| 561 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 562 |
return agg, true |
| 563 |
} |
| 564 |
} |
| 565 |
return nil, false |
| 566 |
} |
| 567 |
|
| 568 |
// SumBucket returns sum bucket pipeline aggregation results. |
| 569 |
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-sum-bucket-aggregation.html |
| 570 |
func (a Aggregations) SumBucket(name string) (*AggregationPipelineSimpleValue, bool) { |
| 571 |
if raw, found := a[name]; found { |
| 572 |
agg := new(AggregationPipelineSimpleValue) |
| 573 |
if raw == nil { |
| 574 |
return agg, true |
| 575 |
} |
| 576 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 577 |
return agg, true |
| 578 |
} |
| 579 |
} |
| 580 |
return nil, false |
| 581 |
} |
| 582 |
|
| 583 |
// StatsBucket returns stats bucket pipeline aggregation results. |
| 584 |
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-stats-bucket-aggregation.html |
| 585 |
func (a Aggregations) StatsBucket(name string) (*AggregationPipelineStatsMetric, bool) { |
| 586 |
if raw, found := a[name]; found { |
| 587 |
agg := new(AggregationPipelineStatsMetric) |
| 588 |
if raw == nil { |
| 589 |
return agg, true |
| 590 |
} |
| 591 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 592 |
return agg, true |
| 593 |
} |
| 594 |
} |
| 595 |
return nil, false |
| 596 |
} |
| 597 |
|
| 598 |
// PercentilesBucket returns stats bucket pipeline aggregation results. |
| 599 |
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-percentiles-bucket-aggregation.html |
| 600 |
func (a Aggregations) PercentilesBucket(name string) (*AggregationPipelinePercentilesMetric, bool) { |
| 601 |
if raw, found := a[name]; found { |
| 602 |
agg := new(AggregationPipelinePercentilesMetric) |
| 603 |
if raw == nil { |
| 604 |
return agg, true |
| 605 |
} |
| 606 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 607 |
return agg, true |
| 608 |
} |
| 609 |
} |
| 610 |
return nil, false |
| 611 |
} |
| 612 |
|
| 613 |
// MaxBucket returns maximum bucket pipeline aggregation results. |
| 614 |
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-max-bucket-aggregation.html |
| 615 |
func (a Aggregations) MaxBucket(name string) (*AggregationPipelineBucketMetricValue, bool) { |
| 616 |
if raw, found := a[name]; found { |
| 617 |
agg := new(AggregationPipelineBucketMetricValue) |
| 618 |
if raw == nil { |
| 619 |
return agg, true |
| 620 |
} |
| 621 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 622 |
return agg, true |
| 623 |
} |
| 624 |
} |
| 625 |
return nil, false |
| 626 |
} |
| 627 |
|
| 628 |
// MinBucket returns minimum bucket pipeline aggregation results. |
| 629 |
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-min-bucket-aggregation.html |
| 630 |
func (a Aggregations) MinBucket(name string) (*AggregationPipelineBucketMetricValue, bool) { |
| 631 |
if raw, found := a[name]; found { |
| 632 |
agg := new(AggregationPipelineBucketMetricValue) |
| 633 |
if raw == nil { |
| 634 |
return agg, true |
| 635 |
} |
| 636 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 637 |
return agg, true |
| 638 |
} |
| 639 |
} |
| 640 |
return nil, false |
| 641 |
} |
| 642 |
|
| 643 |
// MovAvg returns moving average pipeline aggregation results. |
| 644 |
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-movavg-aggregation.html |
| 645 |
func (a Aggregations) MovAvg(name string) (*AggregationPipelineSimpleValue, bool) { |
| 646 |
if raw, found := a[name]; found { |
| 647 |
agg := new(AggregationPipelineSimpleValue) |
| 648 |
if raw == nil { |
| 649 |
return agg, true |
| 650 |
} |
| 651 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 652 |
return agg, true |
| 653 |
} |
| 654 |
} |
| 655 |
return nil, false |
| 656 |
} |
| 657 |
|
| 658 |
// Derivative returns derivative pipeline aggregation results. |
| 659 |
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-derivative-aggregation.html |
| 660 |
func (a Aggregations) Derivative(name string) (*AggregationPipelineDerivative, bool) { |
| 661 |
if raw, found := a[name]; found { |
| 662 |
agg := new(AggregationPipelineDerivative) |
| 663 |
if raw == nil { |
| 664 |
return agg, true |
| 665 |
} |
| 666 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 667 |
return agg, true |
| 668 |
} |
| 669 |
} |
| 670 |
return nil, false |
| 671 |
} |
| 672 |
|
| 673 |
// CumulativeSum returns a cumulative sum pipeline aggregation results. |
| 674 |
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-cumulative-sum-aggregation.html |
| 675 |
func (a Aggregations) CumulativeSum(name string) (*AggregationPipelineSimpleValue, bool) { |
| 676 |
if raw, found := a[name]; found { |
| 677 |
agg := new(AggregationPipelineSimpleValue) |
| 678 |
if raw == nil { |
| 679 |
return agg, true |
| 680 |
} |
| 681 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 682 |
return agg, true |
| 683 |
} |
| 684 |
} |
| 685 |
return nil, false |
| 686 |
} |
| 687 |
|
| 688 |
// BucketScript returns bucket script pipeline aggregation results. |
| 689 |
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-bucket-script-aggregation.html |
| 690 |
func (a Aggregations) BucketScript(name string) (*AggregationPipelineSimpleValue, bool) { |
| 691 |
if raw, found := a[name]; found { |
| 692 |
agg := new(AggregationPipelineSimpleValue) |
| 693 |
if raw == nil { |
| 694 |
return agg, true |
| 695 |
} |
| 696 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 697 |
return agg, true |
| 698 |
} |
| 699 |
} |
| 700 |
return nil, false |
| 701 |
} |
| 702 |
|
| 703 |
// SerialDiff returns serial differencing pipeline aggregation results. |
| 704 |
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-pipeline-serialdiff-aggregation.html |
| 705 |
func (a Aggregations) SerialDiff(name string) (*AggregationPipelineSimpleValue, bool) { |
| 706 |
if raw, found := a[name]; found { |
| 707 |
agg := new(AggregationPipelineSimpleValue) |
| 708 |
if raw == nil { |
| 709 |
return agg, true |
| 710 |
} |
| 711 |
if err := json.Unmarshal(*raw, agg); err == nil { |
| 712 |
return agg, true |
| 713 |
} |
| 714 |
} |
| 715 |
return nil, false |
| 716 |
} |
| 717 |
|
| 718 |
// -- Single value metric -- |
| 719 |
|
| 720 |
// AggregationValueMetric is a single-value metric, returned e.g. by a |
| 721 |
// Min or Max aggregation. |
| 722 |
type AggregationValueMetric struct { |
| 723 |
Aggregations |
| 724 |
|
| 725 |
Value *float64 //`json:"value"` |
| 726 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 727 |
} |
| 728 |
|
| 729 |
// UnmarshalJSON decodes JSON data and initializes an AggregationValueMetric structure. |
| 730 |
func (a *AggregationValueMetric) UnmarshalJSON(data []byte) error { |
| 731 |
var aggs map[string]*json.RawMessage |
| 732 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 733 |
return err |
| 734 |
} |
| 735 |
if v, ok := aggs["value"]; ok && v != nil { |
| 736 |
json.Unmarshal(*v, &a.Value) |
| 737 |
} |
| 738 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 739 |
json.Unmarshal(*v, &a.Meta) |
| 740 |
} |
| 741 |
a.Aggregations = aggs |
| 742 |
return nil |
| 743 |
} |
| 744 |
|
| 745 |
// -- Stats metric -- |
| 746 |
|
| 747 |
// AggregationStatsMetric is a multi-value metric, returned by a Stats aggregation. |
| 748 |
type AggregationStatsMetric struct { |
| 749 |
Aggregations |
| 750 |
|
| 751 |
Count int64 // `json:"count"` |
| 752 |
Min *float64 //`json:"min,omitempty"` |
| 753 |
Max *float64 //`json:"max,omitempty"` |
| 754 |
Avg *float64 //`json:"avg,omitempty"` |
| 755 |
Sum *float64 //`json:"sum,omitempty"` |
| 756 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 757 |
} |
| 758 |
|
| 759 |
// UnmarshalJSON decodes JSON data and initializes an AggregationStatsMetric structure. |
| 760 |
func (a *AggregationStatsMetric) UnmarshalJSON(data []byte) error { |
| 761 |
var aggs map[string]*json.RawMessage |
| 762 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 763 |
return err |
| 764 |
} |
| 765 |
if v, ok := aggs["count"]; ok && v != nil { |
| 766 |
json.Unmarshal(*v, &a.Count) |
| 767 |
} |
| 768 |
if v, ok := aggs["min"]; ok && v != nil { |
| 769 |
json.Unmarshal(*v, &a.Min) |
| 770 |
} |
| 771 |
if v, ok := aggs["max"]; ok && v != nil { |
| 772 |
json.Unmarshal(*v, &a.Max) |
| 773 |
} |
| 774 |
if v, ok := aggs["avg"]; ok && v != nil { |
| 775 |
json.Unmarshal(*v, &a.Avg) |
| 776 |
} |
| 777 |
if v, ok := aggs["sum"]; ok && v != nil { |
| 778 |
json.Unmarshal(*v, &a.Sum) |
| 779 |
} |
| 780 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 781 |
json.Unmarshal(*v, &a.Meta) |
| 782 |
} |
| 783 |
a.Aggregations = aggs |
| 784 |
return nil |
| 785 |
} |
| 786 |
|
| 787 |
// -- Extended stats metric -- |
| 788 |
|
| 789 |
// AggregationExtendedStatsMetric is a multi-value metric, returned by an ExtendedStats aggregation. |
| 790 |
type AggregationExtendedStatsMetric struct { |
| 791 |
Aggregations |
| 792 |
|
| 793 |
Count int64 // `json:"count"` |
| 794 |
Min *float64 //`json:"min,omitempty"` |
| 795 |
Max *float64 //`json:"max,omitempty"` |
| 796 |
Avg *float64 //`json:"avg,omitempty"` |
| 797 |
Sum *float64 //`json:"sum,omitempty"` |
| 798 |
SumOfSquares *float64 //`json:"sum_of_squares,omitempty"` |
| 799 |
Variance *float64 //`json:"variance,omitempty"` |
| 800 |
StdDeviation *float64 //`json:"std_deviation,omitempty"` |
| 801 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 802 |
} |
| 803 |
|
| 804 |
// UnmarshalJSON decodes JSON data and initializes an AggregationExtendedStatsMetric structure. |
| 805 |
func (a *AggregationExtendedStatsMetric) UnmarshalJSON(data []byte) error { |
| 806 |
var aggs map[string]*json.RawMessage |
| 807 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 808 |
return err |
| 809 |
} |
| 810 |
if v, ok := aggs["count"]; ok && v != nil { |
| 811 |
json.Unmarshal(*v, &a.Count) |
| 812 |
} |
| 813 |
if v, ok := aggs["min"]; ok && v != nil { |
| 814 |
json.Unmarshal(*v, &a.Min) |
| 815 |
} |
| 816 |
if v, ok := aggs["max"]; ok && v != nil { |
| 817 |
json.Unmarshal(*v, &a.Max) |
| 818 |
} |
| 819 |
if v, ok := aggs["avg"]; ok && v != nil { |
| 820 |
json.Unmarshal(*v, &a.Avg) |
| 821 |
} |
| 822 |
if v, ok := aggs["sum"]; ok && v != nil { |
| 823 |
json.Unmarshal(*v, &a.Sum) |
| 824 |
} |
| 825 |
if v, ok := aggs["sum_of_squares"]; ok && v != nil { |
| 826 |
json.Unmarshal(*v, &a.SumOfSquares) |
| 827 |
} |
| 828 |
if v, ok := aggs["variance"]; ok && v != nil { |
| 829 |
json.Unmarshal(*v, &a.Variance) |
| 830 |
} |
| 831 |
if v, ok := aggs["std_deviation"]; ok && v != nil { |
| 832 |
json.Unmarshal(*v, &a.StdDeviation) |
| 833 |
} |
| 834 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 835 |
json.Unmarshal(*v, &a.Meta) |
| 836 |
} |
| 837 |
a.Aggregations = aggs |
| 838 |
return nil |
| 839 |
} |
| 840 |
|
| 841 |
// -- Matrix Stats -- |
| 842 |
|
| 843 |
// AggregationMatrixStats is returned by a MatrixStats aggregation. |
| 844 |
type AggregationMatrixStats struct { |
| 845 |
Aggregations |
| 846 |
|
| 847 |
Fields []*AggregationMatrixStatsField // `json:"field,omitempty"` |
| 848 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 849 |
} |
| 850 |
|
| 851 |
// AggregationMatrixStatsField represents running stats of a single field |
| 852 |
// returned from MatrixStats aggregation. |
| 853 |
type AggregationMatrixStatsField struct { |
| 854 |
Name string `json:"name"` |
| 855 |
Count int64 `json:"count"` |
| 856 |
Mean float64 `json:"mean,omitempty"` |
| 857 |
Variance float64 `json:"variance,omitempty"` |
| 858 |
Skewness float64 `json:"skewness,omitempty"` |
| 859 |
Kurtosis float64 `json:"kurtosis,omitempty"` |
| 860 |
Covariance map[string]float64 `json:"covariance,omitempty"` |
| 861 |
Correlation map[string]float64 `json:"correlation,omitempty"` |
| 862 |
} |
| 863 |
|
| 864 |
// UnmarshalJSON decodes JSON data and initializes an AggregationMatrixStats structure. |
| 865 |
func (a *AggregationMatrixStats) UnmarshalJSON(data []byte) error { |
| 866 |
var aggs map[string]*json.RawMessage |
| 867 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 868 |
return err |
| 869 |
} |
| 870 |
if v, ok := aggs["fields"]; ok && v != nil { |
| 871 |
// RunningStats for every field |
| 872 |
json.Unmarshal(*v, &a.Fields) |
| 873 |
} |
| 874 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 875 |
json.Unmarshal(*v, &a.Meta) |
| 876 |
} |
| 877 |
a.Aggregations = aggs |
| 878 |
return nil |
| 879 |
} |
| 880 |
|
| 881 |
// -- Percentiles metric -- |
| 882 |
|
| 883 |
// AggregationPercentilesMetric is a multi-value metric, returned by a Percentiles aggregation. |
| 884 |
type AggregationPercentilesMetric struct { |
| 885 |
Aggregations |
| 886 |
|
| 887 |
Values map[string]float64 // `json:"values"` |
| 888 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 889 |
} |
| 890 |
|
| 891 |
// UnmarshalJSON decodes JSON data and initializes an AggregationPercentilesMetric structure. |
| 892 |
func (a *AggregationPercentilesMetric) UnmarshalJSON(data []byte) error { |
| 893 |
var aggs map[string]*json.RawMessage |
| 894 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 895 |
return err |
| 896 |
} |
| 897 |
if v, ok := aggs["values"]; ok && v != nil { |
| 898 |
json.Unmarshal(*v, &a.Values) |
| 899 |
} |
| 900 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 901 |
json.Unmarshal(*v, &a.Meta) |
| 902 |
} |
| 903 |
a.Aggregations = aggs |
| 904 |
return nil |
| 905 |
} |
| 906 |
|
| 907 |
// -- Top-hits metric -- |
| 908 |
|
| 909 |
// AggregationTopHitsMetric is a metric returned by a TopHits aggregation. |
| 910 |
type AggregationTopHitsMetric struct { |
| 911 |
Aggregations |
| 912 |
|
| 913 |
Hits *SearchHits //`json:"hits"` |
| 914 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 915 |
} |
| 916 |
|
| 917 |
// UnmarshalJSON decodes JSON data and initializes an AggregationTopHitsMetric structure. |
| 918 |
func (a *AggregationTopHitsMetric) UnmarshalJSON(data []byte) error { |
| 919 |
var aggs map[string]*json.RawMessage |
| 920 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 921 |
return err |
| 922 |
} |
| 923 |
a.Aggregations = aggs |
| 924 |
a.Hits = new(SearchHits) |
| 925 |
if v, ok := aggs["hits"]; ok && v != nil { |
| 926 |
json.Unmarshal(*v, &a.Hits) |
| 927 |
} |
| 928 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 929 |
json.Unmarshal(*v, &a.Meta) |
| 930 |
} |
| 931 |
return nil |
| 932 |
} |
| 933 |
|
| 934 |
// -- Geo-bounds metric -- |
| 935 |
|
| 936 |
// AggregationGeoBoundsMetric is a metric as returned by a GeoBounds aggregation. |
| 937 |
type AggregationGeoBoundsMetric struct { |
| 938 |
Aggregations |
| 939 |
|
| 940 |
Bounds struct { |
| 941 |
TopLeft struct { |
| 942 |
Latitude float64 `json:"lat"` |
| 943 |
Longitude float64 `json:"lon"` |
| 944 |
} `json:"top_left"` |
| 945 |
BottomRight struct { |
| 946 |
Latitude float64 `json:"lat"` |
| 947 |
Longitude float64 `json:"lon"` |
| 948 |
} `json:"bottom_right"` |
| 949 |
} `json:"bounds"` |
| 950 |
|
| 951 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 952 |
} |
| 953 |
|
| 954 |
// UnmarshalJSON decodes JSON data and initializes an AggregationGeoBoundsMetric structure. |
| 955 |
func (a *AggregationGeoBoundsMetric) UnmarshalJSON(data []byte) error { |
| 956 |
var aggs map[string]*json.RawMessage |
| 957 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 958 |
return err |
| 959 |
} |
| 960 |
if v, ok := aggs["bounds"]; ok && v != nil { |
| 961 |
json.Unmarshal(*v, &a.Bounds) |
| 962 |
} |
| 963 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 964 |
json.Unmarshal(*v, &a.Meta) |
| 965 |
} |
| 966 |
a.Aggregations = aggs |
| 967 |
return nil |
| 968 |
} |
| 969 |
|
| 970 |
// -- Geo Centroid -- |
| 971 |
|
| 972 |
// AggregationGeocentroidMetric is a metric as returned by a GeoCentroid aggregation. |
| 973 |
type AggregationGeoCentroidMetric struct { |
| 974 |
Aggregations |
| 975 |
|
| 976 |
Location struct { |
| 977 |
Latitude float64 `json:"lat"` |
| 978 |
Longitude float64 `json:"lon"` |
| 979 |
} `json:"location"` |
| 980 |
|
| 981 |
Count int // `json:"count,omitempty"` |
| 982 |
|
| 983 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 984 |
} |
| 985 |
|
| 986 |
// UnmarshalJSON decodes JSON data and initializes an AggregationGeoCentroidMetric structure. |
| 987 |
func (a *AggregationGeoCentroidMetric) UnmarshalJSON(data []byte) error { |
| 988 |
var aggs map[string]*json.RawMessage |
| 989 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 990 |
return err |
| 991 |
} |
| 992 |
if v, ok := aggs["location"]; ok && v != nil { |
| 993 |
json.Unmarshal(*v, &a.Location) |
| 994 |
} |
| 995 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 996 |
json.Unmarshal(*v, &a.Meta) |
| 997 |
} |
| 998 |
if v, ok := aggs["count"]; ok && v != nil { |
| 999 |
json.Unmarshal(*v, &a.Count) |
| 1000 |
} |
| 1001 |
a.Aggregations = aggs |
| 1002 |
return nil |
| 1003 |
} |
| 1004 |
|
| 1005 |
// -- Single bucket -- |
| 1006 |
|
| 1007 |
// AggregationSingleBucket is a single bucket, returned e.g. via an aggregation of type Global. |
| 1008 |
type AggregationSingleBucket struct { |
| 1009 |
Aggregations |
| 1010 |
|
| 1011 |
DocCount int64 // `json:"doc_count"` |
| 1012 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 1013 |
} |
| 1014 |
|
| 1015 |
// UnmarshalJSON decodes JSON data and initializes an AggregationSingleBucket structure. |
| 1016 |
func (a *AggregationSingleBucket) UnmarshalJSON(data []byte) error { |
| 1017 |
var aggs map[string]*json.RawMessage |
| 1018 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1019 |
return err |
| 1020 |
} |
| 1021 |
if v, ok := aggs["doc_count"]; ok && v != nil { |
| 1022 |
json.Unmarshal(*v, &a.DocCount) |
| 1023 |
} |
| 1024 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 1025 |
json.Unmarshal(*v, &a.Meta) |
| 1026 |
} |
| 1027 |
a.Aggregations = aggs |
| 1028 |
return nil |
| 1029 |
} |
| 1030 |
|
| 1031 |
// -- Bucket range items -- |
| 1032 |
|
| 1033 |
// AggregationBucketRangeItems is a bucket aggregation that is e.g. returned |
| 1034 |
// with a range aggregation. |
| 1035 |
type AggregationBucketRangeItems struct { |
| 1036 |
Aggregations |
| 1037 |
|
| 1038 |
DocCountErrorUpperBound int64 //`json:"doc_count_error_upper_bound"` |
| 1039 |
SumOfOtherDocCount int64 //`json:"sum_other_doc_count"` |
| 1040 |
Buckets []*AggregationBucketRangeItem //`json:"buckets"` |
| 1041 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 1042 |
} |
| 1043 |
|
| 1044 |
// UnmarshalJSON decodes JSON data and initializes an AggregationBucketRangeItems structure. |
| 1045 |
func (a *AggregationBucketRangeItems) UnmarshalJSON(data []byte) error { |
| 1046 |
var aggs map[string]*json.RawMessage |
| 1047 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1048 |
return err |
| 1049 |
} |
| 1050 |
if v, ok := aggs["doc_count_error_upper_bound"]; ok && v != nil { |
| 1051 |
json.Unmarshal(*v, &a.DocCountErrorUpperBound) |
| 1052 |
} |
| 1053 |
if v, ok := aggs["sum_other_doc_count"]; ok && v != nil { |
| 1054 |
json.Unmarshal(*v, &a.SumOfOtherDocCount) |
| 1055 |
} |
| 1056 |
if v, ok := aggs["buckets"]; ok && v != nil { |
| 1057 |
json.Unmarshal(*v, &a.Buckets) |
| 1058 |
} |
| 1059 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 1060 |
json.Unmarshal(*v, &a.Meta) |
| 1061 |
} |
| 1062 |
a.Aggregations = aggs |
| 1063 |
return nil |
| 1064 |
} |
| 1065 |
|
| 1066 |
// AggregationBucketKeyedRangeItems is a bucket aggregation that is e.g. returned |
| 1067 |
// with a keyed range aggregation. |
| 1068 |
type AggregationBucketKeyedRangeItems struct { |
| 1069 |
Aggregations |
| 1070 |
|
| 1071 |
DocCountErrorUpperBound int64 //`json:"doc_count_error_upper_bound"` |
| 1072 |
SumOfOtherDocCount int64 //`json:"sum_other_doc_count"` |
| 1073 |
Buckets map[string]*AggregationBucketRangeItem //`json:"buckets"` |
| 1074 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 1075 |
} |
| 1076 |
|
| 1077 |
// UnmarshalJSON decodes JSON data and initializes an AggregationBucketRangeItems structure. |
| 1078 |
func (a *AggregationBucketKeyedRangeItems) UnmarshalJSON(data []byte) error { |
| 1079 |
var aggs map[string]*json.RawMessage |
| 1080 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1081 |
return err |
| 1082 |
} |
| 1083 |
if v, ok := aggs["doc_count_error_upper_bound"]; ok && v != nil { |
| 1084 |
json.Unmarshal(*v, &a.DocCountErrorUpperBound) |
| 1085 |
} |
| 1086 |
if v, ok := aggs["sum_other_doc_count"]; ok && v != nil { |
| 1087 |
json.Unmarshal(*v, &a.SumOfOtherDocCount) |
| 1088 |
} |
| 1089 |
if v, ok := aggs["buckets"]; ok && v != nil { |
| 1090 |
json.Unmarshal(*v, &a.Buckets) |
| 1091 |
} |
| 1092 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 1093 |
json.Unmarshal(*v, &a.Meta) |
| 1094 |
} |
| 1095 |
a.Aggregations = aggs |
| 1096 |
return nil |
| 1097 |
} |
| 1098 |
|
| 1099 |
// AggregationBucketRangeItem is a single bucket of an AggregationBucketRangeItems structure. |
| 1100 |
type AggregationBucketRangeItem struct { |
| 1101 |
Aggregations |
| 1102 |
|
| 1103 |
Key string //`json:"key"` |
| 1104 |
DocCount int64 //`json:"doc_count"` |
| 1105 |
From *float64 //`json:"from"` |
| 1106 |
FromAsString string //`json:"from_as_string"` |
| 1107 |
To *float64 //`json:"to"` |
| 1108 |
ToAsString string //`json:"to_as_string"` |
| 1109 |
} |
| 1110 |
|
| 1111 |
// UnmarshalJSON decodes JSON data and initializes an AggregationBucketRangeItem structure. |
| 1112 |
func (a *AggregationBucketRangeItem) UnmarshalJSON(data []byte) error { |
| 1113 |
var aggs map[string]*json.RawMessage |
| 1114 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1115 |
return err |
| 1116 |
} |
| 1117 |
if v, ok := aggs["key"]; ok && v != nil { |
| 1118 |
json.Unmarshal(*v, &a.Key) |
| 1119 |
} |
| 1120 |
if v, ok := aggs["doc_count"]; ok && v != nil { |
| 1121 |
json.Unmarshal(*v, &a.DocCount) |
| 1122 |
} |
| 1123 |
if v, ok := aggs["from"]; ok && v != nil { |
| 1124 |
json.Unmarshal(*v, &a.From) |
| 1125 |
} |
| 1126 |
if v, ok := aggs["from_as_string"]; ok && v != nil { |
| 1127 |
json.Unmarshal(*v, &a.FromAsString) |
| 1128 |
} |
| 1129 |
if v, ok := aggs["to"]; ok && v != nil { |
| 1130 |
json.Unmarshal(*v, &a.To) |
| 1131 |
} |
| 1132 |
if v, ok := aggs["to_as_string"]; ok && v != nil { |
| 1133 |
json.Unmarshal(*v, &a.ToAsString) |
| 1134 |
} |
| 1135 |
a.Aggregations = aggs |
| 1136 |
return nil |
| 1137 |
} |
| 1138 |
|
| 1139 |
// -- Bucket key items -- |
| 1140 |
|
| 1141 |
// AggregationBucketKeyItems is a bucket aggregation that is e.g. returned |
| 1142 |
// with a terms aggregation. |
| 1143 |
type AggregationBucketKeyItems struct { |
| 1144 |
Aggregations |
| 1145 |
|
| 1146 |
DocCountErrorUpperBound int64 //`json:"doc_count_error_upper_bound"` |
| 1147 |
SumOfOtherDocCount int64 //`json:"sum_other_doc_count"` |
| 1148 |
Buckets []*AggregationBucketKeyItem //`json:"buckets"` |
| 1149 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 1150 |
} |
| 1151 |
|
| 1152 |
// UnmarshalJSON decodes JSON data and initializes an AggregationBucketKeyItems structure. |
| 1153 |
func (a *AggregationBucketKeyItems) UnmarshalJSON(data []byte) error { |
| 1154 |
var aggs map[string]*json.RawMessage |
| 1155 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1156 |
return err |
| 1157 |
} |
| 1158 |
if v, ok := aggs["doc_count_error_upper_bound"]; ok && v != nil { |
| 1159 |
json.Unmarshal(*v, &a.DocCountErrorUpperBound) |
| 1160 |
} |
| 1161 |
if v, ok := aggs["sum_other_doc_count"]; ok && v != nil { |
| 1162 |
json.Unmarshal(*v, &a.SumOfOtherDocCount) |
| 1163 |
} |
| 1164 |
if v, ok := aggs["buckets"]; ok && v != nil { |
| 1165 |
json.Unmarshal(*v, &a.Buckets) |
| 1166 |
} |
| 1167 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 1168 |
json.Unmarshal(*v, &a.Meta) |
| 1169 |
} |
| 1170 |
a.Aggregations = aggs |
| 1171 |
return nil |
| 1172 |
} |
| 1173 |
|
| 1174 |
// AggregationBucketKeyItem is a single bucket of an AggregationBucketKeyItems structure. |
| 1175 |
type AggregationBucketKeyItem struct { |
| 1176 |
Aggregations |
| 1177 |
|
| 1178 |
Key interface{} //`json:"key"` |
| 1179 |
KeyAsString *string //`json:"key_as_string"` |
| 1180 |
KeyNumber json.Number |
| 1181 |
DocCount int64 //`json:"doc_count"` |
| 1182 |
} |
| 1183 |
|
| 1184 |
// UnmarshalJSON decodes JSON data and initializes an AggregationBucketKeyItem structure. |
| 1185 |
func (a *AggregationBucketKeyItem) UnmarshalJSON(data []byte) error { |
| 1186 |
var aggs map[string]*json.RawMessage |
| 1187 |
dec := json.NewDecoder(bytes.NewReader(data)) |
| 1188 |
dec.UseNumber() |
| 1189 |
if err := dec.Decode(&aggs); err != nil { |
| 1190 |
return err |
| 1191 |
} |
| 1192 |
if v, ok := aggs["key"]; ok && v != nil { |
| 1193 |
json.Unmarshal(*v, &a.Key) |
| 1194 |
json.Unmarshal(*v, &a.KeyNumber) |
| 1195 |
} |
| 1196 |
if v, ok := aggs["key_as_string"]; ok && v != nil { |
| 1197 |
json.Unmarshal(*v, &a.KeyAsString) |
| 1198 |
} |
| 1199 |
if v, ok := aggs["doc_count"]; ok && v != nil { |
| 1200 |
json.Unmarshal(*v, &a.DocCount) |
| 1201 |
} |
| 1202 |
a.Aggregations = aggs |
| 1203 |
return nil |
| 1204 |
} |
| 1205 |
|
| 1206 |
// -- Bucket types for significant terms -- |
| 1207 |
|
| 1208 |
// AggregationBucketSignificantTerms is a bucket aggregation returned |
| 1209 |
// with a significant terms aggregation. |
| 1210 |
type AggregationBucketSignificantTerms struct { |
| 1211 |
Aggregations |
| 1212 |
|
| 1213 |
DocCount int64 //`json:"doc_count"` |
| 1214 |
Buckets []*AggregationBucketSignificantTerm //`json:"buckets"` |
| 1215 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 1216 |
} |
| 1217 |
|
| 1218 |
// UnmarshalJSON decodes JSON data and initializes an AggregationBucketSignificantTerms structure. |
| 1219 |
func (a *AggregationBucketSignificantTerms) UnmarshalJSON(data []byte) error { |
| 1220 |
var aggs map[string]*json.RawMessage |
| 1221 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1222 |
return err |
| 1223 |
} |
| 1224 |
if v, ok := aggs["doc_count"]; ok && v != nil { |
| 1225 |
json.Unmarshal(*v, &a.DocCount) |
| 1226 |
} |
| 1227 |
if v, ok := aggs["buckets"]; ok && v != nil { |
| 1228 |
json.Unmarshal(*v, &a.Buckets) |
| 1229 |
} |
| 1230 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 1231 |
json.Unmarshal(*v, &a.Meta) |
| 1232 |
} |
| 1233 |
a.Aggregations = aggs |
| 1234 |
return nil |
| 1235 |
} |
| 1236 |
|
| 1237 |
// AggregationBucketSignificantTerm is a single bucket of an AggregationBucketSignificantTerms structure. |
| 1238 |
type AggregationBucketSignificantTerm struct { |
| 1239 |
Aggregations |
| 1240 |
|
| 1241 |
Key string //`json:"key"` |
| 1242 |
DocCount int64 //`json:"doc_count"` |
| 1243 |
BgCount int64 //`json:"bg_count"` |
| 1244 |
Score float64 //`json:"score"` |
| 1245 |
} |
| 1246 |
|
| 1247 |
// UnmarshalJSON decodes JSON data and initializes an AggregationBucketSignificantTerm structure. |
| 1248 |
func (a *AggregationBucketSignificantTerm) UnmarshalJSON(data []byte) error { |
| 1249 |
var aggs map[string]*json.RawMessage |
| 1250 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1251 |
return err |
| 1252 |
} |
| 1253 |
if v, ok := aggs["key"]; ok && v != nil { |
| 1254 |
json.Unmarshal(*v, &a.Key) |
| 1255 |
} |
| 1256 |
if v, ok := aggs["doc_count"]; ok && v != nil { |
| 1257 |
json.Unmarshal(*v, &a.DocCount) |
| 1258 |
} |
| 1259 |
if v, ok := aggs["bg_count"]; ok && v != nil { |
| 1260 |
json.Unmarshal(*v, &a.BgCount) |
| 1261 |
} |
| 1262 |
if v, ok := aggs["score"]; ok && v != nil { |
| 1263 |
json.Unmarshal(*v, &a.Score) |
| 1264 |
} |
| 1265 |
a.Aggregations = aggs |
| 1266 |
return nil |
| 1267 |
} |
| 1268 |
|
| 1269 |
// -- Bucket filters -- |
| 1270 |
|
| 1271 |
// AggregationBucketFilters is a multi-bucket aggregation that is returned |
| 1272 |
// with a filters aggregation. |
| 1273 |
type AggregationBucketFilters struct { |
| 1274 |
Aggregations |
| 1275 |
|
| 1276 |
Buckets []*AggregationBucketKeyItem //`json:"buckets"` |
| 1277 |
NamedBuckets map[string]*AggregationBucketKeyItem //`json:"buckets"` |
| 1278 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 1279 |
} |
| 1280 |
|
| 1281 |
// UnmarshalJSON decodes JSON data and initializes an AggregationBucketFilters structure. |
| 1282 |
func (a *AggregationBucketFilters) UnmarshalJSON(data []byte) error { |
| 1283 |
var aggs map[string]*json.RawMessage |
| 1284 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1285 |
return err |
| 1286 |
} |
| 1287 |
if v, ok := aggs["buckets"]; ok && v != nil { |
| 1288 |
json.Unmarshal(*v, &a.Buckets) |
| 1289 |
json.Unmarshal(*v, &a.NamedBuckets) |
| 1290 |
} |
| 1291 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 1292 |
json.Unmarshal(*v, &a.Meta) |
| 1293 |
} |
| 1294 |
a.Aggregations = aggs |
| 1295 |
return nil |
| 1296 |
} |
| 1297 |
|
| 1298 |
// -- Bucket AdjacencyMatrix -- |
| 1299 |
|
| 1300 |
// AggregationBucketAdjacencyMatrix is a multi-bucket aggregation that is returned |
| 1301 |
// with a AdjacencyMatrix aggregation. |
| 1302 |
type AggregationBucketAdjacencyMatrix struct { |
| 1303 |
Aggregations |
| 1304 |
|
| 1305 |
Buckets []*AggregationBucketKeyItem //`json:"buckets"` |
| 1306 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 1307 |
} |
| 1308 |
|
| 1309 |
// UnmarshalJSON decodes JSON data and initializes an AggregationBucketAdjacencyMatrix structure. |
| 1310 |
func (a *AggregationBucketAdjacencyMatrix) UnmarshalJSON(data []byte) error { |
| 1311 |
var aggs map[string]*json.RawMessage |
| 1312 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1313 |
return err |
| 1314 |
} |
| 1315 |
if v, ok := aggs["buckets"]; ok && v != nil { |
| 1316 |
json.Unmarshal(*v, &a.Buckets) |
| 1317 |
} |
| 1318 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 1319 |
json.Unmarshal(*v, &a.Meta) |
| 1320 |
} |
| 1321 |
a.Aggregations = aggs |
| 1322 |
return nil |
| 1323 |
} |
| 1324 |
|
| 1325 |
// -- Bucket histogram items -- |
| 1326 |
|
| 1327 |
// AggregationBucketHistogramItems is a bucket aggregation that is returned |
| 1328 |
// with a date histogram aggregation. |
| 1329 |
type AggregationBucketHistogramItems struct { |
| 1330 |
Aggregations |
| 1331 |
|
| 1332 |
Buckets []*AggregationBucketHistogramItem //`json:"buckets"` |
| 1333 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 1334 |
} |
| 1335 |
|
| 1336 |
// UnmarshalJSON decodes JSON data and initializes an AggregationBucketHistogramItems structure. |
| 1337 |
func (a *AggregationBucketHistogramItems) UnmarshalJSON(data []byte) error { |
| 1338 |
var aggs map[string]*json.RawMessage |
| 1339 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1340 |
return err |
| 1341 |
} |
| 1342 |
if v, ok := aggs["buckets"]; ok && v != nil { |
| 1343 |
json.Unmarshal(*v, &a.Buckets) |
| 1344 |
} |
| 1345 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 1346 |
json.Unmarshal(*v, &a.Meta) |
| 1347 |
} |
| 1348 |
a.Aggregations = aggs |
| 1349 |
return nil |
| 1350 |
} |
| 1351 |
|
| 1352 |
// AggregationBucketKeyedHistogramItems is a bucket aggregation that is returned |
| 1353 |
// with a (keyed) date histogram aggregation. |
| 1354 |
type AggregationBucketKeyedHistogramItems struct { |
| 1355 |
Aggregations |
| 1356 |
|
| 1357 |
Buckets map[string]*AggregationBucketHistogramItem //`json:"buckets"` |
| 1358 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 1359 |
} |
| 1360 |
|
| 1361 |
// UnmarshalJSON decodes JSON data and initializes an AggregationBucketKeyedHistogramItems structure. |
| 1362 |
func (a *AggregationBucketKeyedHistogramItems) UnmarshalJSON(data []byte) error { |
| 1363 |
var aggs map[string]*json.RawMessage |
| 1364 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1365 |
return err |
| 1366 |
} |
| 1367 |
if v, ok := aggs["buckets"]; ok && v != nil { |
| 1368 |
json.Unmarshal(*v, &a.Buckets) |
| 1369 |
} |
| 1370 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 1371 |
json.Unmarshal(*v, &a.Meta) |
| 1372 |
} |
| 1373 |
a.Aggregations = aggs |
| 1374 |
return nil |
| 1375 |
} |
| 1376 |
|
| 1377 |
// AggregationBucketHistogramItem is a single bucket of an AggregationBucketHistogramItems structure. |
| 1378 |
type AggregationBucketHistogramItem struct { |
| 1379 |
Aggregations |
| 1380 |
|
| 1381 |
Key float64 //`json:"key"` |
| 1382 |
KeyAsString *string //`json:"key_as_string"` |
| 1383 |
DocCount int64 //`json:"doc_count"` |
| 1384 |
} |
| 1385 |
|
| 1386 |
// UnmarshalJSON decodes JSON data and initializes an AggregationBucketHistogramItem structure. |
| 1387 |
func (a *AggregationBucketHistogramItem) UnmarshalJSON(data []byte) error { |
| 1388 |
var aggs map[string]*json.RawMessage |
| 1389 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1390 |
return err |
| 1391 |
} |
| 1392 |
if v, ok := aggs["key"]; ok && v != nil { |
| 1393 |
json.Unmarshal(*v, &a.Key) |
| 1394 |
} |
| 1395 |
if v, ok := aggs["key_as_string"]; ok && v != nil { |
| 1396 |
json.Unmarshal(*v, &a.KeyAsString) |
| 1397 |
} |
| 1398 |
if v, ok := aggs["doc_count"]; ok && v != nil { |
| 1399 |
json.Unmarshal(*v, &a.DocCount) |
| 1400 |
} |
| 1401 |
a.Aggregations = aggs |
| 1402 |
return nil |
| 1403 |
} |
| 1404 |
|
| 1405 |
// -- Pipeline simple value -- |
| 1406 |
|
| 1407 |
// AggregationPipelineSimpleValue is a simple value, returned e.g. by a |
| 1408 |
// MovAvg aggregation. |
| 1409 |
type AggregationPipelineSimpleValue struct { |
| 1410 |
Aggregations |
| 1411 |
|
| 1412 |
Value *float64 // `json:"value"` |
| 1413 |
ValueAsString string // `json:"value_as_string"` |
| 1414 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 1415 |
} |
| 1416 |
|
| 1417 |
// UnmarshalJSON decodes JSON data and initializes an AggregationPipelineSimpleValue structure. |
| 1418 |
func (a *AggregationPipelineSimpleValue) UnmarshalJSON(data []byte) error { |
| 1419 |
var aggs map[string]*json.RawMessage |
| 1420 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1421 |
return err |
| 1422 |
} |
| 1423 |
if v, ok := aggs["value"]; ok && v != nil { |
| 1424 |
json.Unmarshal(*v, &a.Value) |
| 1425 |
} |
| 1426 |
if v, ok := aggs["value_as_string"]; ok && v != nil { |
| 1427 |
json.Unmarshal(*v, &a.ValueAsString) |
| 1428 |
} |
| 1429 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 1430 |
json.Unmarshal(*v, &a.Meta) |
| 1431 |
} |
| 1432 |
a.Aggregations = aggs |
| 1433 |
return nil |
| 1434 |
} |
| 1435 |
|
| 1436 |
// -- Pipeline simple value -- |
| 1437 |
|
| 1438 |
// AggregationPipelineBucketMetricValue is a value returned e.g. by a |
| 1439 |
// MaxBucket aggregation. |
| 1440 |
type AggregationPipelineBucketMetricValue struct { |
| 1441 |
Aggregations |
| 1442 |
|
| 1443 |
Keys []interface{} // `json:"keys"` |
| 1444 |
Value *float64 // `json:"value"` |
| 1445 |
ValueAsString string // `json:"value_as_string"` |
| 1446 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 1447 |
} |
| 1448 |
|
| 1449 |
// UnmarshalJSON decodes JSON data and initializes an AggregationPipelineBucketMetricValue structure. |
| 1450 |
func (a *AggregationPipelineBucketMetricValue) UnmarshalJSON(data []byte) error { |
| 1451 |
var aggs map[string]*json.RawMessage |
| 1452 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1453 |
return err |
| 1454 |
} |
| 1455 |
if v, ok := aggs["keys"]; ok && v != nil { |
| 1456 |
json.Unmarshal(*v, &a.Keys) |
| 1457 |
} |
| 1458 |
if v, ok := aggs["value"]; ok && v != nil { |
| 1459 |
json.Unmarshal(*v, &a.Value) |
| 1460 |
} |
| 1461 |
if v, ok := aggs["value_as_string"]; ok && v != nil { |
| 1462 |
json.Unmarshal(*v, &a.ValueAsString) |
| 1463 |
} |
| 1464 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 1465 |
json.Unmarshal(*v, &a.Meta) |
| 1466 |
} |
| 1467 |
a.Aggregations = aggs |
| 1468 |
return nil |
| 1469 |
} |
| 1470 |
|
| 1471 |
// -- Pipeline derivative -- |
| 1472 |
|
| 1473 |
// AggregationPipelineDerivative is the value returned by a |
| 1474 |
// Derivative aggregation. |
| 1475 |
type AggregationPipelineDerivative struct { |
| 1476 |
Aggregations |
| 1477 |
|
| 1478 |
Value *float64 // `json:"value"` |
| 1479 |
ValueAsString string // `json:"value_as_string"` |
| 1480 |
NormalizedValue *float64 // `json:"normalized_value"` |
| 1481 |
NormalizedValueAsString string // `json:"normalized_value_as_string"` |
| 1482 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 1483 |
} |
| 1484 |
|
| 1485 |
// UnmarshalJSON decodes JSON data and initializes an AggregationPipelineDerivative structure. |
| 1486 |
func (a *AggregationPipelineDerivative) UnmarshalJSON(data []byte) error { |
| 1487 |
var aggs map[string]*json.RawMessage |
| 1488 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1489 |
return err |
| 1490 |
} |
| 1491 |
if v, ok := aggs["value"]; ok && v != nil { |
| 1492 |
json.Unmarshal(*v, &a.Value) |
| 1493 |
} |
| 1494 |
if v, ok := aggs["value_as_string"]; ok && v != nil { |
| 1495 |
json.Unmarshal(*v, &a.ValueAsString) |
| 1496 |
} |
| 1497 |
if v, ok := aggs["normalized_value"]; ok && v != nil { |
| 1498 |
json.Unmarshal(*v, &a.NormalizedValue) |
| 1499 |
} |
| 1500 |
if v, ok := aggs["normalized_value_as_string"]; ok && v != nil { |
| 1501 |
json.Unmarshal(*v, &a.NormalizedValueAsString) |
| 1502 |
} |
| 1503 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 1504 |
json.Unmarshal(*v, &a.Meta) |
| 1505 |
} |
| 1506 |
a.Aggregations = aggs |
| 1507 |
return nil |
| 1508 |
} |
| 1509 |
|
| 1510 |
// -- Pipeline stats metric -- |
| 1511 |
|
| 1512 |
// AggregationPipelineStatsMetric is a simple value, returned e.g. by a |
| 1513 |
// MovAvg aggregation. |
| 1514 |
type AggregationPipelineStatsMetric struct { |
| 1515 |
Aggregations |
| 1516 |
|
| 1517 |
Count int64 // `json:"count"` |
| 1518 |
CountAsString string // `json:"count_as_string"` |
| 1519 |
Min *float64 // `json:"min"` |
| 1520 |
MinAsString string // `json:"min_as_string"` |
| 1521 |
Max *float64 // `json:"max"` |
| 1522 |
MaxAsString string // `json:"max_as_string"` |
| 1523 |
Avg *float64 // `json:"avg"` |
| 1524 |
AvgAsString string // `json:"avg_as_string"` |
| 1525 |
Sum *float64 // `json:"sum"` |
| 1526 |
SumAsString string // `json:"sum_as_string"` |
| 1527 |
|
| 1528 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 1529 |
} |
| 1530 |
|
| 1531 |
// UnmarshalJSON decodes JSON data and initializes an AggregationPipelineStatsMetric structure. |
| 1532 |
func (a *AggregationPipelineStatsMetric) UnmarshalJSON(data []byte) error { |
| 1533 |
var aggs map[string]*json.RawMessage |
| 1534 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1535 |
return err |
| 1536 |
} |
| 1537 |
if v, ok := aggs["count"]; ok && v != nil { |
| 1538 |
json.Unmarshal(*v, &a.Count) |
| 1539 |
} |
| 1540 |
if v, ok := aggs["count_as_string"]; ok && v != nil { |
| 1541 |
json.Unmarshal(*v, &a.CountAsString) |
| 1542 |
} |
| 1543 |
if v, ok := aggs["min"]; ok && v != nil { |
| 1544 |
json.Unmarshal(*v, &a.Min) |
| 1545 |
} |
| 1546 |
if v, ok := aggs["min_as_string"]; ok && v != nil { |
| 1547 |
json.Unmarshal(*v, &a.MinAsString) |
| 1548 |
} |
| 1549 |
if v, ok := aggs["max"]; ok && v != nil { |
| 1550 |
json.Unmarshal(*v, &a.Max) |
| 1551 |
} |
| 1552 |
if v, ok := aggs["max_as_string"]; ok && v != nil { |
| 1553 |
json.Unmarshal(*v, &a.MaxAsString) |
| 1554 |
} |
| 1555 |
if v, ok := aggs["avg"]; ok && v != nil { |
| 1556 |
json.Unmarshal(*v, &a.Avg) |
| 1557 |
} |
| 1558 |
if v, ok := aggs["avg_as_string"]; ok && v != nil { |
| 1559 |
json.Unmarshal(*v, &a.AvgAsString) |
| 1560 |
} |
| 1561 |
if v, ok := aggs["sum"]; ok && v != nil { |
| 1562 |
json.Unmarshal(*v, &a.Sum) |
| 1563 |
} |
| 1564 |
if v, ok := aggs["sum_as_string"]; ok && v != nil { |
| 1565 |
json.Unmarshal(*v, &a.SumAsString) |
| 1566 |
} |
| 1567 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 1568 |
json.Unmarshal(*v, &a.Meta) |
| 1569 |
} |
| 1570 |
a.Aggregations = aggs |
| 1571 |
return nil |
| 1572 |
} |
| 1573 |
|
| 1574 |
// -- Pipeline percentiles |
| 1575 |
|
| 1576 |
// AggregationPipelinePercentilesMetric is the value returned by a pipeline |
| 1577 |
// percentiles Metric aggregation |
| 1578 |
type AggregationPipelinePercentilesMetric struct { |
| 1579 |
Aggregations |
| 1580 |
|
| 1581 |
Values map[string]float64 // `json:"values"` |
| 1582 |
Meta map[string]interface{} // `json:"meta,omitempty"` |
| 1583 |
} |
| 1584 |
|
| 1585 |
// UnmarshalJSON decodes JSON data and initializes an AggregationPipelinePercentilesMetric structure. |
| 1586 |
func (a *AggregationPipelinePercentilesMetric) UnmarshalJSON(data []byte) error { |
| 1587 |
var aggs map[string]*json.RawMessage |
| 1588 |
if err := json.Unmarshal(data, &aggs); err != nil { |
| 1589 |
return err |
| 1590 |
} |
| 1591 |
if v, ok := aggs["values"]; ok && v != nil { |
| 1592 |
json.Unmarshal(*v, &a.Values) |
| 1593 |
} |
| 1594 |
if v, ok := aggs["meta"]; ok && v != nil { |
| 1595 |
json.Unmarshal(*v, &a.Meta) |
| 1596 |
} |
| 1597 |
a.Aggregations = aggs |
| 1598 |
return nil |
| 1599 |
} |