1
0
Fork 0

Adding upstream version 1.34.4.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-24 07:26:29 +02:00
parent e393c3af3f
commit 4978089aab
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
4963 changed files with 677545 additions and 0 deletions

View file

@ -0,0 +1,60 @@
package opensearch_query
import (
"encoding/json"
)
type aggregationRequest interface {
addAggregation(string, string, string) error
}
type aggregationFunction struct {
aggType string
field string
size int
missing string
nested aggregationRequest
}
// MarshalJSON serializes the aggregationFunction into JSON format.
func (a *aggregationFunction) MarshalJSON() ([]byte, error) {
agg := make(map[string]interface{})
field := map[string]interface{}{"field": a.field}
if t := getAggregationFunctionType(a.aggType); t == "bucket" {
// We'll use the default size of 10 if it hasn't been set; size == 0 is illegal in a bucket aggregation
if a.size == 0 {
a.size = 10
}
field["size"] = a.size
}
if a.missing != "" {
field["missing"] = a.missing
}
agg[a.aggType] = field
if a.nested != nil {
agg["aggregations"] = a.nested
}
return json.Marshal(agg)
}
func (a *aggregationFunction) setSize(size int) {
a.size = size
}
func (a *aggregationFunction) setMissing(missing string) {
a.missing = missing
}
func getAggregationFunctionType(field string) string {
switch field {
case "avg", "sum", "min", "max", "value_count", "stats", "extended_stats", "percentiles":
return "metric"
case "terms":
return "bucket"
default:
return ""
}
}