XEsOlivere

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2021 License: MIT Imports: 7 Imported by: 0

README

ElasticSearch 客户端

基于 github.com/olivere/elastic/v7 包

ElasticSearch Documentation

Documentation https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html

XEsOlivere Starter Usage
// ...

goinfras.Register(XEsOlivere.NewStarter())

// ...
XEsOlivere Config Setting
URL         string // 服务地址
	Username    string // 鉴权用户名
	Password    string // 鉴权密码
	Sniff       bool   // 启用或禁用嗅探器。
	Healthcheck bool   // 启用连接健康检查
	Infolog     string // Info级别日志记录文件路径
	Errorlog    string // Error级别日志记录文件路径
	Tracelog    string // Trace级别日志记录文件路径

XEsOlivere Usage
// 查找文档是否存在
XEsOlivere.XCommon().IsDocExists(1,"xxxxxxxx")

// 获取
XEsOlivere.XCommon().GetDoc(1,"xxxxxxxx")

// 新增文档
XEsOlivere.XCommon().AddDoc(1,"xxxxxxxx")

// 更新文档
XEsOlivere.XCommon().UpdateDoc(1,"xxxxxxxx")

// 删除文档
XEsOlivere.XCommon().DeleteDoc(1,"xxxxxxxx")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDefaultESClient

func CreateDefaultESClient() error

创建默认的ES Client

func NewESClient

func NewESClient(cfg *Config) (*elasticv7.Client, error)

func NewStarter

func NewStarter() *starter

应用注册启动器时创建

func XClient

func XClient() *elasticv7.Client

func XFClient

func XFClient(f func(c *elasticv7.Client) error) error

Types

type Config

type Config struct {
	URL         string // 服务地址
	Username    string // 鉴权用户名
	Password    string // 鉴权密码
	Sniff       bool   // 启用或禁用嗅探器。
	Healthcheck bool   // 启用连接健康检查
	Infolog     string // Info级别日志记录文件路径
	Errorlog    string // Error级别日志记录文件路径
	Tracelog    string // Trace级别日志记录文件路径
}

func DefaultConfig

func DefaultConfig() *Config

type EsCommonDoc

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

一些常用的文档操作方法

func XCommonDoc

func XCommonDoc() *EsCommonDoc

func (*EsCommonDoc) AddDoc

func (c *EsCommonDoc) AddDoc(docId, esType, esIndex string, doc interface{}) (*elasticv7.IndexResponse, error)

添加文档

func (*EsCommonDoc) BatchAddDoc

func (c *EsCommonDoc) BatchAddDoc(esIndex, esType string, datas ...interface{}) error

批量插入

func (*EsCommonDoc) DeleteDoc

func (c *EsCommonDoc) DeleteDoc(docId, esType, esIndex string) (*elasticv7.DeleteResponse, error)

删除文档

func (*EsCommonDoc) GetDoc

func (c *EsCommonDoc) GetDoc(docId, esIndex string) (*elasticv7.GetResult, error)

获取文档

func (*EsCommonDoc) IsDocExists

func (c *EsCommonDoc) IsDocExists(docId, esType, esIndex string) (bool, error)

查看某文档是否存在,给定文档ID查询

func (*EsCommonDoc) UpdateDoc

func (c *EsCommonDoc) UpdateDoc(updateField *map[string]interface{}, docId, esType, esIndex string) (*elasticv7.UpdateResponse, error)

更新文档

type EsCommonSearch

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

一些常用的搜索方法

func XCommonSearch

func XCommonSearch() *EsCommonSearch

func (*EsCommonSearch) MultiSearch

func (c *EsCommonSearch) MultiSearch(ctx context.Context, esIndex string, requests ...*elasticv7.SearchRequest) (*elasticv7.MultiSearchResult, error)

func (*EsCommonSearch) Search

func (c *EsCommonSearch) Search(ctx context.Context, esIndex, esType string, query elasticv7.Query) (*elasticv7.SearchResult, error)

func (*EsCommonSearch) SearchShards

func (c *EsCommonSearch) SearchShards(ctx context.Context, indies ...string) (*elasticv7.SearchShardsResponse, error)

Jump to

Keyboard shortcuts

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