Skip to content
Snippets Groups Projects

Initial implementation of an elasticsearch indexer in Go

Merged Nick Thomas requested to merge 1-initial-implementation into master
All threads resolved!
8 files
+ 93
51
Compare changes
  • Side-by-side
  • Inline
Files
8
+ 44
11
@@ -22,13 +22,15 @@ var (
)
type Client struct {
client *elastic.Client
bulk *elastic.BulkProcessor
IndexName string
ProjectID string
client *elastic.Client
bulk *elastic.BulkProcessor
}
// FromEnv creates an Elasticsearch client from the `ELASTIC_CONNECTION_INFO`
// environment variable
func FromEnv() (*Client, error) {
func FromEnv(projectID string) (*Client, error) {
data := strings.NewReader(os.Getenv("ELASTIC_CONNECTION_INFO"))
config, err := ReadConfig(data)
@@ -36,6 +38,15 @@ func FromEnv() (*Client, error) {
return nil, fmt.Errorf("Couldn't parse ELASTIC_CONNECTION_INFO: %s", err)
}
railsEnv := os.Getenv("RAILS_ENV")
indexName := "gitlab"
if railsEnv != "" {
indexName = indexName + "-" + railsEnv
}
config.IndexName = indexName
config.ProjectID = projectID
return NewClient(config)
}
@@ -78,21 +89,43 @@ func NewClient(config *Config) (*Client, error) {
return nil, err
}
return &Client{client: client, bulk: bulk}, nil
return &Client{
IndexName: config.IndexName,
ProjectID: config.ProjectID,
client: client,
bulk: bulk,
}, nil
}
func (c *Client) ParentID() string {
return c.ProjectID
}
func (c *Client) Flush() error {
return c.bulk.Flush()
}
func (c *Client) IndexCommit(indexName string, commit interface{}) error {
return fmt.Errorf("TODO")
}
func (c *Client) Index(id string, thing interface{}) error {
req := elastic.NewBulkIndexRequest().
Index(c.IndexName).
Type("repository").
Parent(c.ProjectID).
Id(id).
Doc(thing)
c.bulk.Add(req)
func (c *Client) IndexBlob(indexName string, blob interface{}) error {
return fmt.Errorf("TODO")
return nil
}
func (c *Client) RemoveBlob(indexName string, blob interface{}) error {
return fmt.Errorf("TODO")
func (c *Client) Remove(id string) error {
req := elastic.NewBulkDeleteRequest().
Index(c.IndexName).
Type("repository").
Parent(c.ProjectID).
Id(id)
c.bulk.Add(req)
return nil
}
Loading