elasticsearch

package
v0.0.0-...-f39a356 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: GPL-2.0, GPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IndexNameProcessor = func(s string) string {
	return s
}
View Source
var UpdateConflictRetries = 10

Functions

func AddToIndex

func AddToIndex(c ElasticConnector, index string, source interface{}) (err error)

AddToIndex adds source to a search index. Source must have a field `Id *datastore.key`.

func Clear

func Clear(c ElasticConnector, toDelete ...string) (err error)

Clear will delete things. If toDelete is empty, EVERYTHING will be deleted. If toDelete has one element, that index will be deleted. If toDelete has two elements, that index and doc type will be deleted.

func CreateDynamicMapping

func CreateDynamicMapping(c ElasticConnector) (err error)

CreateDynamicMapping will create a sane default dynamic mapping where all string type fields are indexed twice, once analyzed under their proper name, and once non-analyzed under [name].na

func CreateIndex

func CreateIndex(c ElasticConnector, name string, def IndexDef) (err error)

func CreateIndexTemplate

func CreateIndexTemplate(c ElasticConnector, name string, def IndexDef) (err error)

func RemoveFromIndex

func RemoveFromIndex(c ElasticConnector, index string, source interface{}) (err error)

func SearchAndCopy

func SearchAndCopy(c ElasticSearchContext, query *SearchRequest, index string, result interface{}) (err error)

func UpdateDoc

func UpdateDoc(c ElasticConnector, index string, id key.Key, groovyCode string, params map[string]interface{}) (err error)

Types

type AggRequest

type AggRequest struct {
	ValueCount  *ValueCountAggRequest  `json:"value_count,omitempty"`
	Cardinality *CardinalityAggRequest `json:"cardinality,omitempty"`
	Terms       *TermsAggRequest       `json:"terms,omitempty"`
	Aggs        map[string]AggRequest  `json:"aggs,omitempty"`
	Filter      *Filter                `json:"filter,omitempty"`
}

type AggregationResult

type AggregationResult struct {
	Value     int                        `json:"value,omitempty"`
	DocCount  int                        `json:"doc_count,omitempty"`
	TermCount AggregationTermCountResult `json:"termcount,omitempty"`
}

type AggregationTermCountBucket

type AggregationTermCountBucket struct {
	DocCount int    `json:"doc_count"`
	Key      string `json:"key"`
}

type AggregationTermCountResult

type AggregationTermCountResult struct {
	Buckets []AggregationTermCountBucket `json:"buckets"`
}

type Analyzer

type Analyzer struct {
	Tokenizer string   `json:"tokenizer"`
	Filter    []string `json:"filter"`
}

type Analyzers

type Analyzers struct {
	Analyzers map[string]Analyzer `json:"analyzer,omitempty"`
}

type BoolFilter

type BoolFilter struct {
	Must    []Filter `json:"must,omitempty"`
	MustNot []Filter `json:"must_not,omitempty"`
	Should  []Filter `json:"should,omitempty"`
}

type BoolQuery

type BoolQuery struct {
	Must               []Query `json:"must,omitempty"`
	MustNot            []Query `json:"must_not,omitempty"`
	Should             []Query `json:"should,omitempty"`
	MinimumShouldMatch int     `json:"minimum_should_match,omitempty"`
	Boost              float64 `json:"boost,omitempty"`
}

type CardinalityAggRequest

type CardinalityAggRequest struct {
	Field string `json:"field"`
}

type DynamicTemplate

type DynamicTemplate struct {
	Match            string      `json:"match"`
	MatchMappingType string      `json:"match_mapping_type"`
	Mapping          *Properties `json:"mapping,omitempty"`
}

type ElasticConnector

type ElasticConnector interface {
	Client() *http.Client
	GetElasticService() string
	GetElasticUsername() string
	GetElasticPassword() string
}

type ElasticDoc

type ElasticDoc struct {
	Index  string                      `json:"_index"`
	Type   string                      `json:"_type"`
	Id     string                      `json:"_id"`
	Score  float64                     `json:"_score"`
	Source map[string]*json.RawMessage `json:"_source"`
}

type ElasticSearchContext

type ElasticSearchContext interface {
	ElasticConnector
	Debugf(format string, args ...interface{})
}

type FacetRequest

type FacetRequest struct {
	Terms *TermsFacetRequest `json:"terms,omitempty"`
}

type FacetResponse

type FacetResponse struct {
	Type    string              `json:"_type"`
	Missing int                 `json:"missing"`
	Total   int                 `json:"total"`
	Other   int                 `json:"other"`
	Terms   []TermFacetResponse `json:"terms"`
}

type Filter

type Filter struct {
	Or      []Query                `json:"or,omitempty"`
	Query   *Query                 `json:"query,omitempty"`
	Bool    *BoolFilter            `json:"bool,omitempty"`
	Term    map[string]interface{} `json:"term,omitempty"`
	Range   map[string]RangeDef    `json:"range,omitempty"`
	Missing *MissingFilter         `json:"missing,omitempty"`
}

type FilteredQuery

type FilteredQuery struct {
	Query  *Query  `json:"query"`
	Filter *Filter `json:"filter"`
}

type Hits

type Hits struct {
	Total    int          `json:"total"`
	MaxScore float64      `json:"max_score"`
	Hits     []ElasticDoc `json:"hits"`
}

type IndexDef

type IndexDef struct {
	Settings Settings           `json:"settings,omitempty"`
	Mappings map[string]Mapping `json:"mappings,omitempty"`
	Template string             `json:"template,omitempty"`
}

type IndexOption

type IndexOption string
const (
	AnalyzedIndex    IndexOption = "analyzed"
	NotAnalyzedIndex IndexOption = "not_analyzed"
	NoIndex          IndexOption = "no"
)

type Mapping

type Mapping struct {
	DynamicTemplates []map[string]DynamicTemplate `json:"dynamic_templates,omitempty"`
	Properties       map[string]Properties        `json:"properties,omitempty"`
}

type MatchAllQuery

type MatchAllQuery struct {
	Boost float64 `json:"boost,omitempty"`
}

type MissingFilter

type MissingFilter struct {
	Field string `json:"field"`
}

type PageableItems

type PageableItems struct {
	Items   []interface{} `json:"items"`
	Total   int           `json:"total"`
	Page    int           `json:"page"`
	PerPage int           `json:"per_page"`
}

type Properties

type Properties struct {
	Type     string                `json:"type"`
	Index    IndexOption           `json:"index,omitempty"`
	Store    bool                  `json:"store"`
	Fields   map[string]Properties `json:"fields,omitempty"`
	Analyzer string                `json:"analyzer,omitempty"`
}

type Query

type Query struct {
	String       *StringQuery           `json:"query_string,omitempty"`
	SimpleString *SimpleStringQuery     `json:"simple_query_string,omitempty"`
	Term         map[string]string      `json:"term,omitempty"`
	Range        map[string]RangeDef    `json:"range,omitempty"`
	Bool         *BoolQuery             `json:"bool,omitempty"`
	Filtered     *FilteredQuery         `json:"filtered,omitempty"`
	MatchAll     *MatchAllQuery         `json:"match_all,omitempty"`
	Ids          map[string]interface{} `json:"ids,omitempty"`
}

type RangeDef

type RangeDef struct {
	Gt    string `json:"gt,omitempty"`
	Gte   string `json:"gte,omitempty"`
	Lt    string `json:"lt,omitempty"`
	Lte   string `json:"lte,omitempty"`
	Boost string `json:"boost,omitempty"`
}

type SearchRequest

type SearchRequest struct {
	Query  *Query                  `json:"query,omitempty"`
	From   int                     `json:"from,omitempty"`
	Size   int                     `json:"size,omitempty"`
	Sort   []map[string]Sort       `json:"sort,omitempty"`
	Facets map[string]FacetRequest `json:"facets,omitempty"`
	Aggs   map[string]AggRequest   `json:"aggs,omitempty"`
}

type SearchResponse

type SearchResponse struct {
	Took         float64                      `json:"took"`
	Hits         Hits                         `json:"hits"`
	Facets       map[string]FacetResponse     `json:"facets,omitempty"`
	Page         int                          `json:"page"`
	PerPage      int                          `json:"per_page"`
	Aggregations map[string]AggregationResult `json:"aggregations,omitempty"`
}
func Search(c ElasticSearchContext, query *SearchRequest, index, typ string) (result *SearchResponse, err error)

func (*SearchResponse) Copy

func (self *SearchResponse) Copy(result interface{}) (err error)

type Settings

type Settings struct {
	Analysis Analyzers `json:"analysis,omitempty"`
}

type SimpleStringQuery

type SimpleStringQuery StringQuery

type Sort

type Sort struct {
	Order          string `json:"order"`
	Missing        string `json:"missing,omitempty"`
	IgnoreUnmapped bool   `json:"ignore_unmapped"`
}

type Sources

type Sources []map[string]*json.RawMessage

type StringQuery

type StringQuery struct {
	Query           string `json:"query"`
	AnalyzeWildcard bool   `json:"analyze_wildcard"`
	DefaultField    string `json:"default_field"`
}

type TermFacetResponse

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

type TermsAggRequest

type TermsAggRequest struct {
	Field string `json:"field"`
}

type TermsFacetRequest

type TermsFacetRequest struct {
	Field string `json:"field"`
	Size  int    `json:"size"`
}

type UpdateRequest

type UpdateRequest struct {
	Script string                 `json:"script"`
	Params map[string]interface{} `json:"params"`
}

type ValueCountAggRequest

type ValueCountAggRequest struct {
	Field string `json:"field"`
}

Jump to

Keyboard shortcuts

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