Documentation
¶
Index ¶
- Variables
- func ExtractSource[T any](doc json.RawMessage) (T, error)
- func GenerateAPIError(msg string, resp Inspectable) *models.APIError
- func HandleError(msg string, resp Inspectable, err error) *models.APIError
- func NewRequestHeaders(ctx context.Context) http.Header
- type Client
- type Config
- type Doc
- type Index
- type Inspectable
- type Settings
Constants ¶
This section is empty.
Variables ¶
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") )
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 ¶
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
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) IndexCanonicalName ¶
IndexCanonicalName returns a unique, time-stamped Index name that should be used for all underlying index management requests.
func (*Client) IndexReadAlias ¶
IndexReadAlias returns the read 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 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.