es

package
v0.0.0-...-900be4e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DateFormatEpochMS = "epoch_millis"

DateFormatEpochMS represents a date format of epoch milliseconds (epoch_millis)

Variables

View Source
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, 60, 70:
		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

func (a *Agg) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the agg

type AggArray

type AggArray []*Agg

AggArray represents a collection of key/aggregation pairs

func (AggArray) MarshalJSON

func (a AggArray) MarshalJSON() ([]byte, error)

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 string, bucketPath interface{}, fn func(a *PipelineAggregation)) AggBuilder
	Build() (AggArray, error)
}

AggBuilder represents an aggregation builder

type Aggregation

type Aggregation interface{}

Aggregation represents an aggregation

type BoolQuery

type BoolQuery struct {
	Filters []Filter
}

BoolQuery represents a bool query

func (*BoolQuery) MarshalJSON

func (q *BoolQuery) MarshalJSON() ([]byte, error)

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
	EnableDebug()
}

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"`
	Offset         string          `json:"offset,omitempty"`
}

DateHistogramAgg represents a date histogram aggregation

type ExtendedBounds

type ExtendedBounds struct {
	Min string `json:"min"`
	Max string `json:"max"`
}

ExtendedBounds represents extended bounds

type Filter

type Filter interface{}

Filter represents a search filter

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

type GeoHashGridAggregation struct {
	Field     string `json:"field"`
	Precision int    `json:"precision"`
}

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

type MetricAggregation struct {
	Field    string
	Settings map[string]interface{}
}

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

Build builds and return a multi search request

func (*MultiSearchRequestBuilder) Search

Search initiates and returns a new search request builder

type MultiSearchResponse

type MultiSearchResponse struct {
	Status    int               `json:"status,omitempty"`
	Responses []*SearchResponse `json:"responses"`
	DebugInfo *SearchDebugInfo  `json:"-"`
}

MultiSearchResponse represents a multi search response

type PipelineAggregation

type PipelineAggregation struct {
	BucketPath interface{}
	Settings   map[string]interface{}
}

PipelineAggregation represents a metric aggregation

func (*PipelineAggregation) MarshalJSON

func (a *PipelineAggregation) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the pipeline aggregation

type Query

type Query struct {
	Bool *BoolQuery `json:"bool"`
}

Query represents a query

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

type QueryStringFilter struct {
	Filter
	Query           string
	AnalyzeWildcard bool
}

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

type RangeFilter struct {
	Filter
	Key    string
	Gte    string
	Lte    string
	Format string
}

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 SearchDebugInfo

type SearchDebugInfo struct {
	Request  *SearchRequestInfo  `json:"request"`
	Response *SearchResponseInfo `json:"response"`
}

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

Agg initiate 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

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 SearchRequestInfo

type SearchRequestInfo struct {
	Method string `json:"method"`
	Url    string `json:"url"`
	Data   string `json:"data"`
}

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

type SearchResponseHits struct {
	Hits []map[string]interface{}
}

SearchResponseHits represents search response hits

type SearchResponseInfo

type SearchResponseInfo struct {
	Status int              `json:"status"`
	Data   *simplejson.Json `json:"data"`
}

type TermsAggregation

type TermsAggregation struct {
	Field       string                 `json:"field"`
	Size        int                    `json:"size"`
	Order       map[string]interface{} `json:"order"`
	MinDocCount *int                   `json:"min_doc_count,omitempty"`
	Missing     *string                `json:"missing,omitempty"`
}

TermsAggregation represents a terms aggregation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL