Documentation ¶
Overview ¶
Package elastic 提供 elastic 搜索工具
Index ¶
- func ParseSearchResult[T any](esRes *es.SearchResult) []T
- type BoolQuerier
- func (q *BoolQuerier) Compare(field string, op RangeOperator, target any) *BoolQuerier
- func (q *BoolQuerier) Contains(field string, keyword any) *BoolQuerier
- func (q *BoolQuerier) Debug(f func(string, ...any)) *BoolQuerier
- func (q *BoolQuerier) Do(ctx context.Context, cli *es.Client) (*es.SearchResult, error)
- func (q *BoolQuerier) EQ(field string, value any) *BoolQuerier
- func (q *BoolQuerier) From(from int) *BoolQuerier
- func (q *BoolQuerier) Fuzzy(field string, keyword any) *BoolQuerier
- func (q *BoolQuerier) In(field string, values any) *BoolQuerier
- func (q *BoolQuerier) Limit(limit int) *BoolQuerier
- func (q *BoolQuerier) SortAsc(field string) *BoolQuerier
- func (q *BoolQuerier) SortDesc(field string) *BoolQuerier
- func (q *BoolQuerier) String() string
- type ESHit
- type RangeOperator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseSearchResult ¶
func ParseSearchResult[T any](esRes *es.SearchResult) []T
ParseSearchResult 解析 elastic 搜索结果
Types ¶
type BoolQuerier ¶
type BoolQuerier struct { Index string // contains filtered or unexported fields }
BoolQuerier 表示简单的 bool 搜索器
func NewBoolQuerier ¶
func NewBoolQuerier(index string) *BoolQuerier
NewBoolQuerier 新建 BoolQuerier 对象
func (*BoolQuerier) Compare ¶
func (q *BoolQuerier) Compare(field string, op RangeOperator, target any) *BoolQuerier
Compare 非等比较
func (*BoolQuerier) Contains ¶
func (q *BoolQuerier) Contains(field string, keyword any) *BoolQuerier
Contains 表示搜索包含某个关键字, 适合 text 类型
func (*BoolQuerier) Debug ¶
func (q *BoolQuerier) Debug(f func(string, ...any)) *BoolQuerier
Debug 指定调试输出器
func (*BoolQuerier) Do ¶
func (q *BoolQuerier) Do(ctx context.Context, cli *es.Client) (*es.SearchResult, error)
func (*BoolQuerier) EQ ¶
func (q *BoolQuerier) EQ(field string, value any) *BoolQuerier
EQ 表示相等条件。请注意, EQ 不适用于 text 类型字段, 因为 text 类型通常会被分词器处理成多个 tokens, 而 EQ 使用了 terms, 这是用来精确匹配单个词条的。
func (*BoolQuerier) Fuzzy ¶
func (q *BoolQuerier) Fuzzy(field string, keyword any) *BoolQuerier
Contains 表示模糊搜索某个关键字, 适合 text 类型
func (*BoolQuerier) In ¶
func (q *BoolQuerier) In(field string, values any) *BoolQuerier
In 表示类似 SQL 的 IN 逻辑。其中 values 必须是一个 slice, 但可以是任意类型的 slice
func (*BoolQuerier) SortDesc ¶
func (q *BoolQuerier) SortDesc(field string) *BoolQuerier
SortDesc 降序
func (*BoolQuerier) String ¶
func (q *BoolQuerier) String() string
type ESHit ¶
ESHit 包含 ES 命中之后的外层参数
func ParseWrappedSearchResult ¶
func ParseWrappedSearchResult[T any](esRes *es.SearchResult) []ESHit[T]
ParseSearchResult 解析 elastic 搜索结果, 同时包含外部的其他额外参数
type RangeOperator ¶
type RangeOperator string
RangeOperator 表示 range 所支持的操作符, 也可以通用字符串直接传参
const ( LT RangeOperator = "<" LE RangeOperator = "<=" GT RangeOperator = ">" GE RangeOperator = ">=" )
Click to show internal directories.
Click to hide internal directories.