Documentation
¶
Index ¶
- Variables
- type Analyzer
- type BoundingBox
- type Datastore
- func (ds *Datastore) CleanUp() error
- func (ds *Datastore) CountFiltered(filters map[string]interface{}) (uint32, error)
- func (ds *Datastore) Create(o interface{}, opts ...IndexOptFunc) error
- func (ds *Datastore) DecodeElasticResponse(source *json.RawMessage, ID string, o interface{}) error
- func (ds *Datastore) DecodeElasticResponses(qrs []QueryResult, results interface{}) error
- func (ds *Datastore) DoSearch(query elastic.Query, results interface{}, opts ...QueryOptFunc) error
- func (ds *Datastore) EnsureIndexDoesntExist() error
- func (ds *Datastore) EnsureIndexExists() error
- func (ds *Datastore) FilterByField(fieldName string, value interface{}) QueryOptFunc
- func (ds *Datastore) Find(ID string, result interface{}) error
- func (ds *Datastore) FindAll(results interface{}, opts ...QueryOptFunc) error
- func (ds *Datastore) FindByGeoBoundingBox(fieldName string, box BoundingBox, results interface{}, opts ...QueryOptFunc) error
- func (ds *Datastore) FindByGeoDistance(fieldName string, lat float64, lon float64, distance string, ...) error
- func (ds *Datastore) FindByIDs(IDs []string, result interface{}) error
- func (ds *Datastore) FindFiltered(results interface{}, mustFilters map[string]interface{}, opts ...QueryOptFunc) error
- func (ds *Datastore) FindNestedFiltered(results interface{}, path string, mustFilters map[string]string, ...) error
- func (ds *Datastore) FindNestedQuery(results interface{}, path string, nested elastic.Query, opts ...QueryOptFunc) error
- func (ds *Datastore) FindOneBy(fieldName string, value interface{}, result interface{}, opts ...QueryOptFunc) error
- func (ds *Datastore) FindQuery(results interface{}, q elastic.Query, opts ...QueryOptFunc) error
- func (ds *Datastore) Limit(limit int) QueryOptFunc
- func (ds *Datastore) Offset(offset int) QueryOptFunc
- func (ds *Datastore) Refresh() error
- func (ds *Datastore) ScriptUpdate(script string, params map[string]interface{}, filter map[string]string) error
- func (ds *Datastore) SetSorting(fieldName string, order string) QueryOptFunc
- func (ds *Datastore) Update(o interface{}) error
- func (ds *Datastore) UpdateByQueryService() *elastic.UpdateByQueryService
- type DatastoreOptFunc
- type IndexAnalysis
- type IndexDefinition
- type IndexDefinitionFunc
- type IndexOptFunc
- type IndexSettings
- type MappingConfig
- type MappingFieldConfig
- type Query
- type QueryOptFunc
- type QueryResult
- type TestSuite
- type Tokenizer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidOption is returned when a not valid option is used in a elasticorm tag to configure the mapping of a struct ErrInvalidOption = errors.New(`Invalid elasticorm option is used`) // ErrInvalidType is returned when you try to save a struct with a datastore which has been initialized for another struct ErrInvalidType = errors.New(`Invalid type for this datastore`) // ErrInvalidResultType is returned when no pointer is passed to a find method ErrInvalidResultType = errors.New(`invalid result type`) // ErrInvalidIDField is returned when the defined ID field can't be set ErrInvalidIDField = errors.New(`invalid ID field`) // ErrNotFound is returned when no record could be found ErrNotFound = errors.New(`not found`) // ErrCreationFailed is returned by the Create method, when there was no error by the elastic client, but the record could not have been created - TODO when does this happen? ErrCreationFailed = errors.New(`creation of new elasticsearch record failed`) )
Functions ¶
This section is empty.
Types ¶
type BoundingBox ¶
func NewBoundingBox ¶
func NewBoundingBox(top, right, bottom, left float64) BoundingBox
type Datastore ¶
type Datastore struct { Ctx context.Context IndexDefinition IndexDefinition // in elasticsearch // contains filtered or unexported fields }
Datstore is an instance to communicate easy with elasticsearch It is meant to be used for one struct and helps storing and retrieving it in/from elasticsearch It leverages the great elastic package from olivere
func NewDatastore ¶
func NewDatastore(esc *elastic.Client, opts ...DatastoreOptFunc) (*Datastore, error)
NewDatastore returns a fresh instance of an elasticorm datastore
func NewDatastoreForURL ¶
func NewDatastoreForURL(URL string, opts ...DatastoreOptFunc) (*Datastore, error)
func (*Datastore) CountFiltered ¶
func (*Datastore) Create ¶
func (ds *Datastore) Create(o interface{}, opts ...IndexOptFunc) error
func (*Datastore) DecodeElasticResponse ¶
func (ds *Datastore) DecodeElasticResponse(source *json.RawMessage, ID string, o interface{}) error
func (*Datastore) DecodeElasticResponses ¶
func (ds *Datastore) DecodeElasticResponses(qrs []QueryResult, results interface{}) error
func (*Datastore) DoSearch ¶
func (ds *Datastore) DoSearch(query elastic.Query, results interface{}, opts ...QueryOptFunc) error
func (*Datastore) EnsureIndexDoesntExist ¶
func (*Datastore) EnsureIndexExists ¶
EnsureIndexExists checks wether the needed index for this datastore exists. It it doesn't it gets created the name of the datastore is determined by the structs name (+ plural s)
func (*Datastore) FilterByField ¶
func (ds *Datastore) FilterByField(fieldName string, value interface{}) QueryOptFunc
func (*Datastore) FindAll ¶
func (ds *Datastore) FindAll(results interface{}, opts ...QueryOptFunc) error
func (*Datastore) FindByGeoBoundingBox ¶
func (ds *Datastore) FindByGeoBoundingBox(fieldName string, box BoundingBox, results interface{}, opts ...QueryOptFunc) error
func (*Datastore) FindByGeoDistance ¶
func (*Datastore) FindFiltered ¶
func (ds *Datastore) FindFiltered(results interface{}, mustFilters map[string]interface{}, opts ...QueryOptFunc) error
func (*Datastore) FindNestedFiltered ¶
func (*Datastore) FindNestedQuery ¶
func (*Datastore) FindOneBy ¶
func (ds *Datastore) FindOneBy(fieldName string, value interface{}, result interface{}, opts ...QueryOptFunc) error
func (*Datastore) FindQuery ¶
func (ds *Datastore) FindQuery(results interface{}, q elastic.Query, opts ...QueryOptFunc) error
func (*Datastore) Limit ¶
func (ds *Datastore) Limit(limit int) QueryOptFunc
func (*Datastore) Offset ¶
func (ds *Datastore) Offset(offset int) QueryOptFunc
func (*Datastore) ScriptUpdate ¶
func (*Datastore) SetSorting ¶
func (ds *Datastore) SetSorting(fieldName string, order string) QueryOptFunc
func (*Datastore) UpdateByQueryService ¶
func (ds *Datastore) UpdateByQueryService() *elastic.UpdateByQueryService
type DatastoreOptFunc ¶
DatastoreOptFunc is used as a parameter to NewDatastore and provides a way of configuration
func ForStruct ¶
func ForStruct(i interface{}) DatastoreOptFunc
ForStruct generates a DatastoreOptFunc It is used to generate a default mapping, type name and index name by analysing a provided struct
func WithIDField ¶
func WithIDField(name string) DatastoreOptFunc
type IndexAnalysis ¶
type IndexDefinition ¶
type IndexDefinition struct { Settings IndexSettings `json:"settings,omitempty"` Mappings map[string]MappingConfig `json:"mappings,omitempty"` }
IndexDefinition is a struct which marshals to a valid JSON configuration for creating a new elasticsearch index
func NewIndexDefinition ¶
func NewIndexDefinition(options ...IndexDefinitionFunc) (IndexDefinition, error)
NewIndexDefinition returns a new IndexDefinition which is configurable via IndexDefinitionFuncs like SetNumberOfShards
func (*IndexDefinition) AddAnalyzer ¶
func (d *IndexDefinition) AddAnalyzer(name string, a Analyzer) error
func (*IndexDefinition) AddTokenizer ¶
func (d *IndexDefinition) AddTokenizer(name string, t Tokenizer) error
type IndexDefinitionFunc ¶
type IndexDefinitionFunc func(*IndexDefinition) error
IndexDefinitionFunc is used as a parameter to set options on a new index definition (in NewIndexDefinition)
func AddMappingFromStruct ¶
func AddMappingFromStruct(name string, i interface{}) IndexDefinitionFunc
AddMappingFromStruct is a IndexDefinitionFunc which can be passed to NewIndexDefinition and sets the mapping for the new index by analysing the passed in struct. The mapping should be provide the functionality to save and retrieve structs of the same type (as passed in). The mapping definition is configurable via tags. See MappingFromStruct
func SetNumberOfReplicas ¶
func SetNumberOfReplicas(number int) IndexDefinitionFunc
SetNumberOfReplicas is a IndexDefinitionFunc which can be passed to NewIndexDefinition and sets the number_of_recplicas setting
func SetNumberOfShards ¶
func SetNumberOfShards(number int) IndexDefinitionFunc
SetNumberOfShards is a IndexDefinitionFunc which can be passed to NewIndexDefinition and sets the number_of_shards setting
type IndexOptFunc ¶
type IndexOptFunc func(*elastic.IndexService) error
IndexOptFunc accepts an elastic.IndexService to apply options on it
type IndexSettings ¶
type IndexSettings struct { NumberOfShards int `json:"number_of_shards,omitempty"` NumberOfReplicas int `json:"number_of_replicas,omitempty"` Analysis *IndexAnalysis `json:"analysis,omitempty"` }
type MappingConfig ¶
type MappingConfig struct {
Properties map[string]MappingFieldConfig `json:"properties,omitempty"`
}
MappingConfig is a struct which marshals to a valid elasticsearch mapping configuration
func MappingFromStruct ¶
func MappingFromStruct(i interface{}) (MappingConfig, error)
MappingFromStruct returns the MappingConfig for a passed in struct (pointer). The mapping is configurable via json tags, which can change the name of the field, and elasticorm tags. The elasticorm tags can include
func (*MappingConfig) AddField ¶
func (m *MappingConfig) AddField(name string, cfg MappingFieldConfig)
AddField adds a new field to the mapping
func (*MappingConfig) Analyzers ¶
func (m *MappingConfig) Analyzers() []string
type MappingFieldConfig ¶
type MappingFieldConfig struct { Type string `json:"type"` Analyzer string `json:"analyzer,omitempty"` Properties map[string]MappingFieldConfig `json:"properties,omitempty"` Fields map[string]MappingFieldConfig `json:"fields,omitempty"` Similarity string `json:"similarity,omitempty"` // contains filtered or unexported fields }
MappingFieldConfig is a struct which represents the elasticsearch mapping configuration of one field. It is used in the MappingConfig.
type Query ¶
type Query struct{}
func (Query) QueryContext ¶
QueryContext returns a boolean indicating wether the resulting query should be for query context (with a calculated score) - true - or for filtering context (hard matches) - false -
type QueryOptFunc ¶
type QueryOptFunc func(*elastic.SearchService) error
QueryOptFunc is used as a parameter
type QueryResult ¶
type QueryResult interface { ID() string Source() *json.RawMessage }
type TestSuite ¶
type TestSuite struct { Existing []interface{} Query Query Expecting []interface{} // contains filtered or unexported fields }