elasticsearch

package
v0.0.1-releasedebug Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AggregationNameForKey is the key used within the Elasticsearch query's "aggs" section
	// for the primary terms aggregation requested by the exporter.
	AggregationNameForKey = "uex_term_aggregation"
	// TopHitsAggregationNameForKey is the key for the nested top_hits aggregation
	// used to retrieve source fields within buckets.
	TopHitsAggregationNameForKey = "source_doc"
)

Variables

This section is empty.

Functions

func GetBucketKeyAsString

func GetBucketKeyAsString(key interface{}) string

GetBucketKeyAsString safely converts an aggregation bucket key (interface{}) to its string representation.

Types

type AggregationBucket

type AggregationBucket struct {
	Key      interface{} `json:"key"`       // The bucket key (string, number, bool, etc.)
	DocCount int64       `json:"doc_count"` // Count of documents in the bucket
	// SourceDoc holds the result of the "source_doc" top_hits sub-aggregation, if requested.
	SourceDoc *TopHitsAggregationResult `json:"source_doc,omitempty"`
}

AggregationBucket represents a single bucket in an aggregation result. It now includes an optional field to hold nested top_hits results for source fields.

type Aggregations

type Aggregations map[string]json.RawMessage

Aggregations represents the raw "aggregations" part of an Elasticsearch response. We use RawMessage to delay parsing until we know the specific aggregation type.

type Client

type Client struct {
	Cfg *config.ConnectionConfig
	// contains filtered or unexported fields
}

Client wraps the official Elasticsearch client.

func NewClient

func NewClient(cfg *config.ConnectionConfig) (*Client, error)

NewClient creates and configures a new Elasticsearch client wrapper.

func (*Client) GetESClient

func (c *Client) GetESClient() *elasticsearch.Client

GetESClient returns the underlying raw Elasticsearch client if needed for advanced operations.

func (*Client) RunQuery

func (c *Client) RunQuery(ctx context.Context, metricCfg *config.MetricConfig) (*SearchResponse, error)

RunQuery executes a query defined by MetricConfig against Elasticsearch. It handles both terms aggregations and direct search queries.

type DocHit

type DocHit struct {
	Index  string                 `json:"_index"`  // Index the document belongs to
	ID     string                 `json:"_id"`     // Document ID
	Score  *float64               `json:"_score"`  // Relevance score (can be null)
	Source map[string]interface{} `json:"_source"` // The actual source document content

}

DocHit represents a single document hit in the search results.

type HitsInfo

type HitsInfo struct {
	Total    TotalHits `json:"total"`     // Total number of matching documents
	MaxScore *float64  `json:"max_score"` // Maximum score of matching documents (can be null)
	Hits     []DocHit  `json:"hits"`      // The actual document hits
}

HitsInfo provides information about the search hits (documents found).

type SearchResponse

type SearchResponse struct {
	Took         int          `json:"took"`                   // Time in milliseconds
	TimedOut     bool         `json:"timed_out"`              // Whether the query timed out
	Shards       ShardsInfo   `json:"_shards"`                // Information about shard execution
	Hits         HitsInfo     `json:"hits"`                   // Document hits (for direct searches)
	Aggregations Aggregations `json:"aggregations,omitempty"` // Aggregation results
	Error        interface{}  `json:"error,omitempty"`        // Holds error details if the request failed at ES level
}

SearchResponse represents the relevant parts of an Elasticsearch search response.

type ShardsInfo

type ShardsInfo struct {
	Total      int `json:"total"`      // Total shards queried
	Successful int `json:"successful"` // Shards that succeeded
	Skipped    int `json:"skipped"`    // Shards that were skipped
	Failed     int `json:"failed"`     // Shards that failed

}

ShardsInfo provides information about the shards involved in the search.

type TermsAggregationResult

type TermsAggregationResult struct {
	DocCountErrorUpperBound int64               `json:"doc_count_error_upper_bound"`
	SumOtherDocCount        int64               `json:"sum_other_doc_count"`
	Buckets                 []AggregationBucket `json:"buckets"` // Changed to use AggregationBucket which includes SourceDoc
}

TermsAggregationResult represents the primary result of a terms aggregation.

type TopHitsAggregationResult

type TopHitsAggregationResult struct {
	Hits HitsInfo `json:"hits"` // Embedded HitsInfo structure
}

TopHitsAggregationResult holds the results of a top_hits sub-aggregation.

type TotalHits

type TotalHits struct {
	Value    int64  `json:"value"`    // The total count
	Relation string `json:"relation"` // "eq" (exact) or "gte" (lower bound)
}

TotalHits holds the total number of documents matching the query.

Jump to

Keyboard shortcuts

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