elasticsearch

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Overview

Package elasticsearch provides a Driver for the ElasticSerach search engine.

The elasticsearch.Client wraps both the official ElasticSearch client and the olivere/elastic search DSL. Ikuzo package should not directly use these libraries but use this wrapper client instead.

Index

Constants

View Source
const (
	PathOrgID     string = "meta.orgID"
	PathDatasetID string = "meta.spec"
	PathRevision  string = "meta.revision"
	PathTags      string = "meta.tags"
)

Variables

View Source
var (
	ErrAliasNotFound        = errors.New("alias not found")
	ErrAliasAlreadyCreated  = errors.New("alias is already created")
	ErrIndexNotFound        = errors.New("index not found")
	ErrIndexAlreadyCreated  = errors.New("index already created")
	ErrIndexMappingNotValid = errors.New("parsing error in mapping")
)
View Source
var ErrConfigMissingRequiredValue = errors.New("missing required configuration value")

Functions

This section is empty.

Types

type Alias

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

func (*Alias) Create

func (a *Alias) Create(alias, indexName string) error

Create creates an alias for the given indexName.

When the index does not exist ErrIndexNotExists is returned When the alias is already defined, ErrAliasExist is returned

func (*Alias) Delete

func (a *Alias) Delete(name, indexName string) error

Delete removes the alias from the index it is linked to.

When the alias does not it exist it will return a ErrAliasNotExist error.

When the indexName is empty it will search for the indexName using GetAlias().

func (*Alias) Get

func (a *Alias) Get(name string) (indexName string, err error)

Get returns the indexName for the given alias.

When the alias is not found an ErrAliasNotFound error is returned.

func (*Alias) Update

func (a *Alias) Update(name, indexName string) (oldIndexName string, err error)

Update removes the alias if it exists from another index and creates a new one linked to indexName.

It returns an error when the alias cannot be updated. It returns the old indexName that is removed

type Client

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

Client is a client to interact with the ElasticSearch cluster. Must be used via NewClient to have proper initialisation.

func NewClient

func NewClient(cfg *Config) (*Client, error)

func (*Client) Alias

func (c *Client) Alias() Alias

func (*Client) CreateDefaultMappings

func (c *Client) CreateDefaultMappings(orgs []domain.OrganizationConfig, withAlias, withReset bool) (indices []string, err error)

CreateDefaultMappings creates index mappings for all supplied organizations

func (*Client) GetResourceEntryStats

func (c *Client) GetResourceEntryStats(field string, r *http.Request) (*elastic.SearchResult, error)

func (*Client) Indices

func (c *Client) Indices() Indices

func (*Client) NewBulkIndexer

func (c *Client) NewBulkIndexer(orgs []domain.OrganizationConfig, workers int) (esutil.BulkIndexer, error)

func (*Client) NewOAIPMHStore

func (c *Client) NewOAIPMHStore() (*OAIPMHStore, error)

func (*Client) NewSitemapStore

func (c *Client) NewSitemapStore() *SitemapStore

func (*Client) Ping

func (c *Client) Ping() (*externalAPI.Response, error)

type Config

type Config struct {
	// urls to connect to elasticsearch cluster
	Urls []string `json:"urls"`
	// UserName is the BasicAuth username
	UserName string `json:"userName"`
	// Password is the BasicAuth password
	Password string `json:"password"`
	// Logger messages generated by the Client
	Logger *zerolog.Logger
	// Retries are maximum number of http retries
	MaxRetries int
	// Timeout is de max time in seconds before the request times out
	Timeout int
	// DisableMetrics disables publishing metrics to expvar
	DisableMetrics bool
}

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig is the default configuration. It can be used to only modify your changes such as Urls or use as basis for an external config.

Default logger is a Nop.

func (*Config) Valid

func (c *Config) Valid() error

Valid validates the configuration. When the Configuration is not valid, the Client cannot start.

type Debug

type Debug struct{}

func (Debug) SearchService

func (d Debug) SearchService(s *elastic.SearchService) ([]byte, error)

SearchService returns the search source (json send to elasticsearch) as JSON []byte

type ErrorType

type ErrorType struct {
	Index       string
	Type        string
	Reason      string
	CauseType   string
	CauseReason string
}

func GetErrorType

func GetErrorType(r io.Reader) ErrorType

func (ErrorType) Error

func (et ErrorType) Error() error

type IndexNames

type IndexNames struct{}

func (IndexNames) FragmentIndexName

func (in IndexNames) FragmentIndexName(orgID string) string

func (IndexNames) GetDigitalObjectIndexName

func (in IndexNames) GetDigitalObjectIndexName(orgID, suffix string) string

func (IndexNames) GetIndexName

func (in IndexNames) GetIndexName(orgID string) string

GetIndexName returns the lowercased indexname. This inforced correct behavior when creating an index in ElasticSearch.

func (IndexNames) GetSuggestIndexName

func (in IndexNames) GetSuggestIndexName(orgID string) string

func (IndexNames) GetV1IndexName

func (in IndexNames) GetV1IndexName(orgID string) string

type Indices

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

func (*Indices) Create

func (idx *Indices) Create(alias, mapping string, withAlias bool) (indexName string, err error)

IndexCreate creates a new index with the supplied mapping.

The internal index created from the alias and a timestamp. If 'force' is false, no index is created when the alias exists. When it does not exist a new index is created and the alias is set.

When force is true, there is no check for the alias and no alias is set for created index.

func (*Indices) Delete

func (idx *Indices) Delete(indexName string) error

Delete delete the index from ElasticSearch.

If the error does not exist an ErrIndexNotExist error is returned.

func (Indices) Exists

func (idx Indices) Exists(indexName string) error

func (*Indices) List

func (idx *Indices) List() ([]string, error)

func (*Indices) Switch

func (idx *Indices) Switch(alias, newIndexName string, deleteOldIndex bool) (oldIndexName string, err error)

Switch updates the alias with the new index, and deletes the old index.

When you only want to swith the alias use UpdateAlias().

type OAIPMHStore

type OAIPMHStore struct {
	ResponseSize int
	// contains filtered or unexported fields
}

func (*OAIPMHStore) GetRecord

func (o *OAIPMHStore) GetRecord(ctx context.Context, q *oaipmh.RequestConfig) (record oaipmh.Record, errors []oaipmh.Error, err error)

func (*OAIPMHStore) ListIdentifiers

func (o *OAIPMHStore) ListIdentifiers(ctx context.Context, q *oaipmh.RequestConfig) (res oaipmh.Resumable, err error)

func (*OAIPMHStore) ListMetadataFormats

func (o *OAIPMHStore) ListMetadataFormats(ctx context.Context, q *oaipmh.RequestConfig) (formats []oaipmh.MetadataFormat, err error)

func (*OAIPMHStore) ListRecords

func (o *OAIPMHStore) ListRecords(ctx context.Context, q *oaipmh.RequestConfig) (res oaipmh.Resumable, err error)

func (*OAIPMHStore) ListSets

func (o *OAIPMHStore) ListSets(ctx context.Context, q *oaipmh.RequestConfig) (res oaipmh.Resumable, err error)

type Proxy

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

func NewProxy

func NewProxy(es *Client) (*Proxy, error)

func (*Proxy) SafeHTTP

func (p *Proxy) SafeHTTP(w http.ResponseWriter, r *http.Request)

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Proxy) SetLogger

func (p *Proxy) SetLogger(log *zerolog.Logger)

type QueryBuilder

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

func NewQueryBuilder

func NewQueryBuilder(defaultFields ...QueryField) *QueryBuilder

func (*QueryBuilder) NewElasticQuery

func (qb *QueryBuilder) NewElasticQuery(q *search.QueryTerm) elastic.Query

type QueryField

type QueryField struct {
	Field string
	Boost float64
}

type Response

type Response = externalAPI.Response

type SitemapStore

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

func (*SitemapStore) Datasets

func (s *SitemapStore) Datasets(ctx context.Context, cfg sitemap.Config) ([]sitemap.Location, error)

func (*SitemapStore) LocationCount

func (s *SitemapStore) LocationCount(ctx context.Context, cfg sitemap.Config) (int, error)

func (*SitemapStore) Locations

func (s *SitemapStore) Locations(ctx context.Context, cfg sitemap.Config, start, end int) []sitemap.Location

Directories

Path Synopsis
Package elasticsearchtests provides docker based integration-tests for the elasticsearch driver package.
Package elasticsearchtests provides docker based integration-tests for the elasticsearch driver package.

Jump to

Keyboard shortcuts

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