es

package
v0.0.0-test Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: AGPL-3.0 Imports: 20 Imported by: 87

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, httpClientProvider httpclient.Provider, ds *DatasourceInfo, timeRange backend.TimeRange) (Client, error) {
	ip, err := newIndexPattern(ds.Interval, 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", ds.ESVersion, "timeField", ds.TimeField, "indices", strings.Join(indices, ", "))

	return &baseClientImpl{
		ctx:                ctx,
		httpClientProvider: httpClientProvider,
		ds:                 ds,
		version:            ds.ESVersion,
		timeField:          ds.TimeField,
		indices:            indices,
		timeRange:          timeRange,
	}, nil
}

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() *semver.Version
	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 DatasourceInfo

type DatasourceInfo struct {
	ID                         int64
	HTTPClientOpts             sdkhttpclient.Options
	URL                        string
	Database                   string
	ESVersion                  *semver.Version
	TimeField                  string
	Interval                   string
	TimeInterval               string
	MaxConcurrentShardRequests int64
	IncludeFrozen              bool
	XPack                      bool
}

type DateHistogramAgg

type DateHistogramAgg struct {
	Field          string          `json:"field"`
	Interval       string          `json:"interval,omitempty"`
	FixedInterval  string          `json:"fixed_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"`
	TimeZone       string          `json:"time_zone,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 {
	Type     string
	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 *semver.Version) *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    intervalv2.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 *semver.Version, interval intervalv2.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