es

package
v0.0.0-...-a8c716a Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ESDateFormat   = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" // 创建index定义date类型时的格式
	TimeDateFormat = "2006-01-02 15:04:05"                           // 存储到es date类型时需要的格式
)

Functions

This section is empty.

Types

type Aggregation

type Aggregation struct {
	Name string
	Agg  elastic.Aggregation
}

nolint

type AsyncBatchCreateOptionFunc

type AsyncBatchCreateOptionFunc func(abc *asyncBatchCreateOption)

func WithBulkActions

func WithBulkActions(n int) AsyncBatchCreateOptionFunc

func WithStats

func WithStats(n bool) AsyncBatchCreateOptionFunc

func WithWorkerNum

func WithWorkerNum(n int) AsyncBatchCreateOptionFunc

type AsyncHandle

type AsyncHandle elastic.BulkAfterFunc

type Config

type Config struct {
	User  string   // 用户名
	Pwd   string   // 密码
	Addrs []string // 地址串
}

type DatContainer

type DatContainer struct {
	Data  interface{} `json:"data"`
	ID    string      `json:"id"`
	Index string      `json:"index"`
	Opt   Option      `json:"option"`
}

type Elastic

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

Elastic 封装的ES操作器.

func NewElastic

func NewElastic(ctx context.Context, conf *Config, ops ...OptionFunc) (*Elastic, error)

func (*Elastic) AggregationBySourceQuery

func (e *Elastic) AggregationBySourceQuery(ctx context.Context, index string, query elastic.Query, agg *Aggregation,
	ops ...SearchOption) (*elastic.SearchResult, error)

AggregationBySourceQuery 通过构建的原始查询语句进行聚合统计查询

func (*Elastic) AsyncBatchCreateDoc

func (e *Elastic) AsyncBatchCreateDoc(ctx context.Context, datas <-chan *DatContainer,
	handle AsyncHandle, ops ...AsyncBatchCreateOptionFunc) error

SyncBatchCreateDoc 异步的批量写入

func (*Elastic) CreateDoc

func (e *Elastic) CreateDoc(ctx context.Context, index string, data interface{}) error

CreateDoc 创建一个文档

func (*Elastic) CreateDocByID

func (e *Elastic) CreateDocByID(ctx context.Context, index, id string, data interface{}) error

CreateDocByID 创建一个文档

func (*Elastic) CreateIndex

func (e *Elastic) CreateIndex(ctx context.Context, name string, mapping interface{}, ops ...IndexOption) error

CreateIndex 创建索引

func (*Elastic) DeleteDocByID

func (e *Elastic) DeleteDocByID(ctx context.Context, index, id string) error

DeleteDocByID 根据索引ID删除文档

func (*Elastic) DeleteDocByQuery

func (e *Elastic) DeleteDocByQuery(ctx context.Context, index string, query elastic.Query) (int64, error)

DeleteDocByQuery 根据条件删除文档

func (*Elastic) DeleteIndex

func (e *Elastic) DeleteIndex(ctx context.Context, index string) error

DeleteIndex 删除索引

func (*Elastic) DocIsExist

func (e *Elastic) DocIsExist(ctx context.Context, index, id string) (isExist bool)

DocIsExist 检查文档是否存在 https://www.elastic.co/guide/cn/elasticsearch/guide/current/doc-exists.html

func (*Elastic) DocIsExistByQuery

func (e *Elastic) DocIsExistByQuery(ctx context.Context, index string, query elastic.Query) (isExist bool)

DocIsExistByQuery 检查文档是否存在

func (*Elastic) DocPartialUpdatesByID

func (e *Elastic) DocPartialUpdatesByID(ctx context.Context, index, docID string, data map[string]any) error

DocUpdateByID 根据docID实现局部更新

func (*Elastic) GetDocByID

func (e *Elastic) GetDocByID(ctx context.Context, index, id string, dist interface{}) error

GetDocByID 通过ID获取doc

func (*Elastic) GetMapping

func (e *Elastic) GetMapping(ctx context.Context, name string) (map[string]interface{}, error)

GetMapping 通过索引名称获取 mapping

func (*Elastic) IsExistsIndex

func (e *Elastic) IsExistsIndex(ctx context.Context, index string) bool

func (*Elastic) QueryCountByTime

func (e *Elastic) QueryCountByTime(ctx context.Context, index string, query elastic.Query) (int64, error)

func (*Elastic) QueryDocByOneQuery

func (e *Elastic) QueryDocByOneQuery(ctx context.Context, index string, query elastic.Query) ([]byte, error)

func (*Elastic) QueryDoubleAggByTime

func (e *Elastic) QueryDoubleAggByTime(ctx context.Context, index, field, ntFiled string,
	query elastic.Query) (map[string]map[string]int64, error)

DoubleAgg

func (*Elastic) QueryMapsByTime

func (e *Elastic) QueryMapsByTime(ctx context.Context, index, filed string, query elastic.Query) (map[string]int64, error)

AggregateFieldCount

func (*Elastic) QueryTopXByScroll

func (e *Elastic) QueryTopXByScroll(ctx context.Context, index string, query elastic.Query, x int) (chanr chan []byte, err error)

func (*Elastic) ReIndex

func (e *Elastic) ReIndex(ctx context.Context, source, target string) error

ReIndex 数据迁移, source : 原始 index target : 目标 index

func (*Elastic) SearchDocByQuery

func (e *Elastic) SearchDocByQuery(ctx context.Context, index string,
	query elastic.Query, tar interface{}, ops ...SearchOption) (string, error)

SearchDocByQuery 匹配查询一个doc tar: 结果对象指针 return: docID, err

func (*Elastic) SearchDocByTermQuery

func (e *Elastic) SearchDocByTermQuery(ctx context.Context, index string,
	tqs map[string]interface{}, tar interface{}, ops ...SearchOption) (string, error)

SearchDocByTermQuery 匹配查询一个doc tar: 结果对象指针 return: docID, err

func (*Elastic) SearchDocsBySourceQuery

func (e *Elastic) SearchDocsBySourceQuery(ctx context.Context, index string, query elastic.Query,
	ops ...SearchOption) (*elastic.SearchResult, error)

SearchDocsBySourceQuery 通过构建的原始查询语句进行查询

func (*Elastic) SearchDocsByTermQuery

func (e *Elastic) SearchDocsByTermQuery(ctx context.Context, index string,
	tqs map[string]interface{}, ops ...SearchOption) ([][]byte, error)

SearchDatasByQuery

func (*Elastic) SyncBatchCreateDoc

func (e *Elastic) SyncBatchCreateDoc(ctx context.Context, index string, datas []interface{}) error

SyncBatchCreateDoc 同步的批量写入 TODO: 后期需要限制一下批量数量

func (*Elastic) UpdateCoverDocByID

func (e *Elastic) UpdateCoverDocByID(ctx context.Context, index, id string, doc interface{}) error

UpdateCoverDocByID 覆盖更新doc

func (*Elastic) UpdateMapping

func (e *Elastic) UpdateMapping(ctx context.Context, name string, mapping map[string]interface{}) error

UpdateMapping 修改 Mapping

func (*Elastic) UpdateMappingByReIndex

func (e *Elastic) UpdateMappingByReIndex(ctx context.Context, name string, mapping interface{}) error

UpdateMappingByReIndex 通过 ReIndex 方式修改 mapping

type IndexOption

type IndexOption func(*indexStruct)

func WithAliases

func WithAliases(as []string) IndexOption

func WithAnalysis

func WithAnalysis(analysis map[string]interface{}) IndexOption

WithAnalysis 配置解析器

func WithLimitFields

func WithLimitFields(l int) IndexOption

WithLimitFields 配置索引字段最大条数

func WithMaxWindow

func WithMaxWindow(m int) IndexOption

WithMaxWindow 配置最大结果条数

func WithReplicas

func WithReplicas(r int) IndexOption

WithReplicas 配置副本数

func WithShards

func WithShards(s int) IndexOption

WithShards 配置分片

type Option

type Option int
const (
	Default Option = iota // 0. 空处理
	Insert                // 1. 新增
	Update                // 2. 更新
	Delete                // 3. 删除
)

type OptionFunc

type OptionFunc func(*Elastic)

func WithLogger

func WithLogger(lg logger.Logger) OptionFunc

type SearchOption

type SearchOption func(*elastic.SearchService)

func SearchWithLimit

func SearchWithLimit(limit int) SearchOption

SearchWithLimit 查询指定条数 MARK: 不要和`SearchWithPage`同时使用

func SearchWithPage

func SearchWithPage(page, size int) SearchOption

SearchWithPage page: 从第0页开始

func SearchWithSort

func SearchWithSort(field string, ascending bool) SearchOption

Jump to

Keyboard shortcuts

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