Help us shape the future of Go! Take the 2026 Go Developer Survey

elasticsearch

package
v1.4.33 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package elasticsearch provides bounded, read-only access to one configured Elasticsearch log source.

Index

Constants

View Source
const (
	DefaultLimit                 = 20
	MaximumLimit                 = 50
	MaximumFields                = 32
	MaximumMappingFieldsPerIndex = 50
)

Variables

View Source
var (
	ErrInvalidConfig    = errors.New("elasticsearch: invalid source configuration")
	ErrInvalidArguments = errors.New("elasticsearch: invalid arguments")
	ErrUnauthorized     = errors.New("elasticsearch: unauthorized")
	ErrForbidden        = errors.New("elasticsearch: forbidden")
	ErrNotFound         = errors.New("elasticsearch: not found")
	ErrResponseTooLarge = errors.New("elasticsearch: response too large")
	ErrBackend          = errors.New("elasticsearch: backend unavailable")
	ErrShardFailure     = errors.New("elasticsearch: search failed on one or more shards")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client owns transport, authentication, failover, and source index scoping.

func NewClient

NewClient constructs a client from the same source configuration used by signal tailing. The configured index is the only index this client can read.

func (*Client) ClearIngestScroll

func (client *Client) ClearIngestScroll(ctx context.Context, address, scrollID string) error

ClearIngestScroll releases a server-side snapshot even after Pull is canceled.

func (*Client) NextIngestScroll

func (client *Client) NextIngestScroll(ctx context.Context, address, scrollID string, output any) error

NextIngestScroll reads the next page from a scroll opened by this client.

func (*Client) OpenIngestScroll

func (client *Client) OpenIngestScroll(ctx context.Context, body []byte, output any) (string, error)

OpenIngestScroll starts an index-scoped snapshot and returns its route.

func (*Client) SearchIngestJSON

func (client *Client) SearchIngestJSON(ctx context.Context, body []byte, output any) error

SearchIngestJSON executes a tail search with the historical 30-second operation timeout and a bounded response budget sized for structured pages.

func (*Client) SearchIngestJSONWithPreference

func (client *Client) SearchIngestJSONWithPreference(ctx context.Context, preference string, body []byte, output any) error

SearchIngestJSONWithPreference is SearchIngestJSON with an Elasticsearch `preference` routing value, so requests sharing it hit the same shard copies. An empty preference sends none.

func (*Client) SearchJSON

func (client *Client) SearchJSON(ctx context.Context, body []byte, output any) error

SearchJSON executes a bounded POST _search against the configured index. It exists for both the application service and the signal tail source.

type Index

type Index struct {
	Name      string `json:"name"`
	Status    string `json:"status,omitempty"`
	Documents uint64 `json:"documents,omitempty"`
}

type IndexMapping

type IndexMapping struct {
	Index       string         `json:"index"`
	Fields      []MappingField `json:"fields"`
	TotalFields int            `json:"total_fields"`
	Truncated   bool           `json:"truncated"`
}

type IndexResult

type IndexResult struct {
	Total     int     `json:"total"`
	Truncated bool    `json:"truncated"`
	Items     []Index `json:"items"`
}

type MappingField

type MappingField struct {
	Name string `json:"name"`
	Type string `json:"type,omitempty"`
}

type MappingResult

type MappingResult struct {
	TotalIndices           int            `json:"total_indices"`
	Truncated              bool           `json:"truncated"`
	AllowedFields          []string       `json:"allowed_fields"`
	AllowedFieldsTruncated bool           `json:"allowed_fields_truncated"`
	Items                  []IndexMapping `json:"items"`
}

type SearchHit

type SearchHit struct {
	ID     string         `json:"id,omitempty"`
	Fields map[string]any `json:"fields"`
}

type SearchOptions

type SearchOptions struct {
	QueryBody json.RawMessage
	Fields    []string
	Limit     int
}

type SearchResult

type SearchResult struct {
	Total     uint64      `json:"total"`
	Relation  string      `json:"relation"`
	TimedOut  bool        `json:"timed_out"`
	Truncated bool        `json:"truncated"`
	Hits      []SearchHit `json:"hits"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides provider-neutral, bounded reads for one configured source.

func NewService

NewService constructs one source-scoped application service.

func (*Service) Client

func (service *Service) Client() *Client

Client returns the shared source-scoped transport used by signal tailing.

func (*Service) Config

func (service *Service) Config() config.AgentElasticsearchSourceConfig

Config returns the normalized source configuration used by this service.

func (*Service) ListIndices

func (service *Service) ListIndices(ctx context.Context, limit int) (IndexResult, error)

ListIndices discovers indices matching only the configured pattern.

func (*Service) Mappings

func (service *Service) Mappings(ctx context.Context, limit int) (MappingResult, error)

Mappings returns a flattened, bounded field map for matching indices.

func (*Service) PreviewSearch added in v1.4.32

func (service *Service) PreviewSearch(options SearchOptions) (json.RawMessage, error)

func (*Service) ProjectedFields

func (service *Service) ProjectedFields() []string

ProjectedFields returns the validated fields this source may retrieve.

func (*Service) Search

func (service *Service) Search(ctx context.Context, options SearchOptions) (SearchResult, error)

func (*Service) SearchWithPrefix added in v1.4.32

func (service *Service) SearchWithPrefix(ctx context.Context, options SearchOptions) (SearchResult, error)

Search executes sanitized Query DSL and projects only configured source fields.

func (*Service) SetScrubber

func (service *Service) SetScrubber(scrubber core.Scrubber)

SetScrubber applies the shared redaction policy to every backend string before a result can cross the application-service boundary.

func (*Service) Shards

func (service *Service) Shards(ctx context.Context, limit int) (ShardResult, error)

Shards returns bounded health fields for shards in the configured pattern.

type Shard

type Shard struct {
	Index     string  `json:"index"`
	Shard     int     `json:"shard"`
	Primary   bool    `json:"primary"`
	State     string  `json:"state"`
	Documents *uint64 `json:"documents,omitempty"`
	Store     string  `json:"store,omitempty"`
	Node      string  `json:"node,omitempty"`
}

type ShardResult

type ShardResult struct {
	Total     int     `json:"total"`
	Truncated bool    `json:"truncated"`
	Items     []Shard `json:"items"`
}

type ShardStats

type ShardStats struct {
	Total    int `json:"total"`
	Failed   int `json:"failed"`
	Failures []struct {
		Reason struct {
			Type   string `json:"type"`
			Reason string `json:"reason"`
		} `json:"reason"`
	} `json:"failures"`
}

ShardStats is the `_shards` header of a search response. Elasticsearch reports per-shard query failures (for example sorting on an unmapped field) with HTTP 200 and zero hits, so callers must check it before trusting hits.

func (ShardStats) Err

func (stats ShardStats) Err() error

Err returns ErrShardFailure with the failure count and a bounded, printable first reason when any shard failed, and nil otherwise.

Jump to

Keyboard shortcuts

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