esutils

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SHOULD queryLogic = iota + 1
	MUST
	MUSTNOT
)
View Source
const (
	TEXT    esFieldType = "text"
	KEYWORD esFieldType = "keyword"
	DATE    esFieldType = "date"
	LONG    esFieldType = "long"
	INTEGER esFieldType = "integer"
	SHORT   esFieldType = "short"
	DOUBLE  esFieldType = "double"
	FLOAT   esFieldType = "float"
	BOOL    esFieldType = "boolean"
)

Variables

This section is empty.

Functions

func NewMapping

func NewMapping(mp MappingPayload) string

Types

type Base

type Base struct {
	Index string `json:"index"`
	Type  string `json:"type"`
}

func (*Base) GetIndex

func (b *Base) GetIndex() string

func (*Base) GetType

func (b *Base) GetType() string

func (*Base) SetType

func (b *Base) SetType(s string)

type Es

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

func NewEs

func NewEs(esIndex, esType string, opts ...EsOption) *Es

func (*Es) BulkDelete

func (es *Es) BulkDelete(ctx context.Context, ids []string) error

func (*Es) BulkSaveOrUpdate

func (es *Es) BulkSaveOrUpdate(ctx context.Context, docs []interface{}) error

func (*Es) CheckTypeExists

func (es *Es) CheckTypeExists(ctx context.Context) (b bool, err error)

func (*Es) ClearIndex

func (es *Es) ClearIndex(ctx context.Context) error

func (*Es) Count

func (es *Es) Count(ctx context.Context, paging *Paging) (int64, error)

func (*Es) DeleteIndex

func (es *Es) DeleteIndex(ctx context.Context) error

func (*Es) GetByID

func (es *Es) GetByID(ctx context.Context, id string) (map[string]interface{}, error)

func (*Es) List

func (es *Es) List(ctx context.Context, paging *Paging, callback func(message json.RawMessage) (interface{}, error)) ([]interface{}, error)

func (*Es) NewIndex

func (es *Es) NewIndex(ctx context.Context, mapping string) (exists bool, err error)

func (*Es) Page

func (es *Es) Page(ctx context.Context, paging *Paging) (PageResult, error)

func (*Es) PutMapping

func (es *Es) PutMapping(ctx context.Context, mp MappingPayload) error

func (*Es) Random

func (es *Es) Random(ctx context.Context, paging *Paging) ([]map[string]interface{}, error)

if paging is nil, randomly return 10 pcs of documents as default

func (*Es) SaveOrUpdate

func (es *Es) SaveOrUpdate(ctx context.Context, doc interface{}) (string, error)

func (*Es) SetIndex added in v0.3.6

func (e *Es) SetIndex(index string)

func (*Es) SetType added in v0.3.6

func (e *Es) SetType(estype string)

func (*Es) Stat

func (es *Es) Stat(ctx context.Context, paging *Paging, aggr interface{}) (map[string]interface{}, error)

aggr only accept map[string]interface{} or elastic.Aggregation

type EsOption

type EsOption func(*Es)

func WithClient

func WithClient(client *elastic.Client) EsOption

func WithLogger

func WithLogger(logger *logrus.Logger) EsOption

func WithPassword

func WithPassword(password string) EsOption

func WithUrls

func WithUrls(urls []string) EsOption

func WithUsername

func WithUsername(username string) EsOption

type Field

type Field struct {
	Name   string      `json:"name"`
	Type   esFieldType `json:"type"`
	Format string      `json:"format"`
}

type IBase

type IBase interface {
	GetIndex() string
	GetType() string
	SetType(s string)
}

type MappingPayload

type MappingPayload struct {
	Base
	Fields []Field `json:"fields"`
}

type PageResult

type PageResult struct {
	Page        int           `json:"page"` // from 1
	PageSize    int           `json:"page_size"`
	Total       int           `json:"total"`
	Docs        []interface{} `json:"docs"`
	HasNextPage bool          `json:"has_next_page"`
}

type Paging

type Paging struct {
	StartDate  string      `json:"startDate"`
	EndDate    string      `json:"endDate"`
	DateField  string      `json:"dateField"`
	QueryConds []QueryCond `json:"queryConds"`
	Skip       int         `json:"skip"`
	Limit      int         `json:"limit"`
	Sortby     []Sort      `json:"sortby"`
}

type QueryCond

type QueryCond struct {
	Pair       map[string][]interface{} `json:"pair"`
	QueryLogic queryLogic               `json:"queryLogic"`
	QueryType  queryType                `json:"queryType"`
	Children   []QueryCond              `json:"children"`
}

type Sort

type Sort struct {
	Field     string `json:"field"`
	Ascending bool   `json:"ascending"`
}

Jump to

Keyboard shortcuts

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