ees

package module
v0.0.0-...-16b8504 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

ees

Descriptions
  • Implementing a functionalised code base for the V7 version of es
Run
  • Just pull the code directly

Documentation

Index

Constants

View Source
const (
	AggregationSize = 1000
	CollapseSize    = 1000
)

size

View Source
const (
	SortAsc  = "ASC"
	SortDesc = "DESC"
)

sort

View Source
const (
	ActionAnd = 1
	ActionOr  = 2
	ActionNot = 3
)
View Source
const (
	CreateSucc   = "created"
	UpdateSucc   = "updated"
	DeleteSucc   = "deleted"
	Noop         = "noop"
	DefaultLimit = "1000"
)
View Source
const (
	DefaultNum = 0
	// type
	Type = _type(DefaultNum)
	// dynamic type
	Dynamic = _dynamic(DefaultNum)
	//index type
	Index = _index(DefaultNum)

	// yyyy-MM-dd HH:mm:ss
	DateTimeFormat = "yyyy-MM-dd HH:mm:ss"
	// yyyy-MM-dd
	DateFormat = "yyyy-MM-dd"
	//HH:mm:ss
	TimeFormat = "HH:mm:ss"

	BoolTrue  = true
	BoolFalse = false
)

版本7.x

Variables

This section is empty.

Functions

func FieldAnalyzer

func FieldAnalyzer(fieldName, val string) *elastic.MatchPhraseQuery

text type to Analyzer

func FieldArray

func FieldArray(fieldName string) *elastic.SliceQuery

list query

func FieldEq

func FieldEq(fieldName string, val interface{}) *elastic.TermQuery

func FieldIN

func FieldIN(fieldName string, val ...interface{}) *elastic.TermsQuery

func FieldLike

func FieldLike(fieldName, val string) *elastic.FuzzyQuery

func FieldNotNull

func FieldNotNull(fieldName string) *elastic.ExistsQuery

func FieldRange

func FieldRange(fieldName string) *elastic.RangeQuery

func FieldStartWith

func FieldStartWith(fieldName, subString string) *elastic.PrefixQuery

func FieldTopID

func FieldTopID(query Query, ids ...string) *elastic.PinnedQuery

top by ID

func Float64ToString

func Float64ToString(val interface{}) string

func IkMaxWord

func IkMaxWord() string

IkMaxWord analyzer ,search_analyzer can use

func IkSmart

func IkSmart() string

IkSmart analyzer ,search_analyzer can use

Types

type EQueryReq

type EQueryReq struct {
	Index []string
	Query Query
	// contains filtered or unexported fields
}

func BuildEQueryReq

func BuildEQueryReq(q *QueryCondition) *EQueryReq

func NewEQueryReq

func NewEQueryReq(index ...string) *EQueryReq

func (*EQueryReq) SetAggregation

func (e *EQueryReq) SetAggregation(aliseName string, fieldName string) *EQueryReq

func (*EQueryReq) SetAggregationOpt

func (e *EQueryReq) SetAggregationOpt(aliseName string, aggregation elastic.Aggregation) *EQueryReq

func (*EQueryReq) SetCollapseField

func (e *EQueryReq) SetCollapseField(collapseField string) *EQueryReq

func (*EQueryReq) SetExcludesSource

func (e *EQueryReq) SetExcludesSource(excludes ...string) *EQueryReq

func (*EQueryReq) SetFetchSource

func (e *EQueryReq) SetFetchSource(fetchSource bool) *EQueryReq

fetchSource = true ==>need show fields

func (*EQueryReq) SetIncludesSource

func (e *EQueryReq) SetIncludesSource(includes ...string) *EQueryReq

func (*EQueryReq) SetPage

func (e *EQueryReq) SetPage(pageNo, pageSize int) *EQueryReq

func (*EQueryReq) SetSort

func (e *EQueryReq) SetSort(sortField ...elastic.Sorter) *EQueryReq

eg: elastic.NewFieldSort("field").Desc() desc = 4,3,2,1

func (*EQueryReq) Source

func (e *EQueryReq) Source() (interface{}, error)

type Eelastic

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

func NewClient

func NewClient(opts ...elastic.ClientOptionFunc) (client *Eelastic, err error)

init client

func (*Eelastic) Client

func (e *Eelastic) Client() *elastic.Client

func (*Eelastic) Count

func (e *Eelastic) Count(ctx context.Context, indexName ...string) (int64, error)

func (*Eelastic) DelIndexAlias

func (e *Eelastic) DelIndexAlias(ctx context.Context, index, AliasName string) (bool, error)

func (*Eelastic) DelItemByID

func (e *Eelastic) DelItemByID(ctx context.Context, index string, id string) (isDel bool, err error)

删除数据

func (*Eelastic) DelItemByIDs

func (e *Eelastic) DelItemByIDs(ctx context.Context, index string, ids ...interface{}) (count int64, err error)

ids can int or string

func (*Eelastic) DelTable

func (e *Eelastic) DelTable(ctx context.Context, index string) (isok bool, err error)

func (*Eelastic) GetIndexDetail

func (e *Eelastic) GetIndexDetail(ctx context.Context, index ...string) (map[string]interface{}, error)

func (*Eelastic) GetItemByID

func (e *Eelastic) GetItemByID(index string, id interface{}) (rep *elastic.GetResult, err error)

get data

func (*Eelastic) InitTable

func (e *Eelastic) InitTable(ctx context.Context, index string, mappings interface{}) (bool, error)

Here we think table = index, all _type = default("_doc")

func (*Eelastic) MultiSearch

func (e *Eelastic) MultiSearch(ctx context.Context, req MultiQueryReq) (*elastic.MultiSearchResult, error)

if version =8.* some version can not use it to search

func (*Eelastic) QueryAggregations

func (e *Eelastic) QueryAggregations(ctx context.Context, query *EQueryReq) (*elastic.SearchResult, error)

func (*Eelastic) QuerySql

func (e *Eelastic) QuerySql(ctx context.Context, sql string, result interface{}) (total int64, err error)

between 支持数字类型,支持指定字段查询

func (*Eelastic) Search

func (e *Eelastic) Search(ctx context.Context, query *EQueryReq) (*elastic.SearchResult, error)

func (*Eelastic) SetIndexAlias

func (e *Eelastic) SetIndexAlias(ctx context.Context, index, AliasName string) (bool, error)

func (*Eelastic) UpsertAll

func (e *Eelastic) UpsertAll(ctx context.Context, index string, values map[string]interface{}) (int64, error)

values key is id

func (*Eelastic) UpsertOne

func (e *Eelastic) UpsertOne(ctx context.Context, index string, id string, value interface{}) (isok bool, err error)

type Eq

type Eq struct {
	Value interface{}
}

type Field

type Field struct {
	Action int32  `json:"action"`
	Name   string `json:"name"`
	Alise  string `json:"alise"`
	Value  Value  `json:"value"`
}

func NewQFieldAnd

func NewQFieldAnd(name string) *Field

func NewQFieldNot

func NewQFieldNot(name string) *Field

func NewQFieldOr

func NewQFieldOr(name string) *Field

func (*Field) NoCondition

func (f *Field) NoCondition() bool

func (*Field) SetEq

func (f *Field) SetEq(val interface{}) *Field

func (*Field) SetGt

func (f *Field) SetGt(val interface{}) *Field

func (*Field) SetGte

func (f *Field) SetGte(val interface{}) *Field

func (*Field) SetIn

func (f *Field) SetIn(vals []interface{}) *Field

func (*Field) SetLt

func (f *Field) SetLt(val interface{}) *Field

func (*Field) SetLte

func (f *Field) SetLte(val interface{}) *Field

type Geo

type Geo struct {
	Lat float64 `json:"lat"`
	Lon float64 `json:"lon"`
}

type Gt

type Gt struct {
	Value interface{}
}

>

type Gte

type Gte struct {
	Value interface{}
}

>=

type In

type In struct {
	Value []interface{}
}

type IndexOptions

type IndexOptions int

func (IndexOptions) Docs

func (o IndexOptions) Docs() string

func (IndexOptions) Freqs

func (o IndexOptions) Freqs() string

func (IndexOptions) Offsets

func (o IndexOptions) Offsets() string

func (IndexOptions) Positions

func (o IndexOptions) Positions() string

type Lt

type Lt struct {
	Value interface{}
}

<

type Lte

type Lte struct {
	Value interface{}
}

<=

type Mapping

type Mapping struct {
	Dynamic string         `json:"dynamic,omitempty"` //default true
	Rows    map[string]Row `json:"properties"`
}

func NewMapping

func NewMapping() *Mapping

func (*Mapping) Mappings

func (m *Mapping) Mappings() interface{}

Mappings return mappings interface{}

func (*Mapping) SetDynamic

func (m *Mapping) SetDynamic(dynamic string) *Mapping

func (*Mapping) SetRow

func (m *Mapping) SetRow(fielName string, field *Row) *Mapping

type MultiQueryReq

type MultiQueryReq struct {
	Index string       `json:"index"`
	Req   []*EQueryReq `json:"req"`
}

Mult Query

func NewMultiQueryReq

func NewMultiQueryReq(index string) *MultiQueryReq

func (*MultiQueryReq) Add

func (m *MultiQueryReq) Add(req ...*EQueryReq) *MultiQueryReq

type Query

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

func NewQuery

func NewQuery() Query

func (*Query) And

func (e *Query) And(fields ...elastic.Query) *Query

A=true and B=true

func (*Query) Not

func (e *Query) Not(fields ...elastic.Query) *Query

A!=True and B!=true

func (*Query) OR

func (e *Query) OR(fields ...elastic.Query) *Query

A=true or B=true

type QueryCondition

type QueryCondition struct {
	Index    []string `json:"index"`
	Fields   []*Field `json:"fields"`
	Sort     []Sort   `json:"sort"`
	Page     int      `json:"page"`
	PageSize int      `json:"pageSize"`
	Source   []string `json:"source"` //only return this fields,default all
}

func NewQueryCondition

func NewQueryCondition(index ...string) *QueryCondition

func (*QueryCondition) AddField

func (q *QueryCondition) AddField(field ...*Field)

func (*QueryCondition) SetPage

func (q *QueryCondition) SetPage(pageNo, pageSize int)

type Row

type Row struct {
	Type           string           `json:"type"`
	Index          *bool            `json:"index,omitempty"`           //default true,支持搜索,旧版本使用:"not_analyzed"
	Store          *bool            `json:"store,omitempty"`           //default false ,need not set
	Format         string           `json:"format,omitempty"`          //时间类型格式化
	Analyzer       string           `json:"analyzer,omitempty"`        //写入时就进行分词,最大拆分=ik_max_word,粗略拆分=ik_smart  //text使用
	SearchAnalyzer string           `json:"search_analyzer,omitempty"` //搜索阶段进行分词,会覆盖上面的属性 ,"search_analyzer": "ik_smart"  //text使用
	Rows           *map[string]Rows `json:"fields,omitempty"`          //复合 字段,用于text 的全文搜索,如 type = keyword
	DocValues      *bool            `json:"doc_values,omitempty"`      //default true ,need not set

}

func NewRow

func NewRow() *Row

db Field ,default type=text

func (*Row) CanDocValues

func (f *Row) CanDocValues(can bool) *Row

type = keyword,boolean,binary,date,number

func (*Row) CanIndex

func (f *Row) CanIndex(can bool) *Row

default true. type = text,keyward,boolean,date,geo_point,number 有默认值,可以不处理

func (*Row) CanStore

func (f *Row) CanStore(can bool) *Row

default false. type = text,keyword,binary,boolean,date,number

func (*Row) SetAnalyzer

func (f *Row) SetAnalyzer(a string) *Row

type = text ,一般 会主动选择设置此参数

func (*Row) SetFormat

func (f *Row) SetFormat(fmat string) *Row

type = data ,一般 会主动选择设置此参数

func (*Row) SetRows

func (f *Row) SetRows(t string) *Row

type = keyword,text ,选填

func (*Row) SetSearchAnalyzer

func (f *Row) SetSearchAnalyzer(s string) *Row

type = text ,一般 会主动选择设置此参数

func (*Row) SetType

func (f *Row) SetType(t string) *Row

must do it.

type Rows

type Rows struct {
	Type  string `json:"type"`
	Index bool   `json:"index,omitempty"` //默认选true,支持搜索,旧版本使用:"not_analyzed"
}

type Sort

type Sort struct {
	Name string `json:"name"`
	Desc bool   `json:"desc"` //default false
}

type Value

type Value struct {
	Vals []interface{}
	Eq   *Eq  `json:"eq,omitempty"` //Vals first one
	In   *In  `json:"in,omitempty"`
	Gt   *Gt  `json:"gt,omitempty"`  //Vals first one
	Gte  *Gte `json:"gte,omitempty"` //Vals first one
	Lt   *Lt  `json:"lt,omitempty"`  //Vals first one
	Lte  *Lte `json:"lte,omitempty"` //Vals first one
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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