@@ -19,7 +19,7 @@ var ( | |||
ES_PORT = "9200" | |||
) | |||
func getConnection() (conn *goes.Connection) { | |||
func getConnection() (conn *goes.Client) { | |||
h := os.Getenv("TEST_ELASTICSEARCH_HOST") | |||
if h == "" { | |||
h = ES_HOST | |||
@@ -30,7 +30,7 @@ func getConnection() (conn *goes.Connection) { | |||
p = ES_PORT | |||
} | |||
conn = goes.NewConnection(h, p) | |||
conn = goes.NewClient(h, p) | |||
return | |||
} | |||
@@ -177,7 +177,7 @@ func ExampleConnectionOverrideHttpClient() { | |||
Transport: tr, | |||
} | |||
conn := getConnection() | |||
conn.WithClient(cl) | |||
conn.WithHTTPClient(cl) | |||
fmt.Printf("%v\n", conn.Client) | |||
} |
@@ -27,21 +27,22 @@ func (err *SearchError) Error() string { | |||
return fmt.Sprintf("[%d] %s", err.StatusCode, err.Msg) | |||
} | |||
// NewConnection initiates a new Connection to an elasticsearch server | |||
// NewClient initiates a new client for an elasticsearch server | |||
// | |||
// This function is pretty useless for now but might be useful in a near future | |||
// if wee need more features like connection pooling or load balancing. | |||
func NewConnection(host string, port string) *Connection { | |||
return &Connection{host, port, http.DefaultClient} | |||
func NewClient(host string, port string) *Client { | |||
return &Client{host, port, http.DefaultClient} | |||
} | |||
func (c *Connection) WithClient(cl *http.Client) *Connection { | |||
// WithHTTPClient sets the http.Client to be used with the connection. Returns the original client. | |||
func (c *Client) WithHTTPClient(cl *http.Client) *Client { | |||
c.Client = cl | |||
return c | |||
} | |||
// CreateIndex creates a new index represented by a name and a mapping | |||
func (c *Connection) CreateIndex(name string, mapping interface{}) (*Response, error) { | |||
func (c *Client) CreateIndex(name string, mapping interface{}) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
Query: mapping, | |||
@@ -53,7 +54,7 @@ func (c *Connection) CreateIndex(name string, mapping interface{}) (*Response, e | |||
} | |||
// DeleteIndex deletes an index represented by a name | |||
func (c *Connection) DeleteIndex(name string) (*Response, error) { | |||
func (c *Client) DeleteIndex(name string) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
IndexList: []string{name}, | |||
@@ -64,7 +65,7 @@ func (c *Connection) DeleteIndex(name string) (*Response, error) { | |||
} | |||
// RefreshIndex refreshes an index represented by a name | |||
func (c *Connection) RefreshIndex(name string) (*Response, error) { | |||
func (c *Client) RefreshIndex(name string) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
IndexList: []string{name}, | |||
@@ -77,7 +78,7 @@ func (c *Connection) RefreshIndex(name string) (*Response, error) { | |||
// UpdateIndexSettings updates settings for existing index represented by a name and a settings | |||
// as described here: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html | |||
func (c *Connection) UpdateIndexSettings(name string, settings interface{}) (*Response, error) { | |||
func (c *Client) UpdateIndexSettings(name string, settings interface{}) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
Query: settings, | |||
@@ -91,7 +92,7 @@ func (c *Connection) UpdateIndexSettings(name string, settings interface{}) (*Re | |||
// Optimize an index represented by a name, extra args are also allowed please check: | |||
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-optimize.html#indices-optimize | |||
func (c *Connection) Optimize(indexList []string, extraArgs url.Values) (*Response, error) { | |||
func (c *Client) Optimize(indexList []string, extraArgs url.Values) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
IndexList: indexList, | |||
@@ -104,7 +105,7 @@ func (c *Connection) Optimize(indexList []string, extraArgs url.Values) (*Respon | |||
} | |||
// Stats fetches statistics (_stats) for the current elasticsearch server | |||
func (c *Connection) Stats(indexList []string, extraArgs url.Values) (*Response, error) { | |||
func (c *Client) Stats(indexList []string, extraArgs url.Values) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
IndexList: indexList, | |||
@@ -118,7 +119,7 @@ func (c *Connection) Stats(indexList []string, extraArgs url.Values) (*Response, | |||
// IndexStatus fetches the status (_status) for the indices defined in | |||
// indexList. Use _all in indexList to get stats for all indices | |||
func (c *Connection) IndexStatus(indexList []string) (*Response, error) { | |||
func (c *Client) IndexStatus(indexList []string) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
IndexList: indexList, | |||
@@ -130,7 +131,7 @@ func (c *Connection) IndexStatus(indexList []string) (*Response, error) { | |||
} | |||
// Bulk adds multiple documents in bulk mode | |||
func (c *Connection) BulkSend(documents []Document) (*Response, error) { | |||
func (c *Client) BulkSend(documents []Document) (*Response, error) { | |||
// We do not generate a traditional JSON here (often a one liner) | |||
// Elasticsearch expects one line of JSON per line (EOL = \n) | |||
// plus an extra \n at the very end of the document | |||
@@ -210,7 +211,7 @@ func (c *Connection) BulkSend(documents []Document) (*Response, error) { | |||
} | |||
// Search executes a search query against an index | |||
func (c *Connection) Search(query interface{}, indexList []string, typeList []string, extraArgs url.Values) (*Response, error) { | |||
func (c *Client) Search(query interface{}, indexList []string, typeList []string, extraArgs url.Values) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
Query: query, | |||
@@ -225,7 +226,7 @@ func (c *Connection) Search(query interface{}, indexList []string, typeList []st | |||
} | |||
// Count executes a count query against an index, use the Count field in the response for the result | |||
func (c *Connection) Count(query interface{}, indexList []string, typeList []string, extraArgs url.Values) (*Response, error) { | |||
func (c *Client) Count(query interface{}, indexList []string, typeList []string, extraArgs url.Values) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
Query: query, | |||
@@ -242,7 +243,7 @@ func (c *Connection) Count(query interface{}, indexList []string, typeList []str | |||
//Query runs a query against an index using the provided http method. | |||
//This method can be used to execute a delete by query, just pass in "DELETE" | |||
//for the HTTP method. | |||
func (c *Connection) Query(query interface{}, indexList []string, typeList []string, httpMethod string, extraArgs url.Values) (*Response, error) { | |||
func (c *Client) Query(query interface{}, indexList []string, typeList []string, httpMethod string, extraArgs url.Values) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
Query: query, | |||
@@ -257,7 +258,7 @@ func (c *Connection) Query(query interface{}, indexList []string, typeList []str | |||
} | |||
// Scan starts scroll over an index | |||
func (c *Connection) Scan(query interface{}, indexList []string, typeList []string, timeout string, size int) (*Response, error) { | |||
func (c *Client) Scan(query interface{}, indexList []string, typeList []string, timeout string, size int) (*Response, error) { | |||
v := url.Values{} | |||
v.Add("search_type", "scan") | |||
v.Add("scroll", timeout) | |||
@@ -277,7 +278,7 @@ func (c *Connection) Scan(query interface{}, indexList []string, typeList []stri | |||
} | |||
// Scroll fetches data by scroll id | |||
func (c *Connection) Scroll(scrollId string, timeout string) (*Response, error) { | |||
func (c *Client) Scroll(scrollId string, timeout string) (*Response, error) { | |||
v := url.Values{} | |||
v.Add("scroll", timeout) | |||
@@ -293,7 +294,7 @@ func (c *Connection) Scroll(scrollId string, timeout string) (*Response, error) | |||
} | |||
// Get a typed document by its id | |||
func (c *Connection) Get(index string, documentType string, id string, extraArgs url.Values) (*Response, error) { | |||
func (c *Client) Get(index string, documentType string, id string, extraArgs url.Values) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
IndexList: []string{index}, | |||
@@ -308,7 +309,7 @@ func (c *Connection) Get(index string, documentType string, id string, extraArgs | |||
// Index indexes a Document | |||
// The extraArgs is a list of url.Values that you can send to elasticsearch as | |||
// URL arguments, for example, to control routing, ttl, version, op_type, etc. | |||
func (c *Connection) Index(d Document, extraArgs url.Values) (*Response, error) { | |||
func (c *Client) Index(d Document, extraArgs url.Values) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
Query: d.Fields, | |||
@@ -329,7 +330,7 @@ func (c *Connection) Index(d Document, extraArgs url.Values) (*Response, error) | |||
// Delete deletes a Document d | |||
// The extraArgs is a list of url.Values that you can send to elasticsearch as | |||
// URL arguments, for example, to control routing. | |||
func (c *Connection) Delete(d Document, extraArgs url.Values) (*Response, error) { | |||
func (c *Client) Delete(d Document, extraArgs url.Values) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
IndexList: []string{d.Index.(string)}, | |||
@@ -484,7 +485,7 @@ func (b Bucket) Aggregation(name string) Aggregation { | |||
} | |||
// PutMapping registers a specific mapping for one or more types in one or more indexes | |||
func (c *Connection) PutMapping(typeName string, mapping interface{}, indexes []string) (*Response, error) { | |||
func (c *Client) PutMapping(typeName string, mapping interface{}, indexes []string) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
@@ -497,7 +498,7 @@ func (c *Connection) PutMapping(typeName string, mapping interface{}, indexes [] | |||
return r.Run() | |||
} | |||
func (c *Connection) GetMapping(types []string, indexes []string) (*Response, error) { | |||
func (c *Client) GetMapping(types []string, indexes []string) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
@@ -510,7 +511,7 @@ func (c *Connection) GetMapping(types []string, indexes []string) (*Response, er | |||
} | |||
// IndicesExist checks whether index (or indices) exist on the server | |||
func (c *Connection) IndicesExist(indexes []string) (bool, error) { | |||
func (c *Client) IndicesExist(indexes []string) (bool, error) { | |||
r := Request{ | |||
Conn: c, | |||
@@ -523,7 +524,7 @@ func (c *Connection) IndicesExist(indexes []string) (bool, error) { | |||
return resp.Status == 200, err | |||
} | |||
func (c *Connection) Update(d Document, query interface{}, extraArgs url.Values) (*Response, error) { | |||
func (c *Client) Update(d Document, query interface{}, extraArgs url.Values) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
Query: query, | |||
@@ -542,7 +543,7 @@ func (c *Connection) Update(d Document, query interface{}, extraArgs url.Values) | |||
} | |||
// DeleteMapping deletes a mapping along with all data in the type | |||
func (c *Connection) DeleteMapping(typeName string, indexes []string) (*Response, error) { | |||
func (c *Client) DeleteMapping(typeName string, indexes []string) (*Response, error) { | |||
r := Request{ | |||
Conn: c, | |||
@@ -554,7 +555,7 @@ func (c *Connection) DeleteMapping(typeName string, indexes []string) (*Response | |||
return r.Run() | |||
} | |||
func (c *Connection) modifyAlias(action string, alias string, indexes []string) (*Response, error) { | |||
func (c *Client) modifyAlias(action string, alias string, indexes []string) (*Response, error) { | |||
command := map[string]interface{}{ | |||
"actions": make([]map[string]interface{}, 1), | |||
} | |||
@@ -579,17 +580,17 @@ func (c *Connection) modifyAlias(action string, alias string, indexes []string) | |||
} | |||
// AddAlias creates an alias to one or more indexes | |||
func (c *Connection) AddAlias(alias string, indexes []string) (*Response, error) { | |||
func (c *Client) AddAlias(alias string, indexes []string) (*Response, error) { | |||
return c.modifyAlias("add", alias, indexes) | |||
} | |||
// RemoveAlias removes an alias to one or more indexes | |||
func (c *Connection) RemoveAlias(alias string, indexes []string) (*Response, error) { | |||
func (c *Client) RemoveAlias(alias string, indexes []string) (*Response, error) { | |||
return c.modifyAlias("remove", alias, indexes) | |||
} | |||
// AliasExists checks whether alias is defined on the server | |||
func (c *Connection) AliasExists(alias string) (bool, error) { | |||
func (c *Client) AliasExists(alias string) (bool, error) { | |||
r := Request{ | |||
Conn: c, | |||
@@ -39,12 +39,12 @@ func (s *GoesTestSuite) SetUpTest(c *C) { | |||
} | |||
} | |||
func (s *GoesTestSuite) TestNewConnection(c *C) { | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
c.Assert(conn, DeepEquals, &Connection{ES_HOST, ES_PORT, http.DefaultClient}) | |||
func (s *GoesTestSuite) TestNewClient(c *C) { | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
c.Assert(conn, DeepEquals, &Client{ES_HOST, ES_PORT, http.DefaultClient}) | |||
} | |||
func (s *GoesTestSuite) TestWithClient(c *C) { | |||
func (s *GoesTestSuite) TestWithHTTPClient(c *C) { | |||
tr := &http.Transport{ | |||
DisableCompression: true, | |||
ResponseHeaderTimeout: 1 * time.Second, | |||
@@ -52,15 +52,15 @@ func (s *GoesTestSuite) TestWithClient(c *C) { | |||
cl := &http.Client{ | |||
Transport: tr, | |||
} | |||
conn := NewConnection(ES_HOST, ES_PORT).WithClient(cl) | |||
conn := NewClient(ES_HOST, ES_PORT).WithHTTPClient(cl) | |||
c.Assert(conn, DeepEquals, &Connection{ES_HOST, ES_PORT, cl}) | |||
c.Assert(conn, DeepEquals, &Client{ES_HOST, ES_PORT, cl}) | |||
c.Assert(conn.Client.Transport.(*http.Transport).DisableCompression, Equals, true) | |||
c.Assert(conn.Client.Transport.(*http.Transport).ResponseHeaderTimeout, Equals, 1*time.Second) | |||
} | |||
func (s *GoesTestSuite) TestUrl(c *C) { | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
r := Request{ | |||
Conn: conn, | |||
@@ -89,7 +89,7 @@ func (s *GoesTestSuite) TestUrl(c *C) { | |||
} | |||
func (s *GoesTestSuite) TestEsDown(c *C) { | |||
conn := NewConnection("a.b.c.d", "1234") | |||
conn := NewClient("a.b.c.d", "1234") | |||
var query = map[string]interface{}{"query": "foo"} | |||
@@ -106,7 +106,7 @@ func (s *GoesTestSuite) TestEsDown(c *C) { | |||
} | |||
func (s *GoesTestSuite) TestRunMissingIndex(c *C) { | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
var query = map[string]interface{}{"query": "foo"} | |||
@@ -125,7 +125,7 @@ func (s *GoesTestSuite) TestRunMissingIndex(c *C) { | |||
func (s *GoesTestSuite) TestCreateIndex(c *C) { | |||
indexName := "testcreateindexgoes" | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
defer conn.DeleteIndex(indexName) | |||
mapping := map[string]interface{}{ | |||
@@ -152,7 +152,7 @@ func (s *GoesTestSuite) TestCreateIndex(c *C) { | |||
} | |||
func (s *GoesTestSuite) TestDeleteIndexInexistantIndex(c *C) { | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
resp, err := conn.DeleteIndex("foobar") | |||
c.Assert(err.Error(), Equals, "[404] IndexMissingException[[foobar] missing]") | |||
@@ -161,7 +161,7 @@ func (s *GoesTestSuite) TestDeleteIndexInexistantIndex(c *C) { | |||
} | |||
func (s *GoesTestSuite) TestDeleteIndexExistingIndex(c *C) { | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
indexName := "testdeleteindexexistingindex" | |||
@@ -181,7 +181,7 @@ func (s *GoesTestSuite) TestDeleteIndexExistingIndex(c *C) { | |||
} | |||
func (s *GoesTestSuite) TestUpdateIndexSettings(c *C) { | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
indexName := "testupdateindex" | |||
_, err := conn.CreateIndex(indexName, map[string]interface{}{}) | |||
@@ -199,7 +199,7 @@ func (s *GoesTestSuite) TestUpdateIndexSettings(c *C) { | |||
} | |||
func (s *GoesTestSuite) TestRefreshIndex(c *C) { | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
indexName := "testrefreshindex" | |||
_, err := conn.CreateIndex(indexName, map[string]interface{}{}) | |||
@@ -213,7 +213,7 @@ func (s *GoesTestSuite) TestRefreshIndex(c *C) { | |||
} | |||
func (s *GoesTestSuite) TestOptimize(c *C) { | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
indexName := "testoptimize" | |||
conn.DeleteIndex(indexName) | |||
@@ -260,7 +260,7 @@ func (s *GoesTestSuite) TestBulkSend(c *C) { | |||
}, | |||
} | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
conn.DeleteIndex(indexName) | |||
_, err := conn.CreateIndex(indexName, nil) | |||
@@ -349,7 +349,7 @@ func (s *GoesTestSuite) TestBulkSend(c *C) { | |||
} | |||
func (s *GoesTestSuite) TestStats(c *C) { | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
indexName := "teststats" | |||
conn.DeleteIndex(indexName) | |||
@@ -373,7 +373,7 @@ func (s *GoesTestSuite) TestIndexWithFieldsInStruct(c *C) { | |||
docType := "tweet" | |||
docId := "1234" | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
// just in case | |||
conn.DeleteIndex(indexName) | |||
@@ -416,7 +416,7 @@ func (s *GoesTestSuite) TestIndexWithFieldsNotInMapOrStruct(c *C) { | |||
docType := "tweet" | |||
docId := "1234" | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
// just in case | |||
conn.DeleteIndex(indexName) | |||
@@ -442,7 +442,7 @@ func (s *GoesTestSuite) TestIndexIdDefined(c *C) { | |||
docType := "tweet" | |||
docId := "1234" | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
// just in case | |||
conn.DeleteIndex(indexName) | |||
@@ -481,7 +481,7 @@ func (s *GoesTestSuite) TestIndexIdNotDefined(c *C) { | |||
indexName := "testindexidnotdefined" | |||
docType := "tweet" | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
// just in case | |||
conn.DeleteIndex(indexName) | |||
@@ -512,7 +512,7 @@ func (s *GoesTestSuite) TestDelete(c *C) { | |||
docType := "tweet" | |||
docId := "1234" | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
// just in case | |||
conn.DeleteIndex(indexName) | |||
@@ -568,7 +568,7 @@ func (s *GoesTestSuite) TestDeleteByQuery(c *C) { | |||
docType := "tweet" | |||
docId := "1234" | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
// just in case | |||
conn.DeleteIndex(indexName) | |||
@@ -638,7 +638,7 @@ func (s *GoesTestSuite) TestGet(c *C) { | |||
"f2": "foo", | |||
} | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
conn.DeleteIndex(indexName) | |||
_, err := conn.CreateIndex(indexName, map[string]interface{}{}) | |||
@@ -701,7 +701,7 @@ func (s *GoesTestSuite) TestSearch(c *C) { | |||
"message": "bar", | |||
} | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
conn.DeleteIndex(indexName) | |||
_, err := conn.CreateIndex(indexName, map[string]interface{}{}) | |||
@@ -761,7 +761,7 @@ func (s *GoesTestSuite) TestCount(c *C) { | |||
"message": "bar", | |||
} | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
conn.DeleteIndex(indexName) | |||
_, err := conn.CreateIndex(indexName, map[string]interface{}{}) | |||
@@ -800,7 +800,7 @@ func (s *GoesTestSuite) TestCount(c *C) { | |||
func (s *GoesTestSuite) TestIndexStatus(c *C) { | |||
indexName := "testindexstatus" | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
conn.DeleteIndex(indexName) | |||
mapping := map[string]interface{}{ | |||
@@ -909,7 +909,7 @@ func (s *GoesTestSuite) TestScroll(c *C) { | |||
}, | |||
} | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
mapping := map[string]interface{}{ | |||
"settings": map[string]interface{}{ | |||
@@ -1011,7 +1011,7 @@ func (s *GoesTestSuite) TestAggregations(c *C) { | |||
}, | |||
} | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
mapping := map[string]interface{}{ | |||
"settings": map[string]interface{}{ | |||
@@ -1084,7 +1084,7 @@ func (s *GoesTestSuite) TestPutMapping(c *C) { | |||
indexName := "testputmapping" | |||
docType := "tweet" | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
// just in case | |||
conn.DeleteIndex(indexName) | |||
@@ -1125,7 +1125,7 @@ func (s *GoesTestSuite) TestPutMapping(c *C) { | |||
func (s *GoesTestSuite) TestIndicesExist(c *C) { | |||
indices := []string{"testindicesexist"} | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
// just in case | |||
conn.DeleteIndex(indices[0]) | |||
@@ -1150,7 +1150,7 @@ func (s *GoesTestSuite) TestUpdate(c *C) { | |||
docType := "tweet" | |||
docId := "1234" | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
// just in case | |||
conn.DeleteIndex(indexName) | |||
@@ -1231,7 +1231,7 @@ func (s *GoesTestSuite) TestGetMapping(c *C) { | |||
indexName := "testmapping" | |||
docType := "tweet" | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
// just in case | |||
conn.DeleteIndex(indexName) | |||
@@ -1267,7 +1267,7 @@ func (s *GoesTestSuite) TestDeleteMapping(c *C) { | |||
indexName := "testdeletemapping" | |||
docType := "tweet" | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
// just in case | |||
conn.DeleteIndex(indexName) | |||
@@ -1319,7 +1319,7 @@ func (s *GoesTestSuite) TestAddAlias(c *C) { | |||
"message": "bar", | |||
} | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
defer conn.DeleteIndex(indexName) | |||
_, err := conn.CreateIndex(indexName, map[string]interface{}{}) | |||
@@ -1369,7 +1369,7 @@ func (s *GoesTestSuite) TestRemoveAlias(c *C) { | |||
"message": "bar", | |||
} | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
defer conn.DeleteIndex(indexName) | |||
_, err := conn.CreateIndex(indexName, map[string]interface{}{}) | |||
@@ -1404,7 +1404,7 @@ func (s *GoesTestSuite) TestAliasExists(c *C) { | |||
index := "testaliasexist_1" | |||
alias := "testaliasexists" | |||
conn := NewConnection(ES_HOST, ES_PORT) | |||
conn := NewClient(ES_HOST, ES_PORT) | |||
// just in case | |||
conn.DeleteIndex(index) | |||
@@ -9,8 +9,8 @@ import ( | |||
"net/url" | |||
) | |||
// Represents a Connection object to elasticsearch | |||
type Connection struct { | |||
// Client represents a connection to elasticsearch | |||
type Client struct { | |||
// The host to connect to | |||
Host string | |||
@@ -22,10 +22,10 @@ type Connection struct { | |||
Client *http.Client | |||
} | |||
// Represents a Request to elasticsearch | |||
// Request holds a single request to elasticsearch | |||
type Request struct { | |||
// Which connection will be used | |||
Conn *Connection | |||
Conn *Client | |||
// A search query | |||
Query interface{} | |||
@@ -55,7 +55,7 @@ type Request struct { | |||
id string | |||
} | |||
// Represents a Response from elasticsearch | |||
// Response holds an elasticsearch response | |||
type Response struct { | |||
Acknowledged bool | |||
Error string | |||
@@ -93,13 +93,13 @@ type Response struct { | |||
Raw map[string]interface{} | |||
} | |||
// Represents an aggregation from response | |||
// Aggregation holds the aggregation portion of an ES response | |||
type Aggregation map[string]interface{} | |||
// Represents a bucket for aggregation | |||
// Bucket represents a bucket for aggregation | |||
type Bucket map[string]interface{} | |||
// Represents a document to send to elasticsearch | |||
// Document holds a document to send to elasticsearch | |||
type Document struct { | |||
// XXX : interface as we can support nil values | |||
Index interface{} | |||
@@ -109,7 +109,7 @@ type Document struct { | |||
Fields interface{} | |||
} | |||
// Represents the "items" field in a _bulk response | |||
// Item holds an item from the "items" field in a _bulk response | |||
type Item struct { | |||
Type string `json:"_type"` | |||
Id string `json:"_id"` | |||
@@ -119,7 +119,7 @@ type Item struct { | |||
Status uint64 `json:"status"` | |||
} | |||
// Represents the "_all" field when calling the _stats API | |||
// All represents the "_all" field when calling the _stats API | |||
// This is minimal but this is what I only need | |||
type All struct { | |||
Indices map[string]StatIndex `json:"indices"` | |||
@@ -136,14 +136,14 @@ type StatPrimary struct { | |||
Deleted int | |||
} | |||
// Represents the "shard" struct as returned by elasticsearch | |||
// Shard holds the "shard" struct as returned by elasticsearch | |||
type Shard struct { | |||
Total uint64 | |||
Successful uint64 | |||
Failed uint64 | |||
} | |||
// Represent a hit returned by a search | |||
// Hit holds a hit returned by a search | |||
type Hit struct { | |||
Index string `json:"_index"` | |||
Type string `json:"_type"` | |||
@@ -154,7 +154,7 @@ type Hit struct { | |||
Fields map[string]interface{} `json:"fields"` | |||
} | |||
// Represent the hits structure as returned by elasticsearch | |||
// Hits holds the hits structure as returned by elasticsearch | |||
type Hits struct { | |||
Total uint64 | |||
// max_score may contain the "null" value | |||
@@ -167,7 +167,7 @@ type SearchError struct { | |||
StatusCode uint64 | |||
} | |||
// Represent the status for a given index for the _status command | |||
// IndexStatus holds the status for a given index for the _status command | |||
type IndexStatus struct { | |||
// XXX : problem, int will be marshaled to a float64 which seems logical | |||
// XXX : is it better to use strings even for int values or to keep | |||