esx

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

README

esx

ES 通用模块

tag v2
  • 按照通用模块结构规划代码
  • git push <tag_name>
  • git push --tags
  • git push --delete <tag_name>

Documentation

Index

Constants

View Source
const (
	HTTP_SELF_CODE      = 900 // 自定义的http状态码边界
	HTTP_REQ_FAIL       = 901 // 请求发起就失败了, 不涉及响应
	HTTP_RESP_READ_FAIL = 902 // 响应数据读取失败

	ES_REJECTED_ERROR = "es_rejected_execution_exception"
)

Variables

This section is empty.

Functions

func AliasAction

func AliasAction(client *Client, aliasname string, actions []map[string]map[string]string) error

AliasAction 执行alias操作

func AliasActionWithPool

func AliasActionWithPool(aliasname string, actions []map[string]map[string]string) error

AliasActionWithPool 执行指定alias操作

func AliasQuery

func AliasQuery(client *Client, aliasname string) ([]string, error)

AliasQuery 查询当前指定alias配置

func AliasQueryWithPool

func AliasQueryWithPool(aliasname string) ([]string, error)

AliasQueryWithPool 查询当前alias配置

func Create

func Create(client *Client, indexname string) bool

Create 创建指定index

func CreateWithPool

func CreateWithPool(indexname string) bool

CreateWithPool 创建指定index

func Del

func Del(client *Client, indexList []string) []string

Del 删除指定index 返回删除失败的index列表

func DelWithPool

func DelWithPool(indexList []string) []string

DelWithPool 删除指定index 返回删除失败的index列表

func Exist

func Exist(client *Client, indexname string) bool

Exist 判断index是否存在 true => 存在, false => 不存在

func ExistWithPool

func ExistWithPool(indexname string) bool

ExistWithPool 判断index是否存在 true => 存在, false => 不存在

func Flush

func Flush(client *Client, indexname string) bool

Flush 刷新index true => 成功, false => 失败

func FlushWithPool

func FlushWithPool(indexname string) bool

FlushWithPool 刷新index true => 成功, false => 失败

func GetTimeTemps

func GetTimeTemps(s string) string

GetTimeTemps 将Java的时间格式符转变成Go的

func NewPool

func NewPool(logger *zap.Logger, opt Option, size int) error

func TempCreate

func TempCreate(client *Client, name string, qdata []byte) error

TempCreate 创建模板

func TempCreateWithPool

func TempCreateWithPool(name string, qdata []byte) error

TempCreateWithPool 创建模板

func TempExist

func TempExist(client *Client, name string) bool

TempExist 判断模板是否存在 true => 存在, false => 不存在

func TempExistWithPool

func TempExistWithPool(name string) bool

TempExistWithPool 判断模板是否存在 true => 存在, false => 不存在

Types

type Ack

type Ack struct {
	Acknowledged bool `json:"acknowledged"`
	Status       int  `json:"status"`
}

type BulkClient

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

func NewBulkClient

func NewBulkClient(logger *zap.Logger, client *Client, opt BulkOption) *BulkClient

func (*BulkClient) Add

func (c *BulkClient) Add(indexname, typename, message string) (int, time.Duration)

Add 插入一条记录 返回执行的条目数 + 耗时, 提供给可能的统计模块

func (*BulkClient) Send

func (c *BulkClient) Send() (int, time.Duration)

Send 当调用方推出循环后, 如果缓冲中仍然有数据的, 调用该方法完成发送 返回执行的条目数 + 耗时, 提供给可能的统计模块

func (*BulkClient) Stop

func (c *BulkClient) Stop()

func (*BulkClient) Tick

func (c *BulkClient) Tick() (int, time.Duration)

Tick 提供外部Ticker调用 返回执行的条目数 + 耗时, 提供给可能的统计模块

type BulkOption

type BulkOption struct {
	Tid     int
	MaxCT   int
	MaxSize int
	MaxTime time.Duration
}

type Client

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

func NewClient

func NewClient(logger *zap.Logger, opt Option) (*Client, error)

func NewClientWithID

func NewClientWithID(logger *zap.Logger, opt Option, tid int) (*Client, error)

func (*Client) GetResponse

func (c *Client) GetResponse(method, uri, data string, headers map[string]string) (int, []byte)

type ClientPool

type ClientPool struct {
	// contains filtered or unexported fields
}
var (
	Pool *ClientPool
)

func (*ClientPool) Get

func (c *ClientPool) Get() *Client

func (*ClientPool) GetTimeout

func (c *ClientPool) GetTimeout(t time.Duration) (*Client, error)

func (*ClientPool) Put

func (c *ClientPool) Put(client *Client)

type EasyRequest

type EasyRequest struct {
	Size           int64               `json:"size"`
	PreIndex       string              `json:"preIndex"`
	TimePattern    string              `json:"timePattern"`
	TimeField      string              `json:"timeField" default:"@timestamp"`
	TimeShift      int64               `json:"timeShift"` // 本地的偏移时区, 比如UTC就是-8
	TimeFrom       int64               `json:"timeFrom"`
	TimeTill       int64               `json:"timeTill"`
	Interval       string              `json:"interval"`
	QueryString    string              `json:"querystring"`
	Funcs          map[string][]string `json:"funcs"`
	Terms          []string            `json:"terms"`
	Filters        map[string]any      `json:"filters"`
	Shoulds        []map[string]any    `json:"shoulds"`
	MustNot        []map[string]any    `json:"must_not"`
	ScriptedMetric *ScriptedMetric     `json:"scripted_metric,omitempty"`
}

EasyRequest 简易的ES请求结构体, 会自动封装实际的DSL

type HealthResult added in v1.0.5

type HealthResult struct {
	Status          string  `json:"status"`
	NumOfNodes      int     `json:"number_of_nodes"`
	NumOfDataNodes  int     `json:"number_of_data_nodes"`
	ActiveShards    int     `json:"active_shards"`
	ActivePriShards int     `json:"active_primary_shards"`
	RelocatShards   int     `json:"relocating_shards"`
	InitingShards   int     `json:"initializing_shards"`
	UnAssignShards  int     `json:"unassigned_shards"`
	DelayShards     int     `json:"delayed_unassigned_shards"`
	PendingTasks    int     `json:"number_of_pending_tasks"`
	InFlightFetch   int     `json:"number_of_in_flight_fetch"`
	TaskMaxWaitMs   int     `json:"task_max_waiting_in_queue_millis"`
	ActiveSdPct     float64 `json:"active_shards_percent_as_number"`
}

func Health added in v1.0.5

func Health(client *Client) (HealthResult, error)

func HealthWithPool added in v1.0.5

func HealthWithPool() (HealthResult, error)

type HitsResponse

type HitsResponse struct {
	Index  string         `json:"_index"`
	Score  float64        `json:"_score"`
	Source map[string]any `json:"_source"`
}

type IndexInfo added in v1.0.5

type IndexInfo struct {
	Status string `json:"status"`
	Index  string `json:"index"`
}

func Cat added in v1.0.5

func Cat(client *Client, pattern string) ([]IndexInfo, error)

Cat 查看index信息列表

func CatWithPool added in v1.0.5

func CatWithPool(pattern string) ([]IndexInfo, error)

type Option

type Option struct {
	Addrs    []string
	Username string
	Password string
	Timeout  time.Duration
}

type ReqParam

type ReqParam struct {
	Terms []string
}

type ScriptedMetric

type ScriptedMetric struct {
	Toggle        bool           `json:"toggle,omitempty"` // 定义是否展开script结果集, 默认不展开, 通常只有结果是单层map如 map[string]int 时才有展开需求
	Params        map[string]any `json:"params,omitempty"`
	InitScript    string         `json:"init_script"`
	MapScript     string         `json:"map_script"`
	CombineScript string         `json:"combine_script"`
	ReduceScript  string         `json:"reduce_script"`
}

ScriptedMetric 提供给scripted_metric专用结构体

type SearchRequest

type SearchRequest struct {
	Indices []string `json:"-"`
	Size    int64    `json:"size"`
	Query   struct {
		Bool struct {
			Filter             []map[string]any `json:"filter,omitempty"`
			Must               []map[string]any `json:"must,omitempty"` // v0.1版本不提供must
			MustNot            []map[string]any `json:"must_not,omitempty"`
			Should             []map[string]any `json:"should,omitempty"`
			MinimumShouldMatch int              `json:"minimum_should_match,omitempty"`
		} `json:"bool,omitempty"`
	} `json:"query,omitempty"`
	Aggs map[string]map[string]any `json:"aggs,omitempty"`
}

SearchRequest 实际的DSL请求结构体

func NewSearchRequest

func NewSearchRequest(in *EasyRequest) (SearchRequest, error)

func (*SearchRequest) Tostring

func (c *SearchRequest) Tostring() string

type SearchResponse

type SearchResponse struct {
	Timeout bool `json:"timed_out"`
	Shards  struct {
		Total      int `json:"total"`
		Successful int `json:"successful"`
	} `json:"_shards"`
	Status int `json:"status"`
	Hits   struct {
		Total int64          `json:"total"`
		Hits  []HitsResponse `json:"hits"`
	} `json:"hits"`
	Aggs map[string]json.RawMessage `json:"aggregations"`
}

SearchResponse ES响应的报文结构体

type SearchResult

type SearchResult struct {
	Total int64            `json:"total"`
	Hits  []map[string]any `json:"hits"`
	Aggs  []map[string]any `json:"aggs"`
}

SearchResult 自动解析后的结构体

func ParseSearchResult

func ParseSearchResult(in []byte, req *EasyRequest) (SearchResult, error)
func Search(client *Client, in EasyRequest) (SearchResult, error)

Search 查询数据接口

func SearchWithPool

func SearchWithPool(in EasyRequest) (SearchResult, error)

SearchWithPool 查询数据接口

func (*SearchResult) Tostring

func (c *SearchResult) Tostring() string

Jump to

Keyboard shortcuts

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