core

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BulkAction

type BulkAction struct {
	Index  *BulkActionDetail `json:"index,omitempty"`
	Create *BulkActionDetail `json:"create,omitempty"`
	Update *BulkActionDetail `json:"update,omitempty"`
	Delete *BulkActionDetail `json:"delete,omitempty"`
}

type BulkActionDetail

type BulkActionDetail struct {
	Index string `json:"_index"`
	ID    string `json:"_id"`
}

type BulkActionResult

type BulkActionResult struct {
	Index       string      `json:"_index"`
	ID          string      `json:"_id"`
	Version     int64       `json:"_version"`
	Result      string      `json:"result,omitempty"` // 'created', 'deleted', 'indexed', 'updated'
	Shards      *BulkShards `json:"_shards"`
	Status      int64       `json:"status"` // 200 => indexed, updated, deleted	201 => created	404 => doc not found
	Error       interface{} `json:"error,omitempty"`
	SeqNo       int64       `json:"_seq_no"`
	PrimaryTerm int64       `json:"_primary_term"`
}

func NewBulkActionResult

func NewBulkActionResult(index string, docID string, result string, status int64, err interface{}, seqNo int64) *BulkActionResult

type BulkResult

type BulkResult struct {
	Took   time.Duration    `json:"took"`
	Errors bool             `json:"errors,omitempty"`
	Items  []BulkResultItem `json:"items"`
}

func Bulk

func Bulk(targetIndex string, reader io.Reader) (*BulkResult, error)

Bulk reads data from reader and execute bulk actions defined in reader. The first line looks like {"$action":{"_index": "$index", "_id": "$docID"}}, the $action can be `create`, `delete`, `index`, `update`. Note that here's update don't support update document partially because of performance. If $index is empty, the targetIndex will be used.

type BulkResultItem

type BulkResultItem struct {
	Index  *BulkActionResult `json:"index,omitempty"`
	Delete *BulkActionResult `json:"delete,omitempty"`
	Create *BulkActionResult `json:"create,omitempty"`
	Update *BulkActionResult `json:"update,omitempty"`
}

type BulkShards

type BulkShards struct {
	Total      int64 `json:"total"`
	Successful int64 `json:"successful"`
	Failed     int64 `json:"failed"`
}

type DateRangeFacet

type DateRangeFacet struct {
	Name  string  `json:"name"`
	Start *string `json:"start,omitempty"`
	End   *string `json:"end,omitempty"`
	Count int     `json:"count"`
}

type DateTimeRange

type DateTimeRange struct {
	Name  string    `json:"name,omitempty"`
	Start time.Time `json:"start,omitempty"`
	End   time.Time `json:"end,omitempty"`
}

type Document

type Document struct {
	Index       string      `json:"_index"`
	ID          string      `json:"_id"`
	Version     int64       `json:"_version"`
	SeqNo       int64       `json:"_seq_no"`
	PrimaryTerm int64       `json:"_primary_term"`
	Found       bool        `json:"found"`
	Source      interface{} `json:"_source"`
}

type DocumentMapping

type DocumentMapping struct {
	Disabled        bool                        `json:"disabled" mapstructure:"disabled"`
	Properties      map[string]*DocumentMapping `json:"properties,omitempty" mapstructure:"properties"`
	Fields          []*FieldMapping             `json:"fields,omitempty" mapstructure:"fields"`
	DefaultAnalyzer string                      `json:"default_analyzer,omitempty" mapstructure:"default_analyzer"`
}

type Engine

type Engine struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine() *Engine

func (*Engine) Run

func (e *Engine) Run() error

func (*Engine) Stop

func (e *Engine) Stop() error

type FacetRequest

type FacetRequest struct {
	Size           int             `json:"size"`
	Field          string          `json:"field"`
	NumericRanges  []NumericRange  `json:"numeric_ranges,omitempty"`
	DateTimeRanges []DateTimeRange `json:"date_ranges,omitempty"`
}

type FacetResult

type FacetResult struct {
	Field         string              `json:"field"`
	Total         int                 `json:"total"`
	Missing       int                 `json:"missing"`
	Other         int                 `json:"other"`
	DateRanges    []DateRangeFacet    `json:"date_ranges,omitempty"`
	NumericRanges []NumericRangeFacet `json:"numeric_ranges,omitempty"`
	Terms         []TermFacet         `json:"terms,omitempty"`
}

type FieldMapping

type FieldMapping struct {
	Type     string  `json:"type,omitempty" mapstructure:"type"`         // support "keyword", "text", "datetime", "number", "boolean", "geopoint", "IP"
	Analyzer *string `json:"analyzer,omitempty" mapstructure:"analyzer"` // Analyzer specifies the name of the analyzer to use for this field.
	Store    *bool   `json:"store,omitempty" mapstructure:"store"`       // Store indicates whether to store field values in the index.
	Index    *bool   `json:"index,omitempty" mapstructure:"index"`       // Store indicates whether to analyze the field.
}

type Hit

type Hit struct {
	Index       string                      `json:"_index"`
	ID          string                      `json:"_id"`
	Score       float64                     `json:"_score"`
	Sort        []string                    `json:"_sort"`
	Timestamp   string                      `json:"@timestamp"`
	Explanation *search.Explanation         `json:"_explanation,omitempty"`
	Locations   search.FieldTermLocationMap `json:"_locations,omitempty"`
	Fragments   search.FieldFragmentMap     `json:"_fragments,omitempty"`
	Source      map[string]interface{}      `json:"_source,omitempty"`
	Fields      map[string]interface{}      `json:"_fields,omitempty"`
}

type Hits

type Hits []*Hit

func (Hits) Len

func (h Hits) Len() int

func (Hits) Less

func (h Hits) Less(i, j int) bool

func (Hits) Swap

func (h Hits) Swap(i, j int)

type Index

type Index struct {
	UID            string        `json:"uid"`
	Name           string        `json:"name"`
	Mapping        *IndexMapping `json:"mapping"`
	DocNum         uint64        `json:"doc_num"`          // number of docs
	StorageSize    uint64        `json:"storage_size"`     // bytes on disk
	NumberOfShards int           `json:"number_of_shards"` // number of shards
	Shards         []*IndexShard `json:"shards"`
	CreateAt       time.Time     `json:"create_at"`
	UpdateAt       time.Time     `json:"update_at"`
	// contains filtered or unexported fields
}

func GetIndex

func GetIndex(name string) (*Index, error)

GetIndex firstly search in mem, than find in db, in err == nil and index != nil, it's ready to use(opened).

func ListIndices

func ListIndices() ([]*Index, error)

ListIndices list all managed indices, note: not opened!

func NewIndex

func NewIndex(opts ...Option) (*Index, error)

NewIndex return an Index, which is opened and appended to engine.indices.

func (*Index) BulkIndex

func (index *Index) BulkIndex(docs []map[string]interface{}) error

BulkIndex bulk index(update if exists) docs into index.

func (*Index) Clone

func (index *Index) Clone(name string) error

Clone clones the entire index to a new index.

func (*Index) Close

func (index *Index) Close() error

Close closes index and release the related resource, including remove from engine.indices.

func (*Index) Delete

func (index *Index) Delete() error

Delete close the index, remove from engine.indices, delete all index files, delete index metadata.

func (*Index) DeleteDocument

func (index *Index) DeleteDocument(docID string) error

DeleteDocument try to delete the document from index, do not check if it exists.

func (*Index) GetDocument

func (index *Index) GetDocument(docID string) (*Document, error)

GetDocument returns the doc associated with docID.

func (*Index) IndexOrUpdateDocument

func (index *Index) IndexOrUpdateDocument(docID string, source map[string]interface{}) error

IndexOrUpdateDocument indexes or update a document refers to `index`.

func (*Index) Open

func (index *Index) Open() error

Open open the index, append it to the engine.indices.

func (*Index) Search

func (index *Index) Search(req *SearchRequest) (*SearchResult, error)

Search performs search in specified index.

func (*Index) SetMapping

func (index *Index) SetMapping(mapping interface{}) error

func (*Index) UpdateDocumentPartially

func (index *Index) UpdateDocumentPartially(docID string, fields map[string]interface{}) error

UpdateDocumentPartially can update part fields of indexed document.

func (*Index) UpdateMetadata

func (index *Index) UpdateMetadata() error

UpdateMetadata writes the index metadata to db.

func (*Index) UpdateMetadataByShard

func (index *Index) UpdateMetadataByShard(n int)

type IndexMapping

type IndexMapping struct {
	TypeMapping     map[string]*DocumentMapping `json:"types,omitempty" mapstructure:"types"`
	DefaultMapping  *DocumentMapping            `json:"default_mapping" mapstructure:"default_mapping"`
	TypeField       *string                     `json:"type_field" mapstructure:"type_field"`
	DefaultType     *string                     `json:"default_type" mapstructure:"default_type"`
	DefaultAnalyzer *string                     `json:"default_analyzer" mapstructure:"default_analyzer"` // standard, gse, sego ...
}

func BuildIndexMappingFromMap

func BuildIndexMappingFromMap(m map[string]interface{}) (*IndexMapping, error)

type IndexShard

type IndexShard struct {
	ID          int         `json:"id"`           // shard's id
	DocNum      uint64      `json:"doc_num"`      // doc's number in shard
	StorageSize uint64      `json:"storage_size"` // shard file size
	Indexer     bleve.Index `json:"-"`            // a shard map to a bleve index
}

type NumericRange

type NumericRange struct {
	Name string  `json:"name,omitempty"`
	Min  float64 `json:"min,omitempty"`
	Max  float64 `json:"max,omitempty"`
}

type NumericRangeFacet

type NumericRangeFacet struct {
	Name  string   `json:"name"`
	Min   *float64 `json:"min"`
	Max   *float64 `json:"max"`
	Count int      `json:"count"`
}

type Option

type Option func(*options)

func WithIndexMapping

func WithIndexMapping(m *IndexMapping) Option

func WithName

func WithName(name string) Option

func WithShards

func WithShards(num int) Option

type QueryStringQuery

type QueryStringQuery struct {
	Query string  `json:"query"`
	Boost float64 `json:"boost"`
}

func (*QueryStringQuery) Searcher

type SearchRequest

type SearchRequest struct {
	Query            query.Query              `json:"query"`
	Size             int                      `json:"size"`
	From             int                      `json:"from"`
	Highlight        []string                 `json:"highlight"`
	Fields           []string                 `json:"fields"`
	Facets           map[string]*FacetRequest `json:"facets"`
	Explain          bool                     `json:"explain"`
	Sort             []string                 `json:"sort"`
	IncludeLocations bool                     `json:"includeLocations"`
	SearchAfter      []string                 `json:"search_after"`
	SearchBefore     []string                 `json:"search_before"`
}

func (*SearchRequest) UnmarshalJSON

func (r *SearchRequest) UnmarshalJSON(input []byte) error

type SearchResult

type SearchResult struct {
	Status    Status                  `json:"status"`
	Request   *SearchRequest          `json:"request"`
	Hits      Hits                    `json:"hits"`
	TotalHits uint64                  `json:"total_hits"`
	MaxScore  float64                 `json:"max_score"`
	Took      time.Duration           `json:"took"`
	Facets    map[string]*FacetResult `json:"facets,omitempty"`
}
func Search(req *SearchRequest) (*SearchResult, error)

Search performs search in all existing indices.

type Status

type Status struct {
	Total      int `json:"total"`
	Failed     int `json:"failed"`
	Successful int `json:"successful"`
}

type TermFacet

type TermFacet struct {
	Term  string `json:"term"`
	Count int    `json:"count"`
}

Jump to

Keyboard shortcuts

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