opensearch

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

README

Configuration

data:
  opensearch:
    addresses:
      - "http://localhost:9200"
    username: "admin"
    password: "admin"
    tls:
      enable: false
      config:
        type: #this value can either be "file" or "vault"
        min-version: #optional, if omitted, the default value is "tls10"

        # vault type related properties begin
        path:
        role:
        cn:
        ip-sans:
        alt-names:
        ttl:
        min-renew-interval:
        # vault type related properties end

        # file type related properties begin
        ca-cert-file:
        cert-file:
        key-file:
        key-pass:
        # file type related properties end

Testing

When using the opensearch package, developers are encouraged to use WithOpenSearchPlayback, which wraps httpvcr to test. Examples can be found in the go-lanai/pkg/test/opensearchtest/.

When tests are run WithOpenSearchPlayback, it will generate a yml file in a ./testdata directory that stores the outgoing requests and corresponding responses and mock them when the test suite is not in RecordMode.

BodyModifiers can be used to change expected requests/responses - like time.

The vcr will also preappend(with test_) any index names that are passed as options to the Repo[T] interface.

Check out the example test below.

package main

import (
    "testing"
    "github.com/cisco-open/go-lanai/test/dbtest"
    "github.com/cisco-open/go-lanai/test/suitetest"
    "github.com/cisco-open/go-lanai/test"
    "github.com/cisco-open/go-lanai/test/apptest"
    "go.uber.org/fx"
    "github.com/onsi/gomega"
    "github.com/opensearch-project/opensearch-go/opensearchapi"
    "github.com/cisco-open/go-lanai/pkg/opensearch"
    "context"
)

// To enable record mode, uncomment the block of code below
//func TestMain(m *testing.M) {
//	suitetest.RunTests(m,
//		dbtest.EnableDBRecordMode(),
//	)
//}

type FakeService struct {
	Repo opensearch.Repo[someModel]
}

type fakeServiceDI struct {
	fx.In
	Client opensearch.OpenClient
}

func NewFakeService(di fakeServiceDI) FakeService {
	return FakeService{
		Repo: opensearch.NewRepo(&someModel{}, di.Client),
	}
}

type opensearchDI struct {
	fx.In
	FakeService   FakeService
	Properties    *opensearch.Properties
	BodyModifiers *MatcherBodyModifiers
}

func TestScopeController(t *testing.T) {
	di := &opensearchDI{}
	test.RunTest(context.Background(), t,
		apptest.Bootstrap(),
		WithOpenSearchPlayback(
			SetRecordMode(ModeCommandline),
			SetRecordDelay(time.Millisecond*1500), // Used to ensure enough time for db changes to take place
		),
		apptest.WithTimeout(time.Minute),
		apptest.WithModules(opensearch.Module),
		apptest.WithFxOptions(
			fx.Provide(NewFakeService),
		),
		apptest.WithProperties(
			"data.logging.level: debug",
			"log.levels.data: debug",
		),
		apptest.WithDI(di),
		//test.SubTestSetup(SetupOpenSearchTest(di)),
		test.GomegaSubTest(SubTestTemplateAndAlias(di), "SubTestNewBulkIndexer"),
	)
}


func SubTestTemplateAndAlias(di *opensearchDI) test.GomegaSubTestFunc {
	return func(ctx context.Context, t *testing.T, g *gomega.WithT) {
		fakeNewIndexName := "generic_events_1"
		fakeIndexAlias := "generic_event"
		fakeTemplateName := "test_template"
		indexTemplate := map[string]interface{}{
			"index_patterns": []string{"*generic_events*"}, // Pattern needs to accomodate "test_" append
			"template": map[string]interface{}{
				"settings": map[string]interface{}{
					"number_of_shards":   4,
					"number_of_replicas": 4,
				},
			},
			"version": 1,
			"_meta": map[string]interface{}{
				"description": "some description",
			},
		}
		indexMapping := map[string]interface{}{
			"mappings": map[string]interface{}{
				"properties": map[string]interface{}{
					"SubType": map[string]interface{}{
						"type": "text",
					},
				},
			},
		}
		

		// Create a Template
		err := di.FakeService.Repo.IndicesPutIndexTemplate(ctx, fakeTemplateName, indexTemplate)
		if err != nil {
			t.Fatalf("unable to create index template")
		}

		// Create an Index with template pattern
		err = di.FakeService.Repo.IndicesCreate(ctx, fakeNewIndexName, indexMapping)
		if err != nil {
			t.Fatalf("unable to create index")
		}

		// Create an Alias for the template
		err = di.FakeService.Repo.IndicesPutAlias(ctx, []string{fakeNewIndexName}, fakeIndexAlias)
		if err != nil {
			t.Fatalf("unable to create alias ")
		}

		// Get the new index using the Alias and check the obj
		resp, err := di.FakeService.Repo.IndicesGet(ctx, fakeIndexAlias)
		if err != nil {
			t.Fatalf("unable to get indices information using alias ")
		}

		// This test proves that the index template works against the newly created indices
		g.Expect(resp.Settings.Index.NumberOfShards).To(gomega.Equal("4"))

		// Test Cleanup
		// Delete Alias
		err = di.FakeService.Repo.IndicesDeleteAlias(ctx, []string{fakeNewIndexName}, []string{fakeIndexAlias})
		if err != nil {
			t.Fatalf("unable to delete indices alias ")
		}
		// Delete Index Template
		err = di.FakeService.Repo.IndicesDeleteIndexTemplate(ctx, fakeTemplateName)
		if err != nil {
			t.Fatalf("unable to delete index template ")
		}
		// Delete index
		err = di.FakeService.Repo.IndicesDelete(ctx, []string{fakeNewIndexName})
		if err != nil {
			t.Fatalf("unable to delete index ")
		}
	}
}

Documentation

Index

Constants

View Source
const (
	// FxGroup defines the FX group for the OpenSearch
	FxGroup = "opensearch"
)
View Source
const (
	PropertiesPrefix = "data.opensearch"
)
View Source
const (
	UnknownCommand string = "unknown"
)

Variables

View Source
var BulkIndexer = bulkCfgExt{}
View Source
var CmdToString = map[CommandType]string{
	CmdSearch:                     "search",
	CmdSearchTemplate:             "search template",
	CmdIndex:                      "index",
	CmdIndicesCreate:              "indices create",
	CmdIndicesGet:                 "indices get",
	CmdIndicesDelete:              "indices delete",
	CmdIndicesPutAlias:            "indices put alias",
	CmdIndicesDeleteAlias:         "indices delete alias",
	CmdIndicesPutIndexTemplate:    "indices put index template",
	CmdIndicesDeleteIndexTemplate: "indices delete index template",
	CmdPing:                       "ping",
	CmdBulk:                       "bulk",
}
View Source
var (
	ErrCreatingNewClient = errors.New("unable to create opensearch client")
)
View Source
var (
	ErrIndexNotFound = errors.New("index not found")
)
View Source
var Index = indexExt{}
View Source
var IndicesCreate = indicesCreateExt{}
View Source
var IndicesDelete = indicesDeleteExt{}
View Source
var IndicesDeleteAlias = indicesDeleteAlias{}
View Source
var IndicesDeleteIndexTemplate = indicesDeleteIndexTemplate{}
View Source
var IndicesGet = indicesGetExt{}
View Source
var IndicesPutAlias = indicesPutAlias{}
View Source
var IndicesPutIndexTemplate = indicesPutIndexTemplate{}
View Source
var Module = &bootstrap.Module{
	Precedence: bootstrap.OpenSearchPrecedence,
	Options: []fx.Option{
		appconfig.FxEmbeddedDefaults(defaultConfigFS),
		fx.Provide(BindOpenSearchProperties),
		fx.Provide(NewConfig),
		fx.Provide(NewClient),
		fx.Provide(tracingProvider()),
		fx.Invoke(registerHealth),
	},
}
View Source
var Ping = pingExt{}
View Source
var Search = searchExt{}
View Source
var SearchTemplate = searchTemplateExt{}

Functions

func NewConfig

func NewConfig(ctx *bootstrap.ApplicationContext, di configDI) (opensearch.Config, error)

func UnmarshalResponse

func UnmarshalResponse[T any](resp *opensearchapi.Response) (*T, error)

UnmarshalResponse will take the response, read the body out of it and then place the bytes that were read back into the body so it can be used again after this call

func Use

func Use()

func WithClient

func WithClient(c *opensearch.Client) func(*opensearchutil.BulkIndexerConfig)

Types

type AfterContext

type AfterContext struct {
	Options interface{}
	Resp    *opensearchapi.Response
	Err     *error
	// contains filtered or unexported fields
}

AfterContext is the context given to a AfterHook

Options will be in the form *[]func(request *Request){} example:

options := make([]func(request *opensearchapi.SearchRequest), 0)
AfterContext{Options: &options}

Resp and Err can be modified before they are returned out of Request of OpenClientImpl example being OpenClientImpl.Search

func (*AfterContext) CommandType

func (c *AfterContext) CommandType() CommandType

type AfterHook

type AfterHook interface {
	After(ctx context.Context, after AfterContext) context.Context
}

type AfterHookBase

type AfterHookBase struct {
	Identifier string
	F          func(ctx context.Context, after AfterContext) context.Context
}

AfterHookBase provides a way to create an AfterHook, similar to AfterHookFunc. but in a way that implements the Identifier interface so that it can be removed using the RemoveAfterHook function

func (AfterHookBase) After

func (AfterHookBase) ID

func (s AfterHookBase) ID() string

type AfterHookFunc

type AfterHookFunc func(ctx context.Context, after AfterContext) context.Context

AfterHookFunc provides a way to easily create a AfterHook - however hooks created in this manner are not able to be deleted from the hook slice

func (AfterHookFunc) After

type BeforeContext

type BeforeContext struct {
	Options interface{}
	// contains filtered or unexported fields
}

BeforeContext is the context given to a BeforeHook

Options will be in the form *[]func(request *Request){}, example:

options := make([]func(request *opensearchapi.SearchRequest), 0)
BeforeContext{Options: &options}

func (*BeforeContext) CommandType

func (c *BeforeContext) CommandType() CommandType

type BeforeHook

type BeforeHook interface {
	Before(ctx context.Context, before BeforeContext) context.Context
}

type BeforeHookBase

type BeforeHookBase struct {
	Identifier string
	F          func(ctx context.Context, after BeforeContext) context.Context
}

BeforeHookBase provides a way to create an BeforeHook, similar to BeforeHookFunc, but in a way that implements the Identifier interface so that it can be removed using the RemoveBeforeHook function

func (BeforeHookBase) Before

func (BeforeHookBase) ID

func (s BeforeHookBase) ID() string

type BeforeHookFunc

type BeforeHookFunc func(ctx context.Context, before BeforeContext) context.Context

func (BeforeHookFunc) Before

type BulkAction

type BulkAction string

BulkAction is intended to be used as an enum type for bulk actions

const (
	BulkActionIndex  BulkAction = "index"  // Will add in a document and will override any duplicate (based on ID)
	BulkActionCreate BulkAction = "create" // Will add a document if it doesn't exist or return an error
	BulkActionUpdate BulkAction = "update" // Will update an existing document if it exists or return an error
	BulkActionDelete BulkAction = "delete" // Will delete a document if it exists or return a `not_found`
)

type CommandType

type CommandType int

CommandType lets the hooks know what command is being run

const (
	CmdSearch CommandType = iota
	CmdSearchTemplate
	CmdIndex
	CmdIndicesCreate
	CmdIndicesGet
	CmdIndicesDelete
	CmdIndicesPutAlias
	CmdIndicesDeleteAlias
	CmdIndicesPutIndexTemplate
	CmdIndicesDeleteIndexTemplate
	CmdPing
	CmdBulk
)

func (CommandType) String

func (c CommandType) String() string

String will return the command in string format. If the command is not found the UnknownCommand string will be returned

type HealthIndicator

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

func NewHealthIndicator

func NewHealthIndicator(client OpenClient) *HealthIndicator

func (*HealthIndicator) Health

func (i *HealthIndicator) Health(c context.Context, options health.Options) health.Health

func (*HealthIndicator) Name

func (i *HealthIndicator) Name() string

type Identifier

type Identifier interface {
	ID() string
}

type IndicesDetail

type IndicesDetail struct {
	Aliases  map[string]interface{} `json:"aliases"`
	Mappings map[string]interface{} `json:"mappings"`
	Settings struct {
		Index struct {
			CreationDate     string `json:"creation_date"`
			NumberOfShards   string `json:"number_of_shards"`
			NumberOfReplicas string `json:"number_of_replicas"`
			Uuid             string `json:"uuid"`
			Version          struct {
				Created string `json:"created"`
			} `json:"version"`
			ProvidedName string `json:"provided_name"`
		} `json:"index"`
	}
}

IndicesDetail response follows opensearch spec [format] https://opensearch.org/docs/latest/opensearch/rest-api/index-apis/get-index/#response-body-fields

type OpenClient

type OpenClient interface {
	Search(ctx context.Context, o ...Option[opensearchapi.SearchRequest]) (*opensearchapi.Response, error)
	SearchTemplate(ctx context.Context, body io.Reader, o ...Option[opensearchapi.SearchTemplateRequest]) (*opensearchapi.Response, error)
	Index(ctx context.Context, index string, body io.Reader, o ...Option[opensearchapi.IndexRequest]) (*opensearchapi.Response, error)
	BulkIndexer(ctx context.Context, action BulkAction, bulkItems [][]byte, o ...Option[opensearchutil.BulkIndexerConfig]) (opensearchutil.BulkIndexer, error)
	IndicesCreate(ctx context.Context, index string, o ...Option[opensearchapi.IndicesCreateRequest]) (*opensearchapi.Response, error)
	IndicesGet(ctx context.Context, index string, o ...Option[opensearchapi.IndicesGetRequest]) (*opensearchapi.Response, error)
	IndicesDelete(ctx context.Context, index []string, o ...Option[opensearchapi.IndicesDeleteRequest]) (*opensearchapi.Response, error)
	IndicesPutAlias(ctx context.Context, index []string, name string, o ...Option[opensearchapi.IndicesPutAliasRequest]) (*opensearchapi.Response, error)
	IndicesDeleteAlias(ctx context.Context, index []string, name []string, o ...Option[opensearchapi.IndicesDeleteAliasRequest]) (*opensearchapi.Response, error)
	IndicesPutIndexTemplate(ctx context.Context, name string, body io.Reader, o ...Option[opensearchapi.IndicesPutIndexTemplateRequest]) (*opensearchapi.Response, error)
	IndicesDeleteIndexTemplate(ctx context.Context, name string, o ...Option[opensearchapi.IndicesDeleteIndexTemplateRequest]) (*opensearchapi.Response, error)
	Ping(ctx context.Context, o ...Option[opensearchapi.PingRequest]) (*opensearchapi.Response, error)
	AddBeforeHook(hook BeforeHook)
	AddAfterHook(hook AfterHook)
	RemoveBeforeHook(hook BeforeHook)
	RemoveAfterHook(hook AfterHook)
}

func NewClient

func NewClient(di newClientDI) (OpenClient, error)

type OpenClientImpl

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

func (*OpenClientImpl) AddAfterHook

func (c *OpenClientImpl) AddAfterHook(hook AfterHook)

func (*OpenClientImpl) AddBeforeHook

func (c *OpenClientImpl) AddBeforeHook(hook BeforeHook)

func (*OpenClientImpl) BulkIndexer

func (*OpenClientImpl) Index

func (*OpenClientImpl) IndicesCreate

func (*OpenClientImpl) IndicesDelete

func (*OpenClientImpl) IndicesDeleteAlias

func (c *OpenClientImpl) IndicesDeleteAlias(ctx context.Context, index []string, name []string, o ...Option[opensearchapi.IndicesDeleteAliasRequest]) (*opensearchapi.Response, error)

func (*OpenClientImpl) IndicesDeleteIndexTemplate

func (*OpenClientImpl) IndicesGet

func (*OpenClientImpl) IndicesPutAlias

func (*OpenClientImpl) IndicesPutIndexTemplate

func (*OpenClientImpl) Ping

func (*OpenClientImpl) RemoveAfterHook

func (c *OpenClientImpl) RemoveAfterHook(hook AfterHook)

RemoveAfterHook will remove the given AfterHook. To ensure your hook is removable, the hook should implement the Identifier interface. If not, your hooks should be distinct in the eyes of reflect.DeepEqual, otherwise the hook will not be removed.

func (*OpenClientImpl) RemoveBeforeHook

func (c *OpenClientImpl) RemoveBeforeHook(hook BeforeHook)

RemoveBeforeHook will remove the given BeforeHook. To ensure your hook is removable, the hook should implement the Identifier interface. If not, your hooks should be distinct in the eyes of reflect.DeepEqual, otherwise the hook will not be removed.

func (*OpenClientImpl) Search

func (*OpenClientImpl) SearchTemplate

type Option

type Option[T Request] func(request *T)

type Properties

type Properties struct {
	Addresses []string `json:"addresses"`
	Username  string   `json:"username"`
	Password  string   `json:"password"`
	TLS       TLS      `json:"tls"`
}

func BindOpenSearchProperties

func BindOpenSearchProperties(ctx *bootstrap.ApplicationContext) *Properties

func NewOpenSearchProperties

func NewOpenSearchProperties() *Properties

type Repo

type Repo[T any] interface {
	// Search will search the cluster for data.
	//
	// The data will be unmarshalled and returned to the dest argument.
	// The body argument should follow the Search request body [Format].
	//
	// [Format]: https://opensearch.org/docs/latest/opensearch/rest-api/search/#request-body
	Search(ctx context.Context, dest *[]T, body interface{}, o ...Option[opensearchapi.SearchRequest]) (int, error)

	// SearchTemplate allows to use the Mustache language to pre-render a search definition
	//
	// The data will be unmarshalled and returned to the dest argument.
	// The body argument should follow the Search request body [Format].
	//
	// [Format]: https://opensearch.org/docs/latest/opensearch/rest-api/search/#request-body
	SearchTemplate(ctx context.Context, dest *[]T, body interface{}, o ...Option[opensearchapi.SearchTemplateRequest]) (int, error)

	// Index will create a new Document in the index that is defined.
	//
	// The index argument defines the index name that the document should be stored in.
	Index(ctx context.Context, index string, document T, o ...Option[opensearchapi.IndexRequest]) error

	// BulkIndexer will process bulk requests of a single action type.
	//
	// The index argument defines the index name that the bulk action will target.
	// The action argument must be one of: ("index", "create", "delete", "update").
	// The bulkItems argument is the array of struct items to be actioned.
	//
	// [Ref]: https://pkg.go.dev/github.com/opensearch-project/opensearch-go/opensearchutil#BulkIndexerItem
	BulkIndexer(ctx context.Context, action BulkAction, bulkItems *[]T, o ...Option[opensearchutil.BulkIndexerConfig]) (opensearchutil.BulkIndexerStats, error)

	// IndicesCreate will create a new index in the cluster.
	//
	// The index argument defines the index name to be created.
	// The mapping argument should follow the Index Create request body [Format].
	//
	// [Format]: https://opensearch.org/docs/latest/opensearch/rest-api/index-apis/create-index/#request-body
	IndicesCreate(ctx context.Context, index string, mapping interface{}, o ...Option[opensearchapi.IndicesCreateRequest]) error

	// IndicesGet will return information about an index
	//
	// The index argument defines the index name we want to get
	IndicesGet(ctx context.Context, index string, o ...Option[opensearchapi.IndicesGetRequest]) (*IndicesDetail, error)

	// IndicesDelete will delete an index from the cluster.
	//
	// The index argument defines the index name to be deleted.
	//
	// [Format]: https://opensearch.org/docs/latest/opensearch/rest-api/index-apis/delete-index/
	IndicesDelete(ctx context.Context, index []string, o ...Option[opensearchapi.IndicesDeleteRequest]) error

	// IndicesPutAlias will create or update an alias
	//
	// The index argument defines the index that the alias should point to
	// The name argument defines the name of the new alias
	//
	// [Format]: https://opensearch.org/docs/latest/opensearch/rest-api/alias/#request-body
	IndicesPutAlias(ctx context.Context, index []string, name string, o ...Option[opensearchapi.IndicesPutAliasRequest]) error

	// IndicesDeleteAlias deletes an alias
	//
	// The index argument defines the index that the alias points to
	// The name argument defines the name of the alias we would like to delete
	//
	// [Format]: https://opensearch.org/docs/latest/opensearch/rest-api/alias/#request-body
	IndicesDeleteAlias(ctx context.Context, index []string, name []string, o ...Option[opensearchapi.IndicesDeleteAliasRequest]) error

	// IndicesPutIndexTemplate will create or update an alias
	//
	// The name argument defines the name of the template
	// The body argument defines the specified template options to apply (refer to [Format])
	//
	// [Format]: https://opensearch.org/docs/latest/opensearch/index-templates/#index-template-options
	IndicesPutIndexTemplate(ctx context.Context, name string, body interface{}, o ...Option[opensearchapi.IndicesPutIndexTemplateRequest]) error

	// IndicesDeleteIndexTemplate deletes an index template
	//
	// The name argument defines the name of the template to delete
	IndicesDeleteIndexTemplate(ctx context.Context, name string, o ...Option[opensearchapi.IndicesDeleteIndexTemplateRequest]) error

	// Ping will ping the OpenSearch cluster. If no error is returned, then the ping was successful
	Ping(ctx context.Context, o ...Option[opensearchapi.PingRequest]) error

	AddBeforeHook(hook BeforeHook)
	AddAfterHook(hook AfterHook)
	RemoveBeforeHook(hook BeforeHook)
	RemoveAfterHook(hook AfterHook)
}

func NewRepo

func NewRepo[T any](model *T, client OpenClient) Repo[T]

NewRepo will return a OpenSearch repository for any model type T

type RepoImpl

type RepoImpl[T any] struct {
	// contains filtered or unexported fields
}

func (*RepoImpl[T]) AddAfterHook

func (c *RepoImpl[T]) AddAfterHook(hook AfterHook)

func (*RepoImpl[T]) AddBeforeHook

func (c *RepoImpl[T]) AddBeforeHook(hook BeforeHook)

func (*RepoImpl[T]) BulkIndexer

func (c *RepoImpl[T]) BulkIndexer(ctx context.Context, action BulkAction, bulkItems *[]T, o ...Option[opensearchutil.BulkIndexerConfig]) (opensearchutil.BulkIndexerStats, error)

func (*RepoImpl[T]) Index

func (c *RepoImpl[T]) Index(ctx context.Context, index string, document T, o ...Option[opensearchapi.IndexRequest]) error

func (*RepoImpl[T]) IndicesCreate

func (c *RepoImpl[T]) IndicesCreate(
	ctx context.Context,
	index string,
	mapping interface{},
	o ...Option[opensearchapi.IndicesCreateRequest],
) error

func (*RepoImpl[T]) IndicesDelete

func (c *RepoImpl[T]) IndicesDelete(ctx context.Context, index []string, o ...Option[opensearchapi.IndicesDeleteRequest]) error

func (*RepoImpl[T]) IndicesDeleteAlias

func (c *RepoImpl[T]) IndicesDeleteAlias(ctx context.Context, index []string, name []string, o ...Option[opensearchapi.IndicesDeleteAliasRequest]) error

func (*RepoImpl[T]) IndicesDeleteIndexTemplate

func (c *RepoImpl[T]) IndicesDeleteIndexTemplate(ctx context.Context, name string, o ...Option[opensearchapi.IndicesDeleteIndexTemplateRequest]) error

func (*RepoImpl[T]) IndicesGet

func (c *RepoImpl[T]) IndicesGet(ctx context.Context, index string, o ...Option[opensearchapi.IndicesGetRequest]) (*IndicesDetail, error)

func (*RepoImpl[T]) IndicesPutAlias

func (c *RepoImpl[T]) IndicesPutAlias(ctx context.Context,
	index []string,
	name string,
	o ...Option[opensearchapi.IndicesPutAliasRequest],
) error

func (*RepoImpl[T]) IndicesPutIndexTemplate

func (c *RepoImpl[T]) IndicesPutIndexTemplate(ctx context.Context, name string, body interface{}, o ...Option[opensearchapi.IndicesPutIndexTemplateRequest]) error

func (*RepoImpl[T]) Ping

func (c *RepoImpl[T]) Ping(
	ctx context.Context,
	o ...Option[opensearchapi.PingRequest],
) error

func (*RepoImpl[T]) RemoveAfterHook

func (c *RepoImpl[T]) RemoveAfterHook(hook AfterHook)

func (*RepoImpl[T]) RemoveBeforeHook

func (c *RepoImpl[T]) RemoveBeforeHook(hook BeforeHook)

func (*RepoImpl[T]) Search

func (c *RepoImpl[T]) Search(ctx context.Context, dest *[]T, body interface{}, o ...Option[opensearchapi.SearchRequest]) (hits int, err error)

func (*RepoImpl[T]) SearchTemplate

func (c *RepoImpl[T]) SearchTemplate(ctx context.Context, dest *[]T, body interface{}, o ...Option[opensearchapi.SearchTemplateRequest]) (hits int, err error)

type SearchResponse

type SearchResponse[T any] struct {
	Took     int  `json:"took"`
	TimedOut bool `json:"timed_out"`
	Shards   struct {
		Total      int `json:"total"`
		Successful int `json:"successful"`
		Skipped    int `json:"skipped"`
		Failed     int `json:"failed"`
	} `json:"_shards"`
	Hits struct {
		MaxScore float64 `json:"max_score"`
		Total    struct {
			Value int `json:"value"`
		} `json:"total"`
		Hits []struct {
			Index  string  `json:"_index"`
			ID     string  `json:"_id"`
			Score  float64 `json:"_score"`
			Source T       `json:"_source"`
		} `json:"hits"`
	} `json:"hits"`
}

SearchResponse modeled after https://opensearch.org/docs/latest/opensearch/rest-api/search/#response-body

type TLS

type TLS struct {
	Enable bool                   `json:"enable"`
	Certs  certs.SourceProperties `json:"certs"`
}

type Tracer added in v0.14.0

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

Tracer will provide some opensearch.HookContainer to provide tracing

func TracerHook added in v0.14.0

func TracerHook(tracer opentracing.Tracer) *Tracer

func (*Tracer) After added in v0.14.0

func (t *Tracer) After(ctx context.Context, afterContext AfterContext) context.Context

func (*Tracer) Before added in v0.14.0

func (t *Tracer) Before(ctx context.Context, before BeforeContext) context.Context

Jump to

Keyboard shortcuts

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