elastic8

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ES_LOG_MAX_REQ_LEN  = "ES_LOG_MAX_REQ_LEN"
	ES_LOG_MAX_RESP_LEN = "ES_LOG_MAX_RESP_LEN"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ElasticConf

type ElasticConf struct {
	Addr          string `yaml:"addr"`
	Username      string `yaml:"username"`
	Password      string `yaml:"password"`
	MaxReqBodyLen int    `yaml:"maxReqBodyLen"`
	// response body 最大长度展示,0表示采用默认的10240,-1表示不打印。指定长度的时候需注意,返回的json可能被截断
	MaxRespBodyLen int `yaml:"maxRespBodyLen"`
}

type ElasticsearchClient

type ElasticsearchClient struct {
	Client        *elasticsearch.TypedClient
	MaxReqBodyLen int
	// response body 最大长度展示,0表示采用默认的10240,-1表示不打印。指定长度的时候需注意,返回的json可能被截断
	MaxRespBodyLen int
}

func InitESClient

func InitESClient(conf ElasticConf) (*ElasticsearchClient, error)

func (*ElasticsearchClient) CheckIndex

func (ec *ElasticsearchClient) CheckIndex(ctx *gin.Context, indexName string) (bool, error)

CheckIndex 判断索引是否存在

func (*ElasticsearchClient) CreateIndex

func (ec *ElasticsearchClient) CreateIndex(ctx *gin.Context, indexName string, mapping *types.TypeMapping, setting *types.IndexSettings) error

CreateIndex 根据提供的 mapping 创建索引

func (*ElasticsearchClient) DeleteIndex

func (ec *ElasticsearchClient) DeleteIndex(ctx *gin.Context, indexName string) error

删除索引

func (*ElasticsearchClient) DocumentDelete

func (ec *ElasticsearchClient) DocumentDelete(ctx *gin.Context, indexName string, query *types.Query) error

BulkDelete 批量删除文档

func (*ElasticsearchClient) DocumentInsert

func (ec *ElasticsearchClient) DocumentInsert(ctx *gin.Context, indexName string, docs []any) (err error)

BulkInsert 批量插入数据,批量限制为 3000 条

func (*ElasticsearchClient) Search

func (ec *ElasticsearchClient) Search(ctx *gin.Context, indexName string, query *search.Request) (*search.Response, error)

Search 混合查询

Jump to

Keyboard shortcuts

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