Documentation
¶
Overview ¶
config.go
Index ¶
- type ApplicationPrivileges
- type Bulk
- func (b *Bulk) BulkCreate(ctx context.Context, index string, docs []map[string]interface{}) error
- func (b *Bulk) BulkDelete(ctx context.Context, index string, ids []string) error
- func (b *Bulk) BulkExecute(ctx context.Context, operations []BulkOperation) error
- func (b *Bulk) BulkIndex(ctx context.Context, index string, docs []map[string]interface{}) error
- func (b *Bulk) BulkUpdate(ctx context.Context, index string, docs []map[string]interface{}) error
- func (b *Bulk) MixedBulkExecute(ctx context.Context, indexOperations map[string][]BulkOperation) error
- type BulkOperation
- type Client
- func (c *Client) Bulk() *Bulk
- func (c *Client) ChangeUserPassword(ctx context.Context, username string, password string) error
- func (c *Client) CreateRole(ctx context.Context, roleName string, role Role) error
- func (c *Client) CreateUser(ctx context.Context, username string, user User) error
- func (c *Client) DeleteRole(ctx context.Context, roleName string) error
- func (c *Client) DeleteUser(ctx context.Context, username string) error
- func (c *Client) Document() *Document
- func (c *Client) GetRole(ctx context.Context, roleName string) (*Role, error)
- func (c *Client) GetUser(ctx context.Context, username string) (*User, error)
- func (c *Client) HealthCheck(ctx context.Context) (string, error)
- func (c *Client) Info(ctx context.Context) (map[string]interface{}, error)
- func (c *Client) NewSearch() SearchService
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) Search() SearchService
- func (c *Client) UpdateRole(ctx context.Context, roleName string, role Role) error
- func (c *Client) UpdateUser(ctx context.Context, username string, user User) error
- type Config
- type Document
- func (d *Document) BulkCreate(ctx context.Context, index string, docs []map[string]interface{}) error
- func (d *Document) BulkDelete(ctx context.Context, index string, ids []string) error
- func (d *Document) BulkIndex(ctx context.Context, index string, docs []map[string]interface{}) error
- func (d *Document) BulkUpdate(ctx context.Context, index string, updates []map[string]interface{}) error
- func (d *Document) CreateIndex(ctx context.Context, index string, mapping interface{}) error
- func (d *Document) Delete(ctx context.Context, index string, docID string) error
- func (d *Document) DeleteIndex(ctx context.Context, index string) error
- func (d *Document) Get(ctx context.Context, index string, docID string, result interface{}) error
- func (d *Document) Index(ctx context.Context, index string, doc interface{}, docID string) error
- func (d *Document) IndexExists(ctx context.Context, index string) (bool, error)
- func (d *Document) Update(ctx context.Context, index string, docID string, updateData interface{}) error
- type ESOptions
- type FieldSecurity
- type PaginatedResult
- type PaginatedSearchRequest
- type Pagination
- type PaginationResult
- type Role
- type RoleIndicesPermissions
- type ScrollSearchResult
- type SearchRequest
- type SearchRequestWithSearchAfter
- type SearchResult
- type SearchService
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApplicationPrivileges ¶
type ApplicationPrivileges struct {
Application string `json:"application"`
Privileges []string `json:"privileges"`
Resources []string `json:"resources,omitempty"`
}
ApplicationPrivileges 应用权限
type Bulk ¶
type Bulk struct {
// contains filtered or unexported fields
}
Bulk 批量操作接口
func (*Bulk) BulkCreate ¶
BulkCreate 批量创建文档
func (*Bulk) BulkDelete ¶
BulkDelete 批量删除文档
func (*Bulk) BulkExecute ¶
func (b *Bulk) BulkExecute(ctx context.Context, operations []BulkOperation) error
BulkExecute 执行批量操作
func (*Bulk) BulkUpdate ¶
BulkUpdate 批量更新文档
func (*Bulk) MixedBulkExecute ¶
func (b *Bulk) MixedBulkExecute(ctx context.Context, indexOperations map[string][]BulkOperation) error
MixedBulkExecute 混合批量操作
type BulkOperation ¶
type BulkOperation struct {
Index string `json:"_index"`
ID string `json:"_id,omitempty"`
Action string `json:"-"` // index, create, update, delete
Payload interface{} `json:"-"`
}
BulkOperation 批量操作项
type Client ¶
type Client struct {
*elasticsearch.Client
// contains filtered or unexported fields
}
Client ES客户端封装
func (*Client) ChangeUserPassword ¶
ChangeUserPassword 修改用户密码
func (*Client) CreateRole ¶
CreateRole 创建角色
func (*Client) CreateUser ¶
CreateUser 创建用户
func (*Client) DeleteRole ¶
DeleteRole 删除角色
func (*Client) DeleteUser ¶
DeleteUser 删除用户
func (*Client) HealthCheck ¶
HealthCheck 检查集群健康状态
func (*Client) UpdateRole ¶
UpdateRole 更新角色
type Config ¶
type Config struct {
Addresses []string `json:"addresses"`
Username string `json:"username"`
Password string `json:"password"`
APIKey string `json:"api_key"`
Timeout time.Duration `json:"timeout"`
// 连接池配置
MaxIdleConns int `json:"max_idle_conns"`
MaxIdleConnsPerHost int `json:"max_idle_conns_per_host"`
MaxConnsPerHost int `json:"max_conns_per_host"`
IdleConnTimeout time.Duration `json:"idle_conn_timeout"`
TLSHandshakeTimeout time.Duration `json:"tls_handshake_timeout"`
ExpectContinueTimeout time.Duration `json:"expect_continue_timeout"`
ResponseHeaderTimeout time.Duration `json:"response_header_timeout"`
ConnectionTimeout time.Duration `json:"connection_timeout"`
ConnectionKeepAlive time.Duration `json:"connection_keep_alive"`
// 重试配置
RetryOnStatus []int `json:"retry_on_status"`
MaxRetries int `json:"max_retries"`
RetryBackoff time.Duration `json:"retry_backoff"` // 基础重试间隔
}
Config Elasticsearch配置
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document 文档操作接口
func (*Document) BulkCreate ¶
func (d *Document) BulkCreate(ctx context.Context, index string, docs []map[string]interface{}) error
BulkCreate 批量创建文档
func (*Document) BulkDelete ¶
BulkDelete 批量删除文档
func (*Document) BulkIndex ¶
func (d *Document) BulkIndex(ctx context.Context, index string, docs []map[string]interface{}) error
BulkIndex 添加批量操作示例
func (*Document) BulkUpdate ¶
func (d *Document) BulkUpdate(ctx context.Context, index string, updates []map[string]interface{}) error
BulkUpdate 批量更新文档
func (*Document) CreateIndex ¶
CreateIndex 创建索引
func (*Document) DeleteIndex ¶
DeleteIndex 删除索引
func (*Document) IndexExists ¶
IndexExists 检查索引是否存在
type FieldSecurity ¶
type FieldSecurity struct {
Grant []string `json:"grant,omitempty"`
Except []string `json:"except,omitempty"`
}
FieldSecurity 字段安全设置
type PaginatedResult ¶
type PaginatedResult struct {
SearchResult
Pagination PaginationResult `json:"pagination"`
}
PaginatedResult 分页结果
type PaginatedSearchRequest ¶
type PaginatedSearchRequest struct {
Query interface{} `json:"query,omitempty"`
Pagination Pagination `json:"pagination,omitempty"`
Sort interface{} `json:"sort,omitempty"`
Source interface{} `json:"_source,omitempty"`
}
PaginatedSearchRequest 支持分页的搜索请求
type Pagination ¶
type Pagination struct {
Page int `json:"page"` // 页码,从1开始
PageSize int `json:"page_size"` // 每页大小
}
Pagination 分页信息
type PaginationResult ¶
type PaginationResult struct {
Page int `json:"page"` // 当前页码
PageSize int `json:"page_size"` // 每页大小
Total int `json:"total"` // 总记录数
TotalPages int `json:"total_pages"` // 总页数
}
PaginationResult 分页结果信息
type Role ¶
type Role struct {
Cluster []string `json:"cluster,omitempty"`
Indices []RoleIndicesPermissions `json:"indices,omitempty"`
Applications []ApplicationPrivileges `json:"applications,omitempty"`
Global interface{} `json:"global,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
TransientMetadata map[string]interface{} `json:"transient_metadata,omitempty"`
}
Role 角色结构
type RoleIndicesPermissions ¶
type RoleIndicesPermissions struct {
Names []string `json:"names"`
Privileges []string `json:"privileges"`
FieldSecurity *FieldSecurity `json:"field_security,omitempty"`
Query *string `json:"query,omitempty"`
AllowRestrictedIndices *bool `json:"allow_restricted_indices,omitempty"`
}
RoleIndicesPermissions 索引权限
type ScrollSearchResult ¶
type ScrollSearchResult struct {
SearchResult
ScrollID string `json:"_scroll_id,omitempty"`
}
ScrollSearchResult Scroll搜索结果
type SearchRequest ¶
type SearchRequest struct {
Query interface{} `json:"query,omitempty"`
Size int `json:"size,omitempty"`
From int `json:"from,omitempty"`
Sort interface{} `json:"sort,omitempty"`
Source interface{} `json:"_source,omitempty"`
}
SearchRequest 搜索请求
type SearchRequestWithSearchAfter ¶
type SearchRequestWithSearchAfter struct {
SearchRequest
SearchAfter []interface{} `json:"search_after,omitempty"`
}
SearchRequestWithSearchAfter 带search_after的搜索请求
type SearchResult ¶
type SearchResult struct {
Took int `json:"took"`
TimedOut bool `json:"timed_out"`
Hits struct {
Total struct {
Value int `json:"value"`
Relation string `json:"relation"`
} `json:"total"`
Hits []struct {
Index string `json:"_index"`
ID string `json:"_id"`
Score float64 `json:"_score"`
Source json.RawMessage `json:"_source"`
} `json:"hits"`
} `json:"hits"`
}
SearchResult 搜索结果
type SearchService ¶
type SearchService interface {
Search(ctx context.Context, index string, req SearchRequest) (*SearchResult, error)
SearchWithRawQuery(ctx context.Context, index string, query []byte) (*SearchResult, error)
SearchWithPagination(ctx context.Context, index string, req PaginatedSearchRequest) (*PaginatedResult, error)
ScrollSearch(ctx context.Context, index string, req SearchRequest, scrollTime time.Duration) (*ScrollSearchResult, error)
ScrollContinue(ctx context.Context, scrollID string, scrollTime time.Duration) (*ScrollSearchResult, error)
ScrollClear(ctx context.Context, scrollIDs []string) error
SearchWithSearchAfter(ctx context.Context, index string, req SearchRequestWithSearchAfter) (*SearchResult, error)
}
SearchService 搜索服务接口
type User ¶
type User struct {
Username string `json:"username,omitempty"`
FullName string `json:"full_name,omitempty"`
Email string `json:"email,omitempty"`
Roles []string `json:"roles"`
Password string `json:"password,omitempty"`
PasswordHash string `json:"password_hash,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
Enabled bool `json:"enabled"`
}
User Elasticsearch 用户结构