Documentation ¶
Index ¶
- Constants
- Variables
- func CloseAll()
- func InitClient(clientName string, urls []string, username string, password string) error
- func InitClientWithOptions(clientName string, urls []string, username string, password string, ...) error
- func InitSimpleClient(urls []string, username, password string) error
- type Bulk
- type BulkCreateDoc
- type BulkDoc
- type BulkUpdateDoc
- type BulkUpsertDoc
- type Client
- func (c *Client) AddIndexCache(indexName ...string)
- func (c *Client) BulkCreate(indexName, id, routing string, doc interface{})
- func (c *Client) BulkCreateDocs(ctx context.Context, indexName string, docs []*BulkCreateDoc) (*elastic.BulkResponse, error)
- func (c *Client) BulkCreateWithVersion(ctx context.Context, indexName, id, routing string, version int64, ...)
- func (c *Client) BulkDelete(indexName, id, routing string)
- func (c *Client) BulkDeleteWithVersion(indexName, id, routing string, version int64)
- func (c *Client) BulkReplace(indexName, id, routing string, doc interface{})
- func (c *Client) BulkReplaceDocs(ctx context.Context, indexName string, docs []*BulkCreateDoc) (*elastic.BulkResponse, error)
- func (c *Client) BulkUpdate(indexName, id, routing string, update map[string]interface{})
- func (c *Client) BulkUpdateDocs(ctx context.Context, index string, updates []*BulkUpdateDoc) (*elastic.BulkResponse, error)
- func (c *Client) BulkUpsert(indexName, id, routing string, update map[string]interface{}, doc interface{})
- func (c *Client) BulkUpsertDocs(ctx context.Context, index string, docs []*BulkUpsertDoc) (*elastic.BulkResponse, error)
- func (c *Client) Close() error
- func (c *Client) Create(ctx context.Context, indexName, id, routing string, doc interface{}) error
- func (c *Client) CreateIndex(ctx context.Context, indexName, bodyJson string, forceCheck bool) error
- func (c *Client) Delete(ctx context.Context, indexName, id, routing string) error
- func (c *Client) DeleteByQuery(ctx context.Context, indexName, id, routing string, query elastic.Query) error
- func (c *Client) DeleteIndexCache(indexName ...string)
- func (c *Client) DeleteRefresh(ctx context.Context, indexName, id, routing string) error
- func (c *Client) DeleteWithVersion(ctx context.Context, indexName, id, routing string, version int64) error
- func (c *Client) Get(ctx context.Context, indexName, id, routing string) (*elastic.GetResult, error)
- func (c *Client) IndexExists(ctx context.Context, indexName string, forceCheck bool) (bool, error)
- func (c *Client) Mget(ctx context.Context, mgetItems []Mget) (*elastic.MgetResponse, error)
- func (c *Client) Query(ctx context.Context, indexName string, routings []string, query elastic.Query, ...) (*elastic.SearchResult, error)
- func (c *Client) ScrollQuery(ctx context.Context, index []string, typeStr string, query elastic.Query, ...)
- func (c *Client) Update(ctx context.Context, indexName, id, routing string, ...) error
- func (c *Client) UpdateByQuery(ctx context.Context, indexName string, routings []string, query elastic.Query, ...) (*elastic.BulkIndexByScrollResponse, error)
- func (c *Client) UpdateRefresh(ctx context.Context, indexName, id, routing string, ...) error
- func (c *Client) Upsert(ctx context.Context, indexName, id, routing string, ...) error
- func (c *Client) UpsertWithVersion(ctx context.Context, indexName, id, routing string, doc interface{}, ...) error
- type Mget
- type Option
- type QueryOption
- func WithEnableDSL(enableDSL bool) QueryOption
- func WithExcludeFields(excludeFields []string) QueryOption
- func WithFetchSource(fetchSource bool) QueryOption
- func WithHighlight(highlight *elastic.Highlight) QueryOption
- func WithIncludeFields(includeFields []string) QueryOption
- func WithOrders(orders []map[string]bool) QueryOption
- func WithPreference(preference string) QueryOption
- func WithProfile(profile bool) QueryOption
- func WithSlowQueryMillisecond(slowQueryLogMillisecond int64) QueryOption
Constants ¶
View Source
const ( DefaultClient = "es-default-client" DefaultReadClient = "es-default-read-client" DefaultWriteClient = "es-default-write-client" DefaultVersionType = "external" VersionTypeInternal = "internal" DefaultRefresh = "false" RefreshWaitFor = "wait_for" RefreshTrue = "true" DefaultScriptLang = "painless" )
View Source
const DefaultPreference = "_local"
View Source
const (
SimpleClient = "simple-es-client"
)
Variables ¶
View Source
var EStdLogger stdLogger
Functions ¶
func InitClient ¶
func InitClientWithOptions ¶
func InitSimpleClient ¶
Types ¶
type Bulk ¶
type Bulk struct { Name string Workers int FlushInterval time.Duration ActionSize int //每批提交的文档数 RequestSize int //每批提交的文档大小 AfterFunc elastic.BulkAfterFunc Ctx context.Context }
func DefaultBulk ¶
func DefaultBulk() *Bulk
type BulkCreateDoc ¶
type BulkCreateDoc struct { BulkDoc Doc interface{} }
type BulkUpdateDoc ¶
type BulkUpdateDoc struct { BulkDoc // contains filtered or unexported fields }
type BulkUpsertDoc ¶
type BulkUpsertDoc struct { BulkCreateDoc // contains filtered or unexported fields }
type Client ¶
type Client struct { Name string Urls []string QueryLogEnable bool Username string Bulk *Bulk Client *elastic.Client BulkProcessor *elastic.BulkProcessor DebugMode bool //本地缓存已经创建的索引,用于加速索引是否存在的判断 CachedIndices sync.Map // contains filtered or unexported fields }
func GetSimpleClient ¶
func GetSimpleClient() *Client
func (*Client) AddIndexCache ¶
func (*Client) BulkCreate ¶
批量的方式新建文档,后台提交
func (*Client) BulkCreateDocs ¶
func (c *Client) BulkCreateDocs(ctx context.Context, indexName string, docs []*BulkCreateDoc) (*elastic.BulkResponse, error)
批量的方式新建一批文档,实时提交
func (*Client) BulkCreateWithVersion ¶
func (c *Client) BulkCreateWithVersion(ctx context.Context, indexName, id, routing string, version int64, doc interface{})
业务数据修改时生成版本号,在更新ES文档数据时,根据这个版本号来避免重复和乱序处理,实现操作的幂等性 PUT twitter/_doc/1?version=2&version_type=external { "message" : "elasticsearch now has versioning support, double cool!" } 1.版本管理是完全实时的,不受搜索操作的近实时方面的影响 2.如果当前提供的版本号比实际的版本号大(或者实际文档不存在)就会成功写入,并设置为当前的版本号,否则返回失败(409状态码)
func (*Client) BulkDelete ¶
func (*Client) BulkDeleteWithVersion ¶
func (*Client) BulkReplace ¶
func (*Client) BulkReplaceDocs ¶
func (*Client) BulkUpdate ¶
func (*Client) BulkUpdateDocs ¶
func (*Client) BulkUpsert ¶
func (c *Client) BulkUpsert(indexName, id, routing string, update map[string]interface{}, doc interface{})
异步upsert
func (*Client) BulkUpsertDocs ¶
func (c *Client) BulkUpsertDocs(ctx context.Context, index string, docs []*BulkUpsertDoc) (*elastic.BulkResponse, error)
UpsertBulk 批量upsert
func (*Client) CreateIndex ¶
func (c *Client) CreateIndex(ctx context.Context, indexName, bodyJson string, forceCheck bool) error
创建索引
func (*Client) DeleteByQuery ¶
func (c *Client) DeleteByQuery(ctx context.Context, indexName, id, routing string, query elastic.Query) error
删除过程中如果命中的文档被修改会导致删除出现版本冲突,为了彻底删除文档,需要指定ProceedOnVersionConflict
func (*Client) DeleteIndexCache ¶
func (*Client) DeleteRefresh ¶
func (*Client) DeleteWithVersion ¶
func (*Client) IndexExists ¶
检查索引是否存在
func (*Client) ScrollQuery ¶
func (*Client) UpdateByQuery ¶
func (*Client) UpdateRefresh ¶
type Option ¶
type Option func(*option)
func WithQueryLogEnable ¶
func WithScheme ¶
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 *elastic.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
Click to show internal directories.
Click to hide internal directories.