Skip to content
Snippets Groups Projects
Commit f0a3b562 authored by Nick Thomas's avatar Nick Thomas
Browse files

Move CreateIndex() and DeleteIndex() out of the Indexer

parent 6d9542bd
No related branches found
No related tags found
1 merge request!1Initial implementation of an elasticsearch indexer in Go
Loading
Loading
@@ -84,29 +84,3 @@ func NewClient(config *Config) (*Client, error) {
func (c *Client) Flush() error {
return c.bulk.Flush()
}
func (c *Client) CreateIndex(indexName, mapping string) error {
createIndex, err := c.client.CreateIndex(indexName).BodyString(mapping).Do(context.Background())
if err != nil {
return err
}
if !createIndex.Acknowledged {
return timeoutError
}
return nil
}
func (c *Client) DeleteIndex(indexName string) error {
deleteIndex, err := c.client.DeleteIndex(indexName).Do(context.Background())
if err != nil {
return err
}
if !deleteIndex.Acknowledged {
return timeoutError
}
return nil
}
package indexer
package elastic
import (
"context"
)
 
var indexMapping = `
{
Loading
Loading
@@ -515,7 +519,29 @@ var indexMapping = `
}
`
 
// Creates an index matching that created by gitlab-elasticsearch-git v1.1.1
func (i *Indexer) CreateIndex() error {
return i.Submitter.CreateIndex(i.IndexName, indexMapping)
// CreateIndex creates an index matching that created by gitlab-elasticsearch-git v1.1.1
func (c *Client) CreateIndex(indexName string) error {
createIndex, err := c.client.CreateIndex(indexName).BodyString(indexMapping).Do(context.Background())
if err != nil {
return err
}
if !createIndex.Acknowledged {
return timeoutError
}
return nil
}
func (c *Client) DeleteIndex(indexName string) error {
deleteIndex, err := c.client.DeleteIndex(indexName).Do(context.Background())
if err != nil {
return err
}
if !deleteIndex.Acknowledged {
return timeoutError
}
return nil
}
Loading
Loading
@@ -10,7 +10,6 @@ import (
)
 
type Submitter interface {
CreateIndex(indexName, mapping string) error
Flush() error
}
 
Loading
Loading
Loading
Loading
@@ -10,7 +10,6 @@ import (
"github.com/stretchr/testify/assert"
 
"gitlab.com/gitlab-org/es-git-go/elastic"
"gitlab.com/gitlab-org/es-git-go/indexer"
)
 
var (
Loading
Loading
@@ -41,8 +40,7 @@ func buildIndex(t *testing.T) (string, func()) {
client, err := elastic.FromEnv()
assert.NoError(t, err)
 
indexer := indexer.Indexer{IndexName: indexName, Submitter: client}
assert.NoError(t, indexer.CreateIndex())
assert.NoError(t, client.CreateIndex(indexName))
 
return railsEnv, func() {
client.DeleteIndex(indexName)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment