nwelastic

package
v0.8.25 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailedToPingElastic = errors.New("failed to ping elastic cluster")
)

Functions

This section is empty.

Types

type Elastic

type Elastic struct {
	Config ElasticConfig
	// contains filtered or unexported fields
}

func NewElastic

func NewElastic(config ElasticConfig) Elastic

func (*Elastic) Get

func (e *Elastic) Get(index string, documentId string) *get.Get

func (*Elastic) Search

func (e *Elastic) Search() *search.Search

func (*Elastic) StartClient

func (e *Elastic) StartClient() (err error)

func (*Elastic) StartTypedClient

func (e *Elastic) StartTypedClient() (err error)

type ElasticConfig

type ElasticConfig struct {
	Addresses   []string
	Username    string
	Password    string
	NewsIndex   string `yaml:"newsIndex"`
	LogRequests bool   `yaml:"logRequests"`
}

type News

type News struct {
	Id              string    `json:"id,omitempty"`
	Headline        string    `json:"headline"`
	Body            string    `json:"body,omitempty"`
	Tickers         []string  `json:"tickers,omitempty"`
	Source          string    `json:"source"`
	PublicationTime time.Time `json:"publicationTime"`
	ReceivedTime    time.Time `json:"receivedTime"`
	CreationTime    time.Time `json:"creationTime"` // Override by insert function
	// CategoryCodes represents a code which varies from provider to provider and represents a specific topic such as
	// acquisitions, mergers, etc.
	CategoryCodes []string `json:"categoryCodes"`

	// Ciks only applies to SEC
	Ciks []int `json:"ciks,omitempty"`
	// Link only applies to SEC
	Link string `json:"link,omitempty"`
}

News describes a document that can be inserted to ElasticSearch. Each field is commented with the sources it applies to.

func (*News) UnmarshalJSON added in v0.8.15

func (n *News) UnmarshalJSON(data []byte) error

type NewsRepository

type NewsRepository struct {
	Index string // Defaults to "news"
	// contains filtered or unexported fields
}

func NewNewsRepository

func NewNewsRepository(elastic Elastic, sequenceIndex ...string) (NewsRepository, error)

NewNewsRepository creates a NewsRepository, if the context is a test, an index other than "news" must be passed otherwise it will fail.

func (NewsRepository) Insert

func (b NewsRepository) Insert(news *News) error

func (NewsRepository) InsertBatch

func (b NewsRepository) InsertBatch(news []*News, insertedCallback func(totalIndexed int, lastIndex int)) error

InsertBatch inserts a batch of news, if the batch is too big, it is uploaded in sub-batches. news must be ordered from [oldest... newest]. The insertedCallback is called after a sub-batch is inserted it sends as arguments the total amount of news in the sub-batch and the batch index of the last item in the sub-batch.

type Repository

type Repository interface {
	InsertNews(News) error
}

type Sequence

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

Sequence helps retrieve unique and sequential ids from ElasticSearch using the method: https://blogs.perl.org/users/clinton_gormley/2011/10/elasticsearchsequence---a-blazing-fast-ticket-server.html

func NewSequence

func NewSequence(elastic Elastic, index string, sequenceIndex ...string) (Sequence, error)

NewSequence creates a Sequence. The index argument is the index for which a sequence will be generated.

func (*Sequence) GenerateUniqueIds

func (s *Sequence) GenerateUniqueIds(amount int) ([]int64, error)

GenerateUniqueIds requests unique ids to Sequence.sequenceIndex, the ids are generated for s.index

func (*Sequence) GetLastId

func (s *Sequence) GetLastId() (int64, error)

Jump to

Keyboard shortcuts

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