Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
45
plugins/inputs/opensearch_query/query.go
Normal file
45
plugins/inputs/opensearch_query/query.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package opensearch_query
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type query struct {
|
||||
Size int `json:"size"`
|
||||
Aggregations aggregationRequest `json:"aggregations"`
|
||||
Query interface{} `json:"query,omitempty"`
|
||||
}
|
||||
|
||||
type boolQuery struct {
|
||||
FilterQueryString string
|
||||
TimestampField string
|
||||
TimeRangeFrom time.Time
|
||||
TimeRangeTo time.Time
|
||||
DateFieldFormat string
|
||||
}
|
||||
|
||||
// MarshalJSON customizes the JSON marshaling for boolQuery.
|
||||
func (b *boolQuery) MarshalJSON() ([]byte, error) {
|
||||
// Construct range
|
||||
dateTimeRange := map[string]interface{}{
|
||||
"from": b.TimeRangeFrom,
|
||||
"to": b.TimeRangeTo,
|
||||
"include_lower": true,
|
||||
"include_upper": true,
|
||||
}
|
||||
if b.DateFieldFormat != "" {
|
||||
dateTimeRange["format"] = b.DateFieldFormat
|
||||
}
|
||||
rangeFilter := map[string]map[string]interface{}{"range": {b.TimestampField: dateTimeRange}}
|
||||
|
||||
// Construct Filter
|
||||
queryFilter := map[string]map[string]interface{}{
|
||||
"query_string": {"query": b.FilterQueryString},
|
||||
}
|
||||
|
||||
// Construct boolean query
|
||||
bq := map[string]map[string]interface{}{"bool": {"filter": []interface{}{rangeFilter, queryFilter}}}
|
||||
|
||||
return json.Marshal(&bq)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue