Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ESError ¶
type ESError struct {
Status int `json:"status"` // HTTP状态码
// 错误信息
Error *ErrorDetail `json:"error"` // 错误详情
}
type ESScrollCallback ¶
ESScrollCallback 定义ES滚动查询回调函数类型
type ESSearchResponse ¶
type ESSearchResponse struct {
// 请求元信息
Took int `json:"took"` // 查询耗时(毫秒)
TimedOut bool `json:"timed_out"` // 是否超时
// 分片信息
Shards *ShardsInfo `json:"_shards"` // 分片信息
// 查询结果
Hits *HitsContainer `json:"hits"` // 命中结果
// 聚合结果
Aggregations map[string]interface{} `json:"aggregations"` // 聚合结果
// 分页/滚动
ScrollID string `json:"_scroll_id"` // 滚动查询ID
PitID string `json:"pit_id"` // Point in Time ID
ESError
}
ESSearchResponse 包含成功和错误响应的统一结构
func (*ESSearchResponse) GetErrorMessage ¶
func (r *ESSearchResponse) GetErrorMessage() string
GetErrorMessage 获取错误消息
func (*ESSearchResponse) GetHits ¶
func (r *ESSearchResponse) GetHits() []*Hit
func (*ESSearchResponse) GetTotal ¶
func (r *ESSearchResponse) GetTotal() int
func (*ESSearchResponse) HasPartialResults ¶
func (r *ESSearchResponse) HasPartialResults() bool
HasPartialResults 判断是否有部分结果(部分分片失败)
type ErrorDetail ¶
type ErrorDetail struct {
Type string `json:"type"` // 错误类型
Reason string `json:"reason"` // 可读的错误原因
ResourceType string `json:"resource.type"` // 相关资源类型
ResourceID string `json:"resource.id"` // 相关资源ID
Index string `json:"index"` // 相关索引
Phase string `json:"phase"` // 错误阶段
RootCause []*ErrorDetail `json:"root_cause"` // 根本原因列表
CausedBy map[string]any `json:"caused_by"` // 导致错误的底层原因
Metadata map[string]any `json:"metadata"` // 错误元数据
}
ErrorDetail 错误详情
type EsScroll ¶
type EsScroll struct {
ESClient *elasticsearch.Client // Elasticsearch客户端
SearchRequest *esapi.SearchRequest // 搜索请求
ScrollTime time.Duration // 滚动查询保持时间
BatchSize int // 每批处理的数据量
Index []string // 查询索引
QueryBody io.Reader // 查询体
SortFields []string // 排序字段
}
func (*EsScroll) DoESSearchWithScroll ¶
func (this *EsScroll) DoESSearchWithScroll(ctx context.Context, callback ESScrollCallback) error
DoESSearchWithScroll 执行ES滚动查询
type Hit ¶
type Hit struct {
Index string `json:"_index"` // 索引名
ID string `json:"_id"` // 文档ID
Score float64 `json:"_score"` // 相关性得分
Source map[string]any `json:"_source"` // 文档原始数据
Version int `json:"_version"` // 版本号
SeqNo int64 `json:"_seq_no"` // 序列号
PrimaryTerm int64 `json:"_primary_term"` // 主任期
Highlight map[string][]string `json:"highlight"` // 高亮结果
Fields map[string]any `json:"fields"` // 字段数据
Sort []any `json:"sort"` // 排序值
}
Hit 单个命中文档
type HitsContainer ¶
type HitsContainer struct {
Total *TotalHits `json:"total"` // 总命中数信息
MaxScore float64 `json:"max_score"` // 最大得分
Hits []*Hit `json:"hits"` // 命中文档列表
}
HitsContainer 命中结果容器
Click to show internal directories.
Click to hide internal directories.