v8

package
v0.0.0-...-c46b51c Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultClient      = "es-default-client"
	DefaultReadClient  = "es-default-read-client"
	DefaultWriteClient = "es-default-write-client"
)
View Source
const (
	DefaultVersionType  = "external"
	VersionTypeInternal = "internal"
	DefaultRefresh      = "false"
	RefreshWaitFor      = "wait_for"
	RefreshTrue         = "true"
	DefaultScriptLang   = "painless"
	Bulk
	OptypeCreate = "create"
	OptypeIndex  = "index"
	OptypeUpsert = "upsert"
	OptypeUpdate = "update"
	OptypeDelete = "delete"
)
View Source
const DefaultPreference = "_local"

Variables

This section is empty.

Functions

func CloseAll

func CloseAll()

func InitClient

func InitClient(clientName string, addr []string, username string, password string) error

func InitClientWithCfg

func InitClientWithCfg(clientName string, cfg elasticsearch.Config, queryLogEnable bool, bulk BulkCfg) error

Types

type BulkCfg

type BulkCfg struct {
	Workers       int
	FlushInterval time.Duration
	ActionSize    int //每批提交的文档数
	RequestSize   int //每批提交的文档大小
	AfterFunc     elastic.BulkAfterFunc
	Ctx           context.Context
}

type Client

type Client struct {
	Name           string
	Addr           []string
	QueryLogEnable bool
	Username       string

	BulkCfg       *BulkCfg
	Client        *elasticsearch.TypedClient
	BulkProcessor esutil.BulkIndexer
	DebugMode     bool
	//本地缓存已经创建的索引,用于加速索引是否存在的判断
	CachedIndices sync.Map
	// contains filtered or unexported fields
}

func GetClient

func GetClient(name string) *Client

func (*Client) BulkDelete

func (c *Client) BulkDelete(ctx context.Context, indexName, id, routing string, onFailure BulkIndexerOnFailure) error

func (*Client) BulkDeleteWithSeqNo

func (c *Client) BulkDeleteWithSeqNo(ctx context.Context, indexName, id, routing string, sqNo, primaryTerm *int64, onFailure BulkIndexerOnFailure) error

func (*Client) BulkIndex

func (c *Client) BulkIndex(ctx context.Context, indexName, id, routing, jsonDoc string, onFailure BulkIndexerOnFailure) error

批量的方式新建文档(覆盖写),后台提交

func (*Client) BulkInsert

func (c *Client) BulkInsert(ctx context.Context, indexName, id, routing, jsonDoc string, onFailure BulkIndexerOnFailure) error

批量的方式新建文档,后台提交

func (*Client) BulkInsertWithSeqNo

func (c *Client) BulkInsertWithSeqNo(ctx context.Context, id, routing, indexName, action, jsonDoc string, seqNo, primaryTerm *int64, onFailure BulkIndexerOnFailure) error

seqNo primaryTerm 用于更新文档,通过SeqNo和PrimaryTerm来保证更新操作的顺序性,避免冲突

func (*Client) BulkUpdate

func (c *Client) BulkUpdate(ctx context.Context, indexName, id, routing string, update map[string]interface{}, onFailure BulkIndexerOnFailure) error

func (*Client) Close

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

func (*Client) CreateIndex

func (c *Client) CreateIndex(ctx context.Context, indexName, bodyJson string, forceCheck bool) error

创建索引

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, indexName, id, routing string) (*delete.Response, error)

func (*Client) DeleteByQuery

func (c *Client) DeleteByQuery(ctx context.Context, indexName, routing, preference string, query *types.Query) (*deletebyquery.Response, error)

删除过程中如果命中的文档被修改会导致删除出现版本冲突,为了彻底删除文档,需要指定ProceedOnVersionConflict

func (*Client) DeleteIndex

func (c *Client) DeleteIndex(ctx context.Context, indexName string) (*delete.Response, error)

删除索引

func (*Client) DeleteWithSeqNo

func (c *Client) DeleteWithSeqNo(ctx context.Context, indexName, id, routing, seqNo, primaryTerm string) (*delete.Response, error)

func (*Client) Get

func (c *Client) Get(ctx context.Context, indexName, id, routing, preference string, excludes []string) (*get.Response, error)

func (*Client) IndexExists

func (c *Client) IndexExists(ctx context.Context, indexName string, forceCheck bool) (bool, error)

检查索引是否存在

func (*Client) Insert

func (c *Client) Insert(ctx context.Context, indexName, id, routing, action string, doc interface{}) (*index.Response, error)

新建文档

func (*Client) Mget

func (c *Client) Mget(ctx context.Context, indexName, routing string, ids, excludes []string) (*mget.Response, error)

func (*Client) Query

func (c *Client) Query(ctx context.Context, indexName string, routing string, query *types.Query, from, size int, options ...QueryOption) (*search.Response, error)

func (*Client) ScrollQuery

func (c *Client) ScrollQuery(ctx context.Context, indexName string, routing string, query *types.Query, size int, callback func(res *scroll.Response, err error), options ...QueryOption) error

func (*Client) Update

func (c *Client) Update(ctx context.Context, indexName, id, routing string, update map[string]interface{}) (*update.Response, error)

func (*Client) UpdateByQuery

func (c *Client) UpdateByQuery(ctx context.Context, indexName string, routing, preference string, query *types.Query, script types.Script) (*updatebyquery.Response, error)

func (*Client) Upsert

func (c *Client) Upsert(ctx context.Context, indexName, id, routing string, update map[string]interface{}, upsertDoc interface{}) (*update.Response, error)

type Mget

type Mget struct {
	Index   string
	ID      string
	Routing string
}

type QueryOption

type QueryOption func(queryOption *queryOption)

func WithEnableDSL

func WithEnableDSL(enableDSL bool) QueryOption

func WithExcludeFields

func WithExcludeFields(excludeFields []string) QueryOption

func WithFetchSource

func WithFetchSource(fetchSource bool) QueryOption

func WithHighlight

func WithHighlight(highlight *types.Highlight) QueryOption

func WithIncludeFields

func WithIncludeFields(includeFields []string) QueryOption

func WithOrders

func WithOrders(orders []map[string]bool) QueryOption

func WithPreference

func WithPreference(preference string) QueryOption

func WithProfile

func WithProfile(profile bool) QueryOption

func WithSlowQueryMillisecond

func WithSlowQueryMillisecond(slowQueryLogMillisecond int64) QueryOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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