Documentation ¶
Index ¶
- Variables
- type Aggregation
- type AsyncBatchCreateOptionFunc
- type AsyncHandle
- type Config
- type DatContainer
- type Elastic
- func (e *Elastic) AggregationBySourceQuery(ctx context.Context, index string, query elastic.Query, agg *Aggregation, ...) (*elastic.SearchResult, error)
- func (e *Elastic) AsyncBatchCreateDoc(ctx context.Context, datas <-chan *DatContainer, handle AsyncHandle, ...) error
- func (e *Elastic) CreateDoc(ctx context.Context, index string, data interface{}) error
- func (e *Elastic) CreateDocByID(ctx context.Context, index, id string, data interface{}) error
- func (e *Elastic) CreateIndex(ctx context.Context, name string, mapping interface{}, ops ...IndexOption) error
- func (e *Elastic) DeleteDocByID(ctx context.Context, index, id string) error
- func (e *Elastic) DeleteDocByQuery(ctx context.Context, index string, query elastic.Query) (int64, error)
- func (e *Elastic) DeleteIndex(ctx context.Context, index string) error
- func (e *Elastic) DocIsExist(ctx context.Context, index, id string) (isExist bool)
- func (e *Elastic) DocIsExistByQuery(ctx context.Context, index string, query elastic.Query) (isExist bool)
- func (e *Elastic) DocPartialUpdatesByID(ctx context.Context, index, docID string, data map[string]any) error
- func (e *Elastic) GetDocByID(ctx context.Context, index, id string, dist interface{}) error
- func (e *Elastic) GetMapping(ctx context.Context, name string) (map[string]interface{}, error)
- func (e *Elastic) IsExistsIndex(ctx context.Context, index string) bool
- func (e *Elastic) QueryCountByTime(ctx context.Context, index string, query elastic.Query) (int64, error)
- func (e *Elastic) QueryDocByOneQuery(ctx context.Context, index string, query elastic.Query) ([]byte, error)
- func (e *Elastic) QueryDoubleAggByTime(ctx context.Context, index, field, ntFiled string, query elastic.Query) (map[string]map[string]int64, error)
- func (e *Elastic) QueryMapsByTime(ctx context.Context, index, filed string, query elastic.Query) (map[string]int64, error)
- func (e *Elastic) QueryTopXByScroll(ctx context.Context, index string, query elastic.Query, x int) (chanr chan []byte, err error)
- func (e *Elastic) ReIndex(ctx context.Context, source, target string) error
- func (e *Elastic) SearchDocByQuery(ctx context.Context, index string, query elastic.Query, tar interface{}, ...) (string, error)
- func (e *Elastic) SearchDocByTermQuery(ctx context.Context, index string, tqs map[string]interface{}, tar interface{}, ...) (string, error)
- func (e *Elastic) SearchDocsBySourceQuery(ctx context.Context, index string, query elastic.Query, ops ...SearchOption) (*elastic.SearchResult, error)
- func (e *Elastic) SearchDocsByTermQuery(ctx context.Context, index string, tqs map[string]interface{}, ...) ([][]byte, error)
- func (e *Elastic) SyncBatchCreateDoc(ctx context.Context, index string, datas []interface{}) error
- func (e *Elastic) UpdateCoverDocByID(ctx context.Context, index, id string, doc interface{}) error
- func (e *Elastic) UpdateMapping(ctx context.Context, name string, mapping map[string]interface{}) error
- func (e *Elastic) UpdateMappingByReIndex(ctx context.Context, name string, mapping interface{}) error
- type IndexOption
- type Option
- type OptionFunc
- type SearchOption
Constants ¶
This section is empty.
Variables ¶
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 AsyncBatchCreateOptionFunc ¶
type AsyncBatchCreateOptionFunc func(abc *asyncBatchCreateOption)
func WithBulkActions ¶
func WithBulkActions(n int) AsyncBatchCreateOptionFunc
func WithFlushInterval ¶
func WithFlushInterval(t time.Duration) AsyncBatchCreateOptionFunc
func WithStats ¶
func WithStats(n bool) AsyncBatchCreateOptionFunc
func WithWorkerNum ¶
func WithWorkerNum(n int) AsyncBatchCreateOptionFunc
type AsyncHandle ¶
type AsyncHandle elastic.BulkAfterFunc
type DatContainer ¶
type Elastic ¶
type Elastic struct {
// contains filtered or unexported fields
}
Elastic 封装的ES操作器.
func NewElastic ¶
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) CreateDocByID ¶
CreateDocByID 创建一个文档
func (*Elastic) CreateIndex ¶
func (e *Elastic) CreateIndex(ctx context.Context, name string, mapping interface{}, ops ...IndexOption) error
CreateIndex 创建索引
func (*Elastic) DeleteDocByID ¶
DeleteDocByID 根据索引ID删除文档
func (*Elastic) DeleteDocByQuery ¶
func (e *Elastic) DeleteDocByQuery(ctx context.Context, index string, query elastic.Query) (int64, error)
DeleteDocByQuery 根据条件删除文档
func (*Elastic) DeleteIndex ¶
DeleteIndex 删除索引
func (*Elastic) DocIsExist ¶
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 ¶
GetDocByID 通过ID获取doc
func (*Elastic) GetMapping ¶
GetMapping 通过索引名称获取 mapping
func (*Elastic) IsExistsIndex ¶
func (*Elastic) QueryCountByTime ¶
func (*Elastic) QueryDocByOneQuery ¶
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 (*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 ¶
SyncBatchCreateDoc 同步的批量写入 TODO: 后期需要限制一下批量数量
func (*Elastic) UpdateCoverDocByID ¶
UpdateCoverDocByID 覆盖更新doc
type IndexOption ¶
type IndexOption func(*indexStruct)
func WithAliases ¶
func WithAliases(as []string) IndexOption
func WithAnalysis ¶
func WithAnalysis(analysis map[string]interface{}) IndexOption
WithAnalysis 配置解析器
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 SearchWithSort ¶
func SearchWithSort(field string, ascending bool) SearchOption