Documentation ¶
Index ¶
- type BooleanQuery
- type BulkAction
- type BulkActionDetail
- type BulkActionResult
- type BulkResult
- type BulkResultItem
- type BulkShards
- type ConjunctionQuery
- type DateRangeFacet
- type DateRangeQuery
- type DateTimeRange
- type DisjunctionQuery
- type DocIDQuery
- type Document
- type DocumentMapping
- type Engine
- type FacetRequest
- type FacetResult
- type FieldMapping
- type FuzzyQuery
- type Hit
- type Hits
- type Index
- func (index *Index) BulkIndex(docs []map[string]interface{}) error
- func (index *Index) Clone(name string) error
- func (index *Index) Close() error
- func (index *Index) Delete() error
- func (index *Index) DeleteDocument(docID string) error
- func (index *Index) GetDocument(docID string) (*Document, error)
- func (index *Index) IndexOrUpdateDocument(docID string, source map[string]interface{}) error
- func (index *Index) Open() error
- func (index *Index) Search(req *SearchRequest) (*SearchResult, error)
- func (index *Index) SetMapping(mapping interface{}) error
- func (index *Index) UpdateDocumentPartially(docID string, fields map[string]interface{}) error
- func (index *Index) UpdateMetadata() error
- func (index *Index) UpdateMetadataByShard(n int)
- type IndexMapping
- type IndexShard
- type MatchAllQuery
- type MatchNoneQuery
- type MatchPhraseQuery
- type MatchQuery
- type NumericRange
- type NumericRangeFacet
- type NumericRangeQuery
- type Option
- type PhraseQuery
- type QueryStringQuery
- type SearchRequest
- type SearchResult
- type Status
- type TermFacet
- type TermQuery
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BooleanQuery ¶ added in v0.0.6
type BooleanQuery struct { Must query.Query `json:"must,omitempty"` Should query.Query `json:"should,omitempty"` MustNot query.Query `json:"must_not,omitempty"` BoostVal float64 `json:"boost,omitempty"` }
func (*BooleanQuery) Searcher ¶ added in v0.0.6
func (b *BooleanQuery) Searcher(i bindex.IndexReader, m imapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error)
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 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 ¶
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 ConjunctionQuery ¶ added in v0.0.6
type ConjunctionQuery struct { Conjuncts []query.Query `json:"conjuncts"` BoostVal float64 `json:"boost,omitempty"` }
func (*ConjunctionQuery) Searcher ¶ added in v0.0.6
func (c *ConjunctionQuery) Searcher(i bindex.IndexReader, m imapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error)
type DateRangeFacet ¶
type DateRangeQuery ¶ added in v0.0.6
type DateRangeQuery struct { Start time.Time `json:"start,omitempty"` End time.Time `json:"end,omitempty"` InclusiveStart *bool `json:"inclusive_start,omitempty"` InclusiveEnd *bool `json:"inclusive_end,omitempty"` FieldVal string `json:"field,omitempty"` BoostVal float64 `json:"boost,omitempty"` }
func (*DateRangeQuery) Searcher ¶ added in v0.0.6
func (d *DateRangeQuery) Searcher(i bindex.IndexReader, m imapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error)
type DateTimeRange ¶
type DisjunctionQuery ¶ added in v0.0.6
type DisjunctionQuery struct { Disjuncts []query.Query `json:"disjuncts"` BoostVal float64 `json:"boost,omitempty"` Min float64 `json:"min"` }
func (*DisjunctionQuery) Searcher ¶ added in v0.0.6
func (d *DisjunctionQuery) Searcher(i bindex.IndexReader, m imapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error)
type DocIDQuery ¶ added in v0.0.6
func (*DocIDQuery) Searcher ¶ added in v0.0.6
func (d *DocIDQuery) Searcher(i bindex.IndexReader, m imapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error)
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 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 FuzzyQuery ¶ added in v0.0.6
type FuzzyQuery struct { Term string `json:"term"` Prefix int `json:"prefix_length"` Fuzziness int `json:"fuzziness"` FieldVal string `json:"field,omitempty"` BoostVal float64 `json:"boost,omitempty"` }
func (*FuzzyQuery) Searcher ¶ added in v0.0.6
func (f *FuzzyQuery) Searcher(i bindex.IndexReader, m imapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error)
type Hit ¶
type Hit struct { Index string `json:"_index"` ID string `json:"_id"` Score f64 `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 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 ¶
GetIndex firstly search in mem, than find in db, in err == nil and index != nil, it's ready to use(opened).
func ListIndices ¶
ListIndices list all managed indices, note: not opened!
func (*Index) Close ¶
Close closes index and release the related resource, including remove from engine.indices.
func (*Index) Delete ¶
Delete close the index, remove from engine.indices, delete all index files, delete index metadata.
func (*Index) DeleteDocument ¶
DeleteDocument try to delete the document from index, do not check if it exists.
func (*Index) GetDocument ¶
GetDocument returns the doc associated with docID.
func (*Index) IndexOrUpdateDocument ¶
IndexOrUpdateDocument indexes or update a document refers to `index`.
func (*Index) Search ¶
func (index *Index) Search(req *SearchRequest) (*SearchResult, error)
Search performs search in specified index.
func (*Index) SetMapping ¶
func (*Index) UpdateDocumentPartially ¶
UpdateDocumentPartially can update part fields of indexed document.
func (*Index) UpdateMetadata ¶
UpdateMetadata writes the index metadata to db.
func (*Index) UpdateMetadataByShard ¶
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 }
func BuildIndexMappingFromMap ¶
func BuildIndexMappingFromMap(m map[string]interface{}) (*IndexMapping, error)
type IndexShard ¶
type MatchAllQuery ¶ added in v0.0.6
type MatchAllQuery struct {
BoostVal float64 `json:"boost,omitempty"`
}
func (*MatchAllQuery) Searcher ¶ added in v0.0.6
func (mq *MatchAllQuery) Searcher(i bindex.IndexReader, m imapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error)
type MatchNoneQuery ¶ added in v0.0.6
type MatchNoneQuery struct {
BoostVal float64 `json:"boost,omitempty"`
}
func (*MatchNoneQuery) Searcher ¶ added in v0.0.6
func (mq *MatchNoneQuery) Searcher(i bindex.IndexReader, m imapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error)
type MatchPhraseQuery ¶ added in v0.0.6
type MatchPhraseQuery struct { MatchPhrase string `json:"match_phrase"` FieldVal string `json:"field,omitempty"` Analyzer string `json:"analyzer,omitempty"` BoostVal float64 `json:"boost,omitempty"` }
func (*MatchPhraseQuery) Searcher ¶ added in v0.0.6
func (mp *MatchPhraseQuery) Searcher(i bindex.IndexReader, m imapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error)
type MatchQuery ¶ added in v0.0.6
type MatchQuery struct { Match string `json:"match"` FieldVal string `json:"field,omitempty"` Analyzer string `json:"analyzer,omitempty"` BoostVal float64 `json:"boost,omitempty"` Prefix int `json:"prefix_length"` Fuzziness int `json:"fuzziness"` Operator string `json:"operator,omitempty"` }
func (*MatchQuery) Searcher ¶ added in v0.0.6
func (mq *MatchQuery) Searcher(i bindex.IndexReader, m imapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error)
type NumericRange ¶
type NumericRangeFacet ¶
type NumericRangeQuery ¶ added in v0.0.6
type NumericRangeQuery struct { Min *float64 `json:"min,omitempty"` Max *float64 `json:"max,omitempty"` InclusiveMin *bool `json:"inclusive_min,omitempty"` InclusiveMax *bool `json:"inclusive_max,omitempty"` FieldVal string `json:"field,omitempty"` BoostVal float64 `json:"boost,omitempty"` }
func (*NumericRangeQuery) Searcher ¶ added in v0.0.6
func (n *NumericRangeQuery) Searcher(i bindex.IndexReader, m imapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error)
type Option ¶
type Option func(*options)
func WithIndexMapping ¶
func WithIndexMapping(m *IndexMapping) Option
func WithShards ¶
type PhraseQuery ¶ added in v0.0.6
type PhraseQuery struct { Terms []string `json:"terms"` Field string `json:"field,omitempty"` BoostVal float64 `json:"boost,omitempty"` }
func (*PhraseQuery) Searcher ¶ added in v0.0.6
func (p *PhraseQuery) Searcher(i bindex.IndexReader, m imapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error)
type QueryStringQuery ¶
func (*QueryStringQuery) Searcher ¶
func (q *QueryStringQuery) Searcher(i bindex.IndexReader, m imapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error)
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 ¶
func Search(req *SearchRequest) (*SearchResult, error)
Search performs search in all existing indices.
type TermQuery ¶ added in v0.0.6
type TermQuery struct { Term string `json:"term"` FieldVal string `json:"field,omitempty"` BoostVal float64 `json:"boost,omitempty"` }
func (*TermQuery) Searcher ¶ added in v0.0.6
func (t *TermQuery) Searcher(i bindex.IndexReader, m imapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error)