es

package
v0.0.0-kmdagger1 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: AGPL-3.0 Imports: 13 Imported by: 82

Documentation

Index

Constants

View Source
const (
	HighlightPreTagsString  = "@HIGHLIGHT@"
	HighlightPostTagsString = "@/HIGHLIGHT@"
	HighlightFragmentSize   = 2147483647
)
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 *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
	}

	logger := log.New(loggerName).FromContext(ctx)
	logger.Debug("Creating new client", "configuredFields", fmt.Sprintf("%#v", ds.ConfiguredFields), "indices", strings.Join(indices, ", "))

	return &baseClientImpl{
		logger:           logger,
		ctx:              ctx,
		ds:               ds,
		configuredFields: ds.ConfiguredFields,
		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
	Nested(key, path string, fn func(a *NestedAggregation, 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 {
	GetConfiguredFields() ConfiguredFields
	ExecuteMultisearch(r *MultiSearchRequest) (*MultiSearchResponse, error)
	MultiSearch() *MultiSearchRequestBuilder
}

Client represents a client which can interact with elasticsearch api

type ConfiguredFields

type ConfiguredFields struct {
	TimeField       string
	LogMessageField string
	LogLevelField   string
}

type DatasourceInfo

type DatasourceInfo struct {
	ID                         int64
	HTTPClient                 *http.Client
	URL                        string
	Database                   string
	ConfiguredFields           ConfiguredFields
	Interval                   string
	TimeInterval               string
	MaxConcurrentShardRequests int64
	IncludeFrozen              bool
	XPack                      bool
}

type DateHistogramAgg

type DateHistogramAgg struct {
	Field          string          `json:"field"`
	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 int64 `json:"min"`
	Max int64 `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 string, lte, gte int64, 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() *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"`
}

MultiSearchResponse represents a multi search response

type NestedAggregation

type NestedAggregation struct {
	Path string `json:"path"`
}

NestedAggregation represents a nested aggregation

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    int64
	Lte    int64
	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 SearchRequest

type SearchRequest struct {
	Index       string
	Interval    time.Duration
	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(interval time.Duration) *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) AddHighlight

func (b *SearchRequestBuilder) AddHighlight() *SearchRequestBuilder

Add highlights to the search request for log queries

func (*SearchRequestBuilder) AddSearchAfter

func (b *SearchRequestBuilder) AddSearchAfter(value interface{}) *SearchRequestBuilder

func (*SearchRequestBuilder) AddTimeFieldWithStandardizedFormat

func (b *SearchRequestBuilder) AddTimeFieldWithStandardizedFormat(timeField string) *SearchRequestBuilder

AddTimeFieldWithStandardizedFormat adds a time field to fields with standardized time format

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) Sort

func (b *SearchRequestBuilder) Sort(order SortOrder, field string, unmappedType string) *SearchRequestBuilder

Sort adds a "asc" | "desc" 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

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

SearchResponseHits represents search response hits

type SortOrder

type SortOrder string
const (
	SortOrderAsc  SortOrder = "asc"
	SortOrderDesc SortOrder = "desc"
)

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