elasticsearch

package
v0.0.0-...-b804f52 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MulanPSL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RangeScopeLoRo left open & right open
	RangeScopeLoRo string = "( )"
	// RangeScopeLoRc left open & right close
	RangeScopeLoRc string = "( ]"
	// RangeScopeLcRo left close & right open
	RangeScopeLcRo string = "[ )"
	// RangeScopeLcRc lect close & right close
	RangeScopeLcRc string = "[ ]"

	// LikeLevelHigh wildcard keyword
	LikeLevelHigh string = "high"
	// LikeLevelMiddle ngram(1,2)
	LikeLevelMiddle string = "middle"
	// LikeLevelLow match split word
	LikeLevelLow string = "low"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BulkDeleteItemV7

type BulkDeleteItemV7 struct {
	IndexName string
	IndexID   string
}

type BulkIndexItemV7

type BulkIndexItemV7 struct {
	IndexName string
	IndexID   string
	OpType    string // create,index
	Doc       MapDataV7
}

type BulkUpsertItemV7

type BulkUpsertItemV7 struct {
	IndexName string
	IndexID   string
	Doc       MapDataV7
}

type Config

type Config struct {
	URL []string
	// supporting v7. Default to v7 if empty.
	Version string
	// optional username to communicate with ElasticSearch
	Username string
	// optional password to communicate with ElasticSearch
	Password string
	// optional to disable sniff, according to issues on Github,
	// Sniff could cause issue like "no Elasticsearch node available"
	DisableSniff bool
	// Gzip
	Compress bool
	// Debug
	Debug bool
	// httpClient
	TransportMaxIdleConns        int
	TransportMaxIdleConnsPerHost int
	TransportTimeout             time.Duration
	Timeout                      time.Duration
}

Config ...

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig ...

type GenericClient

type GenericClient interface {
	CreateIndex(ctx context.Context, index, mapping string) error
	DeleteIndex(ctx context.Context, index string) error
	PutMapping(ctx context.Context, index, root, key, valueType string) error
	Index(ctx context.Context, index, id, bodyJson string) (string, error)
	Delete(ctx context.Context, index, id string) (string, error)
	Update(ctx context.Context, index, id string, doc map[string]interface{}, p *UpdateParamsV7) (string, error)
	BulkIndex(ctx context.Context, bulkData []BulkIndexItemV7) (*elastic.BulkResponse, error)
	BulkDelete(ctx context.Context, bulkData []BulkDeleteItemV7) (*elastic.BulkResponse, error)
	BulkUpsert(ctx context.Context, upsertData *UpsertParamsV7) (*elastic.BulkResponse, error)
	CountByQuery(ctx context.Context, index, query string) (int64, error)
	Search(ctx context.Context, p *SearchParametersV7) (*elastic.SearchResult, error)
	SearchWithDSL(ctx context.Context, index, query string) (*elastic.SearchResult, error)
	QueryBody(sp *QueryBody) *elastic.BoolQuery
	Client() *elastic.Client
}

GenericClient is a generic interface for all versions of ElasticSearch clients

func Build

func Build(name string) (GenericClient, error)

func NewGenericClient

func NewGenericClient(connectConfig *Config) (GenericClient, error)

NewGenericClient create a ES Client

func NewV7Client

func NewV7Client(conf *Config, clientOptFuncs ...elastic.ClientOptionFunc) (GenericClient, error)

returns a new implementation of GenericClient

type MapDataV7

type MapDataV7 map[string]interface{}

type Page

type Page struct {
	Pn    int   `json:"num"`
	Ps    int   `json:"size"`
	Total int64 `json:"total"`
}

type QueryBody

type QueryBody struct {
	Fields []string       `json:"fields"` // default:"*" _source,default = *
	Where  QueryBodyWhere `json:"where"`
}

QueryBody .

type QueryBodyWhere

type QueryBodyWhere struct {
	EQ    map[string]interface{}     `json:"eq"` //可能是数据或字符,[12,333,67] ["asd", "你好"]
	Or    map[string]interface{}     `json:"or"` //暂时不支持minimum should
	In    map[string][]interface{}   `json:"in"`
	Range map[string]string          `json:"range"` //[10,20)  (2018-05-10 00:00:00,2018-05-31 00:00:00]  (,30]
	Like  []QueryBodyWhereLike       `json:"like"`
	Combo []*QueryBodyWhereCombo     `json:"combo"` //混合与或
	Not   map[string]map[string]bool `json:"not"`   //对eq、in、range条件取反
}

QueryBodyWhere .

type QueryBodyWhereCombo

type QueryBodyWhereCombo struct {
	EQ       []map[string]interface{}   `json:"eq"`
	In       []map[string][]interface{} `json:"in"`
	Range    []map[string]string        `json:"range"`
	NotEQ    []map[string]interface{}   `json:"not_eq"`
	NotIn    []map[string][]interface{} `json:"not_in"`
	NotRange []map[string]string        `json:"not_range"`
	Min      struct {
		EQ       int `json:"eq"`
		In       int `json:"in"`
		Range    int `json:"range"`
		NotEQ    int `json:"not_eq"`
		NotIn    int `json:"not_in"`
		NotRange int `json:"not_range"`
		Min      int `json:"min"`
	} `json:"min"`
}

QueryBodyWhereCombo .

func (*QueryBodyWhereCombo) ComboEQ

func (cmb *QueryBodyWhereCombo) ComboEQ(eq []map[string]interface{}) *QueryBodyWhereCombo

ComboEQ .

func (*QueryBodyWhereCombo) ComboIn

func (cmb *QueryBodyWhereCombo) ComboIn(in []map[string][]interface{}) *QueryBodyWhereCombo

ComboIn .

func (*QueryBodyWhereCombo) ComboNotEQ

func (cmb *QueryBodyWhereCombo) ComboNotEQ(eq []map[string]interface{}) *QueryBodyWhereCombo

ComboNotEQ .

func (*QueryBodyWhereCombo) ComboNotIn

func (cmb *QueryBodyWhereCombo) ComboNotIn(in []map[string][]interface{}) *QueryBodyWhereCombo

ComboNotIn .

func (*QueryBodyWhereCombo) ComboNotRange

func (cmb *QueryBodyWhereCombo) ComboNotRange(r []map[string]string) *QueryBodyWhereCombo

ComboNotRange .

func (*QueryBodyWhereCombo) ComboRange

func (cmb *QueryBodyWhereCombo) ComboRange(r []map[string]string) *QueryBodyWhereCombo

ComboRange .

func (*QueryBodyWhereCombo) MinAll

func (cmb *QueryBodyWhereCombo) MinAll(min int) *QueryBodyWhereCombo

MinAll .

func (*QueryBodyWhereCombo) MinEQ

func (cmb *QueryBodyWhereCombo) MinEQ(min int) *QueryBodyWhereCombo

MinEQ .

func (*QueryBodyWhereCombo) MinIn

func (cmb *QueryBodyWhereCombo) MinIn(min int) *QueryBodyWhereCombo

MinIn .

func (*QueryBodyWhereCombo) MinNotEQ

func (cmb *QueryBodyWhereCombo) MinNotEQ(min int) *QueryBodyWhereCombo

MinNotEQ .

func (*QueryBodyWhereCombo) MinNotIn

func (cmb *QueryBodyWhereCombo) MinNotIn(min int) *QueryBodyWhereCombo

MinNotIn .

func (*QueryBodyWhereCombo) MinNotRange

func (cmb *QueryBodyWhereCombo) MinNotRange(min int) *QueryBodyWhereCombo

MinNotRange .

func (*QueryBodyWhereCombo) MinRange

func (cmb *QueryBodyWhereCombo) MinRange(min int) *QueryBodyWhereCombo

MinRange .

type QueryBodyWhereLike

type QueryBodyWhereLike struct {
	KWFields []string `json:"kw_fields"`
	KW       []string `json:"kw"`    //将kw的值使用空白间隔给query
	Or       bool     `json:"or"`    //default:"false"
	Level    string   `json:"level"` //默认default
}

QueryBodyWhereLike .

type QueryResult

type QueryResult struct {
	Order  string          `json:"order"`
	Sort   string          `json:"sort"`
	Result json.RawMessage `json:"result"`

	Page *Page `json:"page"`
}

QueryResult query result.

type Request

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

Request request to elastic

func NewRequest

func NewRequest() *Request

NewRequest new a request every search query

func (*Request) Fields

func (r *Request) Fields(fields ...string) *Request

Fields add query fields

func (*Request) Params

func (r *Request) Params() *QueryBody

Params get query parameters

func (*Request) WhereCombo

func (r *Request) WhereCombo(cmb ...*QueryBodyWhereCombo) *Request

WhereCombo where combo

func (*Request) WhereEq

func (r *Request) WhereEq(field string, eq interface{}) *Request

WhereEq where equal

func (*Request) WhereIn

func (r *Request) WhereIn(field string, in interface{}) *Request

WhereIn where in

func (*Request) WhereLike

func (r *Request) WhereLike(fields, words []string, or bool, level string) *Request

WhereLike where like

func (*Request) WhereNot

func (r *Request) WhereNot(typ string, fields ...string) *Request

WhereNot where not

func (*Request) WhereOr

func (r *Request) WhereOr(field string, or interface{}) *Request

WhereOr where or

func (*Request) WhereRange

func (r *Request) WhereRange(field string, start, end interface{}, scope string) *Request

WhereRange where range

type SearchParametersV7

type SearchParametersV7 struct {
	Index       string
	Query       elastic.Query
	From        int
	PageSize    int
	Sorter      []elastic.Sorter
	Aggregation []map[string]elastic.Aggregation
	SearchAfter []interface{}
}

SearchParametersV7 holds all required and optional parameters for executing a search

type UpdateParamsV7

type UpdateParamsV7 struct {
	DetectNoop      bool
	RetryOnConflict int
}

type UpsertParamsV7

type UpsertParamsV7 struct {
	Insert          bool
	RetryOnConflict int
	UpsertBody      []BulkUpsertItemV7
}

type WrapErrorLogger

type WrapErrorLogger struct{}

func (WrapErrorLogger) Printf

func (logger WrapErrorLogger) Printf(format string, vars ...interface{})

type WrapInfoLogger

type WrapInfoLogger struct{}

func (WrapInfoLogger) Printf

func (logger WrapInfoLogger) Printf(format string, vars ...interface{})

type WrapTraceLogger

type WrapTraceLogger struct{}

func (WrapTraceLogger) Printf

func (logger WrapTraceLogger) Printf(format string, vars ...interface{})

Jump to

Keyboard shortcuts

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