Documentation ¶
Index ¶
- Constants
- Variables
- type Agg
- type AggArray
- type AggBuilder
- type Aggregation
- type BoolQuery
- type BoolQueryBuilder
- type Client
- type DateHistogramAgg
- type ExtendedBounds
- type Filter
- type FilterQueryBuilder
- type FiltersAggregation
- type GeoHashGridAggregation
- type HistogramAgg
- type MetricAggregation
- type MultiSearchRequest
- type MultiSearchRequestBuilder
- type MultiSearchResponse
- type PipelineAggregation
- type Query
- type QueryBuilder
- type QueryStringFilter
- type RangeFilter
- type SearchRequest
- type SearchRequestBuilder
- func (b *SearchRequestBuilder) AddDocValueField(field string) *SearchRequestBuilder
- func (b *SearchRequestBuilder) Agg() AggBuilder
- func (b *SearchRequestBuilder) Build() (*SearchRequest, error)
- func (b *SearchRequestBuilder) Query() *QueryBuilder
- func (b *SearchRequestBuilder) Size(size int) *SearchRequestBuilder
- func (b *SearchRequestBuilder) SortDesc(field, unmappedType string) *SearchRequestBuilder
- type SearchResponse
- type SearchResponseHits
- type TermsAggregation
Constants ¶
const DateFormatEpochMS = "epoch_millis"
DateFormatEpochMS represents a date format of epoch milliseconds (epoch_millis)
Variables ¶
var NewClient = func(ctx context.Context, ds *models.DataSource, timeRange *tsdb.TimeRange) (Client, error) { version, err := ds.JsonData.Get("esVersion").Int() if err != nil { return nil, fmt.Errorf("elasticsearch version is required, err=%v", err) } timeField, err := ds.JsonData.Get("timeField").String() if err != nil { return nil, fmt.Errorf("elasticsearch time field name is required, err=%v", err) } indexInterval := ds.JsonData.Get("interval").MustString() ip, err := newIndexPattern(indexInterval, ds.Database) if err != nil { return nil, err } indices, err := ip.GetIndices(timeRange) if err != nil { return nil, err } clientLog.Debug("Creating new client", "version", version, "timeField", timeField, "indices", strings.Join(indices, ", ")) switch version { case 2, 5, 56: return &baseClientImpl{ ctx: ctx, ds: ds, version: version, timeField: timeField, indices: indices, timeRange: timeRange, }, nil } return nil, fmt.Errorf("elasticsearch version=%d is not supported", version) }
NewClient creates a new elasticsearch client
Functions ¶
This section is empty.
Types ¶
type Agg ¶
type Agg struct { Key string Aggregation *aggContainer }
Agg represents a key and aggregation
func (*Agg) MarshalJSON ¶
MarshalJSON returns the JSON encoding of the agg
type AggArray ¶
type AggArray []*Agg
AggArray represents a collection of key/aggregation pairs
func (AggArray) MarshalJSON ¶
MarshalJSON returns the JSON encoding of the agg
type AggBuilder ¶
type AggBuilder interface { Histogram(key, field string, fn func(a *HistogramAgg, b AggBuilder)) AggBuilder DateHistogram(key, field string, fn func(a *DateHistogramAgg, b AggBuilder)) AggBuilder Terms(key, field string, fn func(a *TermsAggregation, b AggBuilder)) AggBuilder Filters(key string, fn func(a *FiltersAggregation, b AggBuilder)) AggBuilder GeoHashGrid(key, field string, fn func(a *GeoHashGridAggregation, b AggBuilder)) AggBuilder Metric(key, metricType, field string, fn func(a *MetricAggregation)) AggBuilder Pipeline(key, pipelineType, bucketPath string, fn func(a *PipelineAggregation)) AggBuilder Build() (AggArray, error) }
AggBuilder represents an aggregation builder
type BoolQuery ¶
type BoolQuery struct {
Filters []Filter
}
BoolQuery represents a bool query
func (*BoolQuery) MarshalJSON ¶
MarshalJSON returns the JSON encoding of the boolean query.
type BoolQueryBuilder ¶
type BoolQueryBuilder struct {
// contains filtered or unexported fields
}
BoolQueryBuilder represents a bool query builder
func NewBoolQueryBuilder ¶
func NewBoolQueryBuilder() *BoolQueryBuilder
NewBoolQueryBuilder create a new bool query builder
func (*BoolQueryBuilder) Build ¶
func (b *BoolQueryBuilder) Build() (*BoolQuery, error)
Build builds and return a bool query builder
func (*BoolQueryBuilder) Filter ¶
func (b *BoolQueryBuilder) Filter() *FilterQueryBuilder
Filter creates and return a filter query builder
type Client ¶
type Client interface { GetVersion() int GetTimeField() string GetMinInterval(queryInterval string) (time.Duration, error) ExecuteMultisearch(r *MultiSearchRequest) (*MultiSearchResponse, error) MultiSearch() *MultiSearchRequestBuilder }
Client represents a client which can interact with elasticsearch api
type DateHistogramAgg ¶
type DateHistogramAgg struct { Field string `json:"field"` Interval string `json:"interval,omitempty"` MinDocCount int `json:"min_doc_count"` Missing *string `json:"missing,omitempty"` ExtendedBounds *ExtendedBounds `json:"extended_bounds"` Format string `json:"format"` }
DateHistogramAgg represents a date histogram aggregation
type ExtendedBounds ¶
ExtendedBounds represents extended bounds
type FilterQueryBuilder ¶
type FilterQueryBuilder struct {
// contains filtered or unexported fields
}
FilterQueryBuilder represents a filter query builder
func NewFilterQueryBuilder ¶
func NewFilterQueryBuilder() *FilterQueryBuilder
NewFilterQueryBuilder creates a new filter query builder
func (*FilterQueryBuilder) AddDateRangeFilter ¶
func (b *FilterQueryBuilder) AddDateRangeFilter(timeField, lte, gte, format string) *FilterQueryBuilder
AddDateRangeFilter adds a new time range filter
func (*FilterQueryBuilder) AddQueryStringFilter ¶
func (b *FilterQueryBuilder) AddQueryStringFilter(querystring string, analyseWildcard bool) *FilterQueryBuilder
AddQueryStringFilter adds a new query string filter
func (*FilterQueryBuilder) Build ¶
func (b *FilterQueryBuilder) Build() ([]Filter, error)
Build builds and return a filter query builder
type FiltersAggregation ¶
type FiltersAggregation struct {
Filters map[string]interface{} `json:"filters"`
}
FiltersAggregation represents a filters aggregation
type GeoHashGridAggregation ¶
GeoHashGridAggregation represents a geo hash grid aggregation
type HistogramAgg ¶
type HistogramAgg struct { Interval int `json:"interval,omitempty"` Field string `json:"field"` MinDocCount int `json:"min_doc_count"` Missing *int `json:"missing,omitempty"` }
HistogramAgg represents a histogram aggregation
type MetricAggregation ¶
MetricAggregation represents a metric aggregation
func (*MetricAggregation) MarshalJSON ¶
func (a *MetricAggregation) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the metric aggregation
type MultiSearchRequest ¶
type MultiSearchRequest struct {
Requests []*SearchRequest
}
MultiSearchRequest represents a multi search request
type MultiSearchRequestBuilder ¶
type MultiSearchRequestBuilder struct {
// contains filtered or unexported fields
}
MultiSearchRequestBuilder represents a builder which can build a multi search request
func NewMultiSearchRequestBuilder ¶
func NewMultiSearchRequestBuilder(version int) *MultiSearchRequestBuilder
NewMultiSearchRequestBuilder creates a new multi search request builder
func (*MultiSearchRequestBuilder) Build ¶
func (m *MultiSearchRequestBuilder) Build() (*MultiSearchRequest, error)
Build builds and return a multi search request
func (*MultiSearchRequestBuilder) Search ¶
func (m *MultiSearchRequestBuilder) Search(interval tsdb.Interval) *SearchRequestBuilder
Search initiates and returns a new search request builder
type MultiSearchResponse ¶
type MultiSearchResponse struct { Status int `json:"status,omitempty"` Responses []*SearchResponse `json:"responses"` }
MultiSearchResponse represents a multi search response
type PipelineAggregation ¶
PipelineAggregation represents a metric aggregation
func (*PipelineAggregation) MarshalJSON ¶
func (a *PipelineAggregation) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the pipeline aggregation
type QueryBuilder ¶
type QueryBuilder struct {
// contains filtered or unexported fields
}
QueryBuilder represents a query builder
func NewQueryBuilder ¶
func NewQueryBuilder() *QueryBuilder
NewQueryBuilder create a new query builder
func (*QueryBuilder) Bool ¶
func (b *QueryBuilder) Bool() *BoolQueryBuilder
Bool creates and return a query builder
func (*QueryBuilder) Build ¶
func (b *QueryBuilder) Build() (*Query, error)
Build builds and return a query builder
type QueryStringFilter ¶
QueryStringFilter represents a query string search filter
func (*QueryStringFilter) MarshalJSON ¶
func (f *QueryStringFilter) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the query string filter.
type RangeFilter ¶
RangeFilter represents a range search filter
func (*RangeFilter) MarshalJSON ¶
func (f *RangeFilter) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the query string filter.
type SearchRequest ¶
type SearchRequest struct { Index string Interval tsdb.Interval Size int Sort map[string]interface{} Query *Query Aggs AggArray CustomProps map[string]interface{} }
SearchRequest represents a search request
func (*SearchRequest) MarshalJSON ¶
func (r *SearchRequest) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the request.
type SearchRequestBuilder ¶
type SearchRequestBuilder struct {
// contains filtered or unexported fields
}
SearchRequestBuilder represents a builder which can build a search request
func NewSearchRequestBuilder ¶
func NewSearchRequestBuilder(version int, interval tsdb.Interval) *SearchRequestBuilder
NewSearchRequestBuilder create a new search request builder
func (*SearchRequestBuilder) AddDocValueField ¶
func (b *SearchRequestBuilder) AddDocValueField(field string) *SearchRequestBuilder
AddDocValueField adds a doc value field to the search request
func (*SearchRequestBuilder) Agg ¶
func (b *SearchRequestBuilder) Agg() AggBuilder
Agg initaite and returns a new aggregation builder
func (*SearchRequestBuilder) Build ¶
func (b *SearchRequestBuilder) Build() (*SearchRequest, error)
Build builds and return a search request
func (*SearchRequestBuilder) Query ¶
func (b *SearchRequestBuilder) Query() *QueryBuilder
Query creates and return a query builder
func (*SearchRequestBuilder) Size ¶
func (b *SearchRequestBuilder) Size(size int) *SearchRequestBuilder
Size sets the size of the search request
func (*SearchRequestBuilder) SortDesc ¶
func (b *SearchRequestBuilder) SortDesc(field, unmappedType string) *SearchRequestBuilder
SortDesc adds a sort to the search request
type SearchResponse ¶
type SearchResponse struct { Error map[string]interface{} `json:"error"` Aggregations map[string]interface{} `json:"aggregations"` Hits *SearchResponseHits `json:"hits"` }
SearchResponse represents a search response
type SearchResponseHits ¶
SearchResponseHits represents search response hits