opensearch

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: AGPL-3.0 Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExtractSource is returned when an error occurred extracting the source of a document from the response hits.
	ErrExtractSource      = errors.New("could not extract document _source")
	ErrExtractAggregation = errors.New("could not extract aggregation")
	ErrAggregationEmpty   = errors.New("aggregation is empty")
)
View Source
var GetClient = sync.OnceValues(func() (*Client, error) {
	appCfg, err := config.LoadAppConfig()
	if err != nil {
		return nil, fmt.Errorf("load app config: %w", err)
	}

	cfg, err := loadConfigOnce()
	if err != nil {
		return nil, fmt.Errorf("load config: %w", err)
	}
	var caFile []byte
	if cfg.CAFile != "" {
		var err error
		caFile, err = os.ReadFile(cfg.CAFile)
		if err != nil {
			return nil, fmt.Errorf("read ca file: %w", err)
		}
	}

	client, err := opensearchapi.NewClient(opensearchapi.Config{
		Client: opensearch.Config{
			Addresses:          cfg.Hosts,
			Username:           cfg.User,
			Password:           cfg.Password,
			InsecureSkipVerify: cfg.SkipTLSVerification,
			CACert:             caFile,
		},
	})
	if err != nil {
		return nil, fmt.Errorf("create client: %w", err)
	}

	slog.Debug("Loaded Opensearch client")

	return &Client{
		Client: client, environment: appCfg.GetAppEnvironment().String(),
		settings: cfg.Settings,
	}, nil
})

Functions

func ExtractSource

func ExtractSource[T any](doc json.RawMessage) (T, error)

ExtractSource extracts the `_source` field from the raw response.

func GenerateAPIError

func GenerateAPIError(msg string, resp Inspectable) *models.APIError

func HandleError

func HandleError(msg string, resp Inspectable, err error) *models.APIError

func NewRequestHeaders

func NewRequestHeaders(ctx context.Context) http.Header

NewRequestHeaders creates a http.Header object with headers that associate the OpenSearch request with any HTTP request that triggered it.

Types

type Client

type Client struct {
	*opensearchapi.Client
	// contains filtered or unexported fields
}

Client hold the underlying OpenSearch client and provides methods for interacting with OpenSearch.

func (*Client) ApplyClusterSettings added in v0.259.0

func (c *Client) ApplyClusterSettings(ctx context.Context) error

ApplyClusterSettings applies any cluster settings read from the config to the cluster. Generally, this should only be called when a new cluster is used or when the settings have changed.

func (*Client) Close added in v0.261.0

func (c *Client) Close() error

func (*Client) IndexCanonicalName

func (c *Client) IndexCanonicalName(name Index) string

IndexCanonicalName returns a unique, time-stamped Index name that should be used for all underlying index management requests.

func (*Client) IndexReadAlias

func (c *Client) IndexReadAlias(name Index) string

IndexReadAlias returns the read alias for the given Index.

func (*Client) IndexWriteAlias

func (c *Client) IndexWriteAlias(name Index) string

IndexWriteAlias returns the write alias for the given Index.

type Config

type Config struct {
	User                string          `koanf:"user"                validate:"required"`
	Password            string          `koanf:"password"            validate:"required"`
	Hosts               []string        `koanf:"hosts"               validate:"required,unique"`
	DialTimeout         config.Duration `koanf:"dialtimeout"`
	ReadTimeout         config.Duration `koanf:"readtimeout"`
	SkipTLSVerification bool            `koanf:"skiptlsverification"`
	CAFile              string          `koanf:"cafile"              validate:"omitempty,file"`
	Settings            Settings        `koanf:"settings"`
}

type Doc added in v0.258.0

type Doc[T ~string] interface {
	GetID() T
}

type Index

type Index string

Index represents an index in OpenSearch.

func (Index) String

func (i Index) String() string

type Inspectable

type Inspectable interface {
	Inspect() opensearchapi.Inspect
}

type Settings added in v0.259.0

type Settings struct {
	Plugins struct {
		MLCommons struct {
			TrustedConnectorEndpointsRegex        []string `json:"trusted_connector_endpoints_regex" koanf:"trusted_connector_endpoints_regex"`
			TrustedConnectorPrivateEndpointsRegex []string `json:"trusted_connector_private_endpoints_regex" koanf:"trusted_connector_private_endpoints_regex"`
			Connector                             struct {
				PrivateIPEnabled bool `json:"private_ip_enabled" koanf:"private_ip_enabled"`
			} `json:"connector" koanf:"connector"`
			OnlyRunOnMLNode bool `json:"only_run_on_ml_node" koanf:"only_run_on_ml_node"`
		} `json:"ml_commons" koanf:"ml_commons"`
	} `json:"plugins" koanf:"plugins"`
}

Settings are Opensearch cluster settings.

Directories

Path Synopsis
ism

Jump to

Keyboard shortcuts

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