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!
5 files
+ 130
12
Compare changes
  • Side-by-side
  • Inline
Files
5
+ 20
2
@@ -27,7 +27,7 @@ const (
type Client struct {
IndexName string
ProjectID string
client *elastic.Client
Client *elastic.Client
bulk *elastic.BulkProcessor
}
@@ -95,7 +95,7 @@ func NewClient(config *Config) (*Client, error) {
return &Client{
IndexName: config.IndexName,
ProjectID: config.ProjectID,
client: client,
Client: client,
bulk: bulk,
}, nil
}
@@ -119,6 +119,24 @@ func (c *Client) Index(id string, thing interface{}) {
c.bulk.Add(req)
}
// We only really use this for tests
func (c *Client) Get(id string) (*elastic.GetResult, error) {
return c.Client.Get().
Index(c.IndexName).
Type("repository").
Id(id).
Routing(c.ProjectID).
Do(context.TODO())
}
func (c *Client) GetCommit(id string) (*elastic.GetResult, error) {
return c.Get(c.ProjectID + "_" + id)
}
func (c *Client) GetBlob(path string) (*elastic.GetResult, error) {
return c.Get(c.ProjectID + "_" + path)
}
func (c *Client) Remove(id string) {
req := elastic.NewBulkDeleteRequest().
Index(c.IndexName).
Loading