Browse Source

Update code to match Go style guide

tags/v1.2.2
Paul Bonser 7 years ago
parent
commit
9f7a8396bb
4 changed files with 176 additions and 170 deletions
  1. +16
    -16
      example_test.go
  2. +27
    -24
      goes.go
  3. +125
    -125
      goes_test.go
  4. +8
    -5
      structs.go

+ 16
- 16
example_test.go View File

@@ -19,7 +19,7 @@ var (
ES_PORT = "9200" ES_PORT = "9200"
) )


func getConnection() (conn *goes.Client) {
func getClient() (conn *goes.Client) {
h := os.Getenv("TEST_ELASTICSEARCH_HOST") h := os.Getenv("TEST_ELASTICSEARCH_HOST")
if h == "" { if h == "" {
h = ES_HOST h = ES_HOST
@@ -35,8 +35,8 @@ func getConnection() (conn *goes.Client) {
return return
} }


func ExampleConnection_CreateIndex() {
conn := getConnection()
func ExampleClient_CreateIndex() {
conn := getClient()


mapping := map[string]interface{}{ mapping := map[string]interface{}{
"settings": map[string]interface{}{ "settings": map[string]interface{}{
@@ -64,8 +64,8 @@ func ExampleConnection_CreateIndex() {
fmt.Printf("%s", resp) fmt.Printf("%s", resp)
} }


func ExampleConnection_DeleteIndex() {
conn := getConnection()
func ExampleClient_DeleteIndex() {
conn := getClient()
resp, err := conn.DeleteIndex("yourinde") resp, err := conn.DeleteIndex("yourinde")


if err != nil { if err != nil {
@@ -75,8 +75,8 @@ func ExampleConnection_DeleteIndex() {
fmt.Printf("%s", resp) fmt.Printf("%s", resp)
} }


func ExampleConnection_RefreshIndex() {
conn := getConnection()
func ExampleClient_RefreshIndex() {
conn := getClient()
resp, err := conn.RefreshIndex("yourindex") resp, err := conn.RefreshIndex("yourindex")


if err != nil { if err != nil {
@@ -86,8 +86,8 @@ func ExampleConnection_RefreshIndex() {
fmt.Printf("%s", resp) fmt.Printf("%s", resp)
} }


func ExampleConnection_Search() {
conn := getConnection()
func ExampleClient_Search() {
conn := getClient()


var query = map[string]interface{}{ var query = map[string]interface{}{
"query": map[string]interface{}{ "query": map[string]interface{}{
@@ -123,8 +123,8 @@ func ExampleConnection_Search() {
fmt.Printf("%s", searchResults) fmt.Printf("%s", searchResults)
} }


func ExampleConnection_Index() {
conn := getConnection()
func ExampleClient_Index() {
conn := getClient()


d := goes.Document{ d := goes.Document{
Index: "twitter", Index: "twitter",
@@ -147,15 +147,15 @@ func ExampleConnection_Index() {
fmt.Printf("%s", response) fmt.Printf("%s", response)
} }


func ExampleConnection_Delete() {
conn := getConnection()
func ExampleClient_Delete() {
conn := getClient()


//[create index, index document ...] //[create index, index document ...]


d := goes.Document{ d := goes.Document{
Index: "twitter", Index: "twitter",
Type: "tweet", Type: "tweet",
Id: "1",
ID: "1",
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"user": "foo", "user": "foo",
}, },
@@ -169,14 +169,14 @@ func ExampleConnection_Delete() {
fmt.Printf("%s", response) fmt.Printf("%s", response)
} }


func ExampleConnectionOverrideHttpClient() {
func ExampleClient_WithHTTPClient() {
tr := &http.Transport{ tr := &http.Transport{
ResponseHeaderTimeout: 1 * time.Second, ResponseHeaderTimeout: 1 * time.Second,
} }
cl := &http.Client{ cl := &http.Client{
Transport: tr, Transport: tr,
} }
conn := getConnection()
conn := getClient()
conn.WithHTTPClient(cl) conn.WithHTTPClient(cl)


fmt.Printf("%v\n", conn.Client) fmt.Printf("%v\n", conn.Client)


+ 27
- 24
goes.go View File

@@ -19,8 +19,10 @@ import (
) )


const ( const (
BULK_COMMAND_INDEX = "index"
BULK_COMMAND_DELETE = "delete"
// BulkCommandIndex specifies a bulk doc should be indexed
BulkCommandIndex = "index"
// BulkCommandDelete specifies a bulk doc should be deleted
BulkCommandDelete = "delete"
) )


func (err *SearchError) Error() string { func (err *SearchError) Error() string {
@@ -130,7 +132,7 @@ func (c *Client) IndexStatus(indexList []string) (*Response, error) {
return r.Run() return r.Run()
} }


// Bulk adds multiple documents in bulk mode
// BulkSend bulk adds multiple documents in bulk mode
func (c *Client) 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) // We do not generate a traditional JSON here (often a one liner)
// Elasticsearch expects one line of JSON per line (EOL = \n) // Elasticsearch expects one line of JSON per line (EOL = \n)
@@ -158,7 +160,7 @@ func (c *Client) BulkSend(documents []Document) (*Response, error) {
doc.BulkCommand: map[string]interface{}{ doc.BulkCommand: map[string]interface{}{
"_index": doc.Index, "_index": doc.Index,
"_type": doc.Type, "_type": doc.Type,
"_id": doc.Id,
"_id": doc.ID,
}, },
}) })


@@ -278,7 +280,7 @@ func (c *Client) Scan(query interface{}, indexList []string, typeList []string,
} }


// Scroll fetches data by scroll id // Scroll fetches data by scroll id
func (c *Client) Scroll(scrollId string, timeout string) (*Response, error) {
func (c *Client) Scroll(scrollID string, timeout string) (*Response, error) {
v := url.Values{} v := url.Values{}
v.Add("scroll", timeout) v.Add("scroll", timeout)


@@ -287,7 +289,7 @@ func (c *Client) Scroll(scrollId string, timeout string) (*Response, error) {
method: "POST", method: "POST",
api: "_search/scroll", api: "_search/scroll",
ExtraArgs: v, ExtraArgs: v,
Body: []byte(scrollId),
Body: []byte(scrollID),
} }


return r.Run() return r.Run()
@@ -319,9 +321,9 @@ func (c *Client) Index(d Document, extraArgs url.Values) (*Response, error) {
method: "POST", method: "POST",
} }


if d.Id != nil {
if d.ID != nil {
r.method = "PUT" r.method = "PUT"
r.id = d.Id.(string)
r.id = d.ID.(string)
} }


return r.Run() return r.Run()
@@ -337,7 +339,7 @@ func (c *Client) Delete(d Document, extraArgs url.Values) (*Response, error) {
TypeList: []string{d.Type}, TypeList: []string{d.Type},
ExtraArgs: extraArgs, ExtraArgs: extraArgs,
method: "DELETE", method: "DELETE",
id: d.Id.(string),
id: d.ID.(string),
} }


return r.Run() return r.Run()
@@ -400,7 +402,7 @@ func (req *Request) run() ([]byte, uint64, error) {


reader := bytes.NewReader(postData) reader := bytes.NewReader(postData)


newReq, err := http.NewRequest(req.method, req.Url(), reader)
newReq, err := http.NewRequest(req.method, req.URL(), reader)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
} }
@@ -428,26 +430,26 @@ func (req *Request) run() ([]byte, uint64, error) {
return body, uint64(resp.StatusCode), nil return body, uint64(resp.StatusCode), nil
} }


// Url builds a Request for a URL
func (r *Request) Url() string {
path := "/" + strings.Join(r.IndexList, ",")
// URL builds a Request for a URL
func (req *Request) URL() string {
path := "/" + strings.Join(req.IndexList, ",")


if len(r.TypeList) > 0 {
path += "/" + strings.Join(r.TypeList, ",")
if len(req.TypeList) > 0 {
path += "/" + strings.Join(req.TypeList, ",")
} }


// XXX : for indexing documents using the normal (non bulk) API // XXX : for indexing documents using the normal (non bulk) API
if len(r.id) > 0 {
path += "/" + r.id
if len(req.id) > 0 {
path += "/" + req.id
} }


path += "/" + r.api
path += "/" + req.api


u := url.URL{ u := url.URL{
Scheme: "http", Scheme: "http",
Host: fmt.Sprintf("%s:%s", r.Conn.Host, r.Conn.Port),
Host: fmt.Sprintf("%s:%s", req.Conn.Host, req.Conn.Port),
Path: path, Path: path,
RawQuery: r.ExtraArgs.Encode(),
RawQuery: req.ExtraArgs.Encode(),
} }


return u.String() return u.String()
@@ -479,9 +481,8 @@ func (b Bucket) DocCount() uint64 {
func (b Bucket) Aggregation(name string) Aggregation { func (b Bucket) Aggregation(name string) Aggregation {
if agg, ok := b[name]; ok { if agg, ok := b[name]; ok {
return agg.(map[string]interface{}) return agg.(map[string]interface{})
} else {
return Aggregation{}
} }
return Aggregation{}
} }


// PutMapping registers a specific mapping for one or more types in one or more indexes // PutMapping registers a specific mapping for one or more types in one or more indexes
@@ -498,6 +499,7 @@ func (c *Client) PutMapping(typeName string, mapping interface{}, indexes []stri
return r.Run() return r.Run()
} }


// GetMapping returns the mappings for the specified types
func (c *Client) GetMapping(types []string, indexes []string) (*Response, error) { func (c *Client) GetMapping(types []string, indexes []string) (*Response, error) {


r := Request{ r := Request{
@@ -524,6 +526,7 @@ func (c *Client) IndicesExist(indexes []string) (bool, error) {
return resp.Status == 200, err return resp.Status == 200, err
} }


// Update updates the specified document using the _update endpoint
func (c *Client) 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{ r := Request{
Conn: c, Conn: c,
@@ -535,8 +538,8 @@ func (c *Client) Update(d Document, query interface{}, extraArgs url.Values) (*R
api: "_update", api: "_update",
} }


if d.Id != nil {
r.id = d.Id.(string)
if d.ID != nil {
r.id = d.ID.(string)
} }


return r.Run() return r.Run()


+ 125
- 125
goes_test.go View File

@@ -16,8 +16,8 @@ import (
) )


var ( var (
ES_HOST = "localhost"
ES_PORT = "9200"
ESHost = "localhost"
ESPort = "9200"
) )


// Hook up gocheck into the gotest runner. // Hook up gocheck into the gotest runner.
@@ -30,18 +30,18 @@ var _ = Suite(&GoesTestSuite{})
func (s *GoesTestSuite) SetUpTest(c *C) { func (s *GoesTestSuite) SetUpTest(c *C) {
h := os.Getenv("TEST_ELASTICSEARCH_HOST") h := os.Getenv("TEST_ELASTICSEARCH_HOST")
if h != "" { if h != "" {
ES_HOST = h
ESHost = h
} }


p := os.Getenv("TEST_ELASTICSEARCH_PORT") p := os.Getenv("TEST_ELASTICSEARCH_PORT")
if p != "" { if p != "" {
ES_PORT = p
ESPort = p
} }
} }


func (s *GoesTestSuite) TestNewClient(c *C) { func (s *GoesTestSuite) TestNewClient(c *C) {
conn := NewClient(ES_HOST, ES_PORT)
c.Assert(conn, DeepEquals, &Client{ES_HOST, ES_PORT, http.DefaultClient})
conn := NewClient(ESHost, ESPort)
c.Assert(conn, DeepEquals, &Client{ESHost, ESPort, http.DefaultClient})
} }


func (s *GoesTestSuite) TestWithHTTPClient(c *C) { func (s *GoesTestSuite) TestWithHTTPClient(c *C) {
@@ -52,15 +52,15 @@ func (s *GoesTestSuite) TestWithHTTPClient(c *C) {
cl := &http.Client{ cl := &http.Client{
Transport: tr, Transport: tr,
} }
conn := NewClient(ES_HOST, ES_PORT).WithHTTPClient(cl)
conn := NewClient(ESHost, ESPort).WithHTTPClient(cl)


c.Assert(conn, DeepEquals, &Client{ES_HOST, ES_PORT, cl})
c.Assert(conn, DeepEquals, &Client{ESHost, ESPort, cl})
c.Assert(conn.Client.Transport.(*http.Transport).DisableCompression, Equals, true) c.Assert(conn.Client.Transport.(*http.Transport).DisableCompression, Equals, true)
c.Assert(conn.Client.Transport.(*http.Transport).ResponseHeaderTimeout, Equals, 1*time.Second) c.Assert(conn.Client.Transport.(*http.Transport).ResponseHeaderTimeout, Equals, 1*time.Second)
} }


func (s *GoesTestSuite) TestUrl(c *C) { func (s *GoesTestSuite) TestUrl(c *C) {
conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)


r := Request{ r := Request{
Conn: conn, Conn: conn,
@@ -71,21 +71,21 @@ func (s *GoesTestSuite) TestUrl(c *C) {
api: "_search", api: "_search",
} }


c.Assert(r.Url(), Equals, "http://"+ES_HOST+":"+ES_PORT+"/i/_search")
c.Assert(r.URL(), Equals, "http://"+ESHost+":"+ESPort+"/i/_search")


r.IndexList = []string{"a", "b"} r.IndexList = []string{"a", "b"}
c.Assert(r.Url(), Equals, "http://"+ES_HOST+":"+ES_PORT+"/a,b/_search")
c.Assert(r.URL(), Equals, "http://"+ESHost+":"+ESPort+"/a,b/_search")


r.TypeList = []string{"c", "d"} r.TypeList = []string{"c", "d"}
c.Assert(r.Url(), Equals, "http://"+ES_HOST+":"+ES_PORT+"/a,b/c,d/_search")
c.Assert(r.URL(), Equals, "http://"+ESHost+":"+ESPort+"/a,b/c,d/_search")


r.ExtraArgs = make(url.Values, 1) r.ExtraArgs = make(url.Values, 1)
r.ExtraArgs.Set("version", "1") r.ExtraArgs.Set("version", "1")
c.Assert(r.Url(), Equals, "http://"+ES_HOST+":"+ES_PORT+"/a,b/c,d/_search?version=1")
c.Assert(r.URL(), Equals, "http://"+ESHost+":"+ESPort+"/a,b/c,d/_search?version=1")


r.id = "1234" r.id = "1234"
r.api = "" r.api = ""
c.Assert(r.Url(), Equals, "http://"+ES_HOST+":"+ES_PORT+"/a,b/c,d/1234/?version=1")
c.Assert(r.URL(), Equals, "http://"+ESHost+":"+ESPort+"/a,b/c,d/1234/?version=1")
} }


func (s *GoesTestSuite) TestEsDown(c *C) { func (s *GoesTestSuite) TestEsDown(c *C) {
@@ -106,7 +106,7 @@ func (s *GoesTestSuite) TestEsDown(c *C) {
} }


func (s *GoesTestSuite) TestRunMissingIndex(c *C) { func (s *GoesTestSuite) TestRunMissingIndex(c *C) {
conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)


var query = map[string]interface{}{"query": "foo"} var query = map[string]interface{}{"query": "foo"}


@@ -125,7 +125,7 @@ func (s *GoesTestSuite) TestRunMissingIndex(c *C) {
func (s *GoesTestSuite) TestCreateIndex(c *C) { func (s *GoesTestSuite) TestCreateIndex(c *C) {
indexName := "testcreateindexgoes" indexName := "testcreateindexgoes"


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
defer conn.DeleteIndex(indexName) defer conn.DeleteIndex(indexName)


mapping := map[string]interface{}{ mapping := map[string]interface{}{
@@ -152,7 +152,7 @@ func (s *GoesTestSuite) TestCreateIndex(c *C) {
} }


func (s *GoesTestSuite) TestDeleteIndexInexistantIndex(c *C) { func (s *GoesTestSuite) TestDeleteIndexInexistantIndex(c *C) {
conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
resp, err := conn.DeleteIndex("foobar") resp, err := conn.DeleteIndex("foobar")


c.Assert(err.Error(), Equals, "[404] IndexMissingException[[foobar] missing]") 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) { func (s *GoesTestSuite) TestDeleteIndexExistingIndex(c *C) {
conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)


indexName := "testdeleteindexexistingindex" indexName := "testdeleteindexexistingindex"


@@ -181,7 +181,7 @@ func (s *GoesTestSuite) TestDeleteIndexExistingIndex(c *C) {
} }


func (s *GoesTestSuite) TestUpdateIndexSettings(c *C) { func (s *GoesTestSuite) TestUpdateIndexSettings(c *C) {
conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
indexName := "testupdateindex" indexName := "testupdateindex"


_, err := conn.CreateIndex(indexName, map[string]interface{}{}) _, err := conn.CreateIndex(indexName, map[string]interface{}{})
@@ -199,7 +199,7 @@ func (s *GoesTestSuite) TestUpdateIndexSettings(c *C) {
} }


func (s *GoesTestSuite) TestRefreshIndex(c *C) { func (s *GoesTestSuite) TestRefreshIndex(c *C) {
conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
indexName := "testrefreshindex" indexName := "testrefreshindex"


_, err := conn.CreateIndex(indexName, map[string]interface{}{}) _, err := conn.CreateIndex(indexName, map[string]interface{}{})
@@ -213,7 +213,7 @@ func (s *GoesTestSuite) TestRefreshIndex(c *C) {
} }


func (s *GoesTestSuite) TestOptimize(c *C) { func (s *GoesTestSuite) TestOptimize(c *C) {
conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
indexName := "testoptimize" indexName := "testoptimize"


conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)
@@ -238,10 +238,10 @@ func (s *GoesTestSuite) TestBulkSend(c *C) {


tweets := []Document{ tweets := []Document{
{ {
Id: "123",
ID: "123",
Index: indexName, Index: indexName,
Type: docType, Type: docType,
BulkCommand: BULK_COMMAND_INDEX,
BulkCommand: BulkCommandIndex,
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"user": "foo", "user": "foo",
"message": "some foo message", "message": "some foo message",
@@ -249,10 +249,10 @@ func (s *GoesTestSuite) TestBulkSend(c *C) {
}, },


{ {
Id: nil,
ID: nil,
Index: indexName, Index: indexName,
Type: docType, Type: docType,
BulkCommand: BULK_COMMAND_INDEX,
BulkCommand: BulkCommandIndex,
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"user": "bar", "user": "bar",
"message": "some bar message", "message": "some bar message",
@@ -260,7 +260,7 @@ func (s *GoesTestSuite) TestBulkSend(c *C) {
}, },
} }


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)


conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)
_, err := conn.CreateIndex(indexName, nil) _, err := conn.CreateIndex(indexName, nil)
@@ -268,13 +268,13 @@ func (s *GoesTestSuite) TestBulkSend(c *C) {


response, err := conn.BulkSend(tweets) response, err := conn.BulkSend(tweets)
i := Item{ i := Item{
Id: "123",
ID: "123",
Type: docType, Type: docType,
Version: 1, Version: 1,
Index: indexName, Index: indexName,
Status: 201, //201 for indexing ( https://issues.apache.org/jira/browse/CONNECTORS-634 ) Status: 201, //201 for indexing ( https://issues.apache.org/jira/browse/CONNECTORS-634 )
} }
c.Assert(response.Items[0][BULK_COMMAND_INDEX], Equals, i)
c.Assert(response.Items[0][BulkCommandIndex], Equals, i)
c.Assert(err, IsNil) c.Assert(err, IsNil)


_, err = conn.RefreshIndex(indexName) _, err = conn.RefreshIndex(indexName)
@@ -292,17 +292,17 @@ func (s *GoesTestSuite) TestBulkSend(c *C) {
var expectedTotal uint64 = 2 var expectedTotal uint64 = 2
c.Assert(searchResults.Hits.Total, Equals, expectedTotal) c.Assert(searchResults.Hits.Total, Equals, expectedTotal)


extraDocId := ""
extraDocID := ""
checked := 0 checked := 0
for _, hit := range searchResults.Hits.Hits { for _, hit := range searchResults.Hits.Hits {
if hit.Source["user"] == "foo" { if hit.Source["user"] == "foo" {
c.Assert(hit.Id, Equals, "123")
c.Assert(hit.ID, Equals, "123")
checked++ checked++
} }


if hit.Source["user"] == "bar" { if hit.Source["user"] == "bar" {
c.Assert(len(hit.Id) > 0, Equals, true)
extraDocId = hit.Id
c.Assert(len(hit.ID) > 0, Equals, true)
extraDocID = hit.ID
checked++ checked++
} }
} }
@@ -310,28 +310,28 @@ func (s *GoesTestSuite) TestBulkSend(c *C) {


docToDelete := []Document{ docToDelete := []Document{
{ {
Id: "123",
ID: "123",
Index: indexName, Index: indexName,
Type: docType, Type: docType,
BulkCommand: BULK_COMMAND_DELETE,
BulkCommand: BulkCommandDelete,
}, },
{ {
Id: extraDocId,
ID: extraDocID,
Index: indexName, Index: indexName,
Type: docType, Type: docType,
BulkCommand: BULK_COMMAND_DELETE,
BulkCommand: BulkCommandDelete,
}, },
} }


response, err = conn.BulkSend(docToDelete) response, err = conn.BulkSend(docToDelete)
i = Item{ i = Item{
Id: "123",
ID: "123",
Type: docType, Type: docType,
Version: 2, Version: 2,
Index: indexName, Index: indexName,
Status: 200, //200 for updates Status: 200, //200 for updates
} }
c.Assert(response.Items[0][BULK_COMMAND_DELETE], Equals, i)
c.Assert(response.Items[0][BulkCommandDelete], Equals, i)


c.Assert(err, IsNil) c.Assert(err, IsNil)


@@ -349,7 +349,7 @@ func (s *GoesTestSuite) TestBulkSend(c *C) {
} }


func (s *GoesTestSuite) TestStats(c *C) { func (s *GoesTestSuite) TestStats(c *C) {
conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
indexName := "teststats" indexName := "teststats"


conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)
@@ -371,9 +371,9 @@ func (s *GoesTestSuite) TestStats(c *C) {
func (s *GoesTestSuite) TestIndexWithFieldsInStruct(c *C) { func (s *GoesTestSuite) TestIndexWithFieldsInStruct(c *C) {
indexName := "testindexwithfieldsinstruct" indexName := "testindexwithfieldsinstruct"
docType := "tweet" docType := "tweet"
docId := "1234"
docID := "1234"


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
// just in case // just in case
conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)


@@ -384,7 +384,7 @@ func (s *GoesTestSuite) TestIndexWithFieldsInStruct(c *C) {
d := Document{ d := Document{
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Fields: struct { Fields: struct {
user string user string
message string message string
@@ -402,7 +402,7 @@ func (s *GoesTestSuite) TestIndexWithFieldsInStruct(c *C) {
expectedResponse := &Response{ expectedResponse := &Response{
Status: 201, Status: 201,
Index: indexName, Index: indexName,
Id: docId,
ID: docID,
Type: docType, Type: docType,
Version: 1, Version: 1,
} }
@@ -414,9 +414,9 @@ func (s *GoesTestSuite) TestIndexWithFieldsInStruct(c *C) {
func (s *GoesTestSuite) TestIndexWithFieldsNotInMapOrStruct(c *C) { func (s *GoesTestSuite) TestIndexWithFieldsNotInMapOrStruct(c *C) {
indexName := "testindexwithfieldsnotinmaporstruct" indexName := "testindexwithfieldsnotinmaporstruct"
docType := "tweet" docType := "tweet"
docId := "1234"
docID := "1234"


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
// just in case // just in case
conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)


@@ -427,7 +427,7 @@ func (s *GoesTestSuite) TestIndexWithFieldsNotInMapOrStruct(c *C) {
d := Document{ d := Document{
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Fields: "test", Fields: "test",
} }


@@ -440,9 +440,9 @@ func (s *GoesTestSuite) TestIndexWithFieldsNotInMapOrStruct(c *C) {
func (s *GoesTestSuite) TestIndexIdDefined(c *C) { func (s *GoesTestSuite) TestIndexIdDefined(c *C) {
indexName := "testindexiddefined" indexName := "testindexiddefined"
docType := "tweet" docType := "tweet"
docId := "1234"
docID := "1234"


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
// just in case // just in case
conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)


@@ -453,7 +453,7 @@ func (s *GoesTestSuite) TestIndexIdDefined(c *C) {
d := Document{ d := Document{
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"user": "foo", "user": "foo",
"message": "bar", "message": "bar",
@@ -468,7 +468,7 @@ func (s *GoesTestSuite) TestIndexIdDefined(c *C) {
expectedResponse := &Response{ expectedResponse := &Response{
Status: 201, Status: 201,
Index: indexName, Index: indexName,
Id: docId,
ID: docID,
Type: docType, Type: docType,
Version: 1, Version: 1,
} }
@@ -481,7 +481,7 @@ func (s *GoesTestSuite) TestIndexIdNotDefined(c *C) {
indexName := "testindexidnotdefined" indexName := "testindexidnotdefined"
docType := "tweet" docType := "tweet"


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
// just in case // just in case
conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)


@@ -504,15 +504,15 @@ func (s *GoesTestSuite) TestIndexIdNotDefined(c *C) {
c.Assert(response.Index, Equals, indexName) c.Assert(response.Index, Equals, indexName)
c.Assert(response.Type, Equals, docType) c.Assert(response.Type, Equals, docType)
c.Assert(response.Version, Equals, 1) c.Assert(response.Version, Equals, 1)
c.Assert(response.Id != "", Equals, true)
c.Assert(response.ID != "", Equals, true)
} }


func (s *GoesTestSuite) TestDelete(c *C) { func (s *GoesTestSuite) TestDelete(c *C) {
indexName := "testdelete" indexName := "testdelete"
docType := "tweet" docType := "tweet"
docId := "1234"
docID := "1234"


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
// just in case // just in case
conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)


@@ -523,7 +523,7 @@ func (s *GoesTestSuite) TestDelete(c *C) {
d := Document{ d := Document{
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"user": "foo", "user": "foo",
}, },
@@ -540,7 +540,7 @@ func (s *GoesTestSuite) TestDelete(c *C) {
Found: true, Found: true,
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
// XXX : even after a DELETE the version number seems to be incremented // XXX : even after a DELETE the version number seems to be incremented
Version: 2, Version: 2,
} }
@@ -555,7 +555,7 @@ func (s *GoesTestSuite) TestDelete(c *C) {
Found: false, Found: false,
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
// XXX : even after a DELETE the version number seems to be incremented // XXX : even after a DELETE the version number seems to be incremented
Version: 3, Version: 3,
} }
@@ -566,9 +566,9 @@ func (s *GoesTestSuite) TestDelete(c *C) {
func (s *GoesTestSuite) TestDeleteByQuery(c *C) { func (s *GoesTestSuite) TestDeleteByQuery(c *C) {
indexName := "testdeletebyquery" indexName := "testdeletebyquery"
docType := "tweet" docType := "tweet"
docId := "1234"
docID := "1234"


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
// just in case // just in case
conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)


@@ -579,7 +579,7 @@ func (s *GoesTestSuite) TestDeleteByQuery(c *C) {
d := Document{ d := Document{
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"user": "foo", "user": "foo",
}, },
@@ -617,7 +617,7 @@ func (s *GoesTestSuite) TestDeleteByQuery(c *C) {
Found: false, Found: false,
Index: "", Index: "",
Type: "", Type: "",
Id: "",
ID: "",
Version: 0, Version: 0,
} }
response.Raw = nil response.Raw = nil
@@ -632,13 +632,13 @@ func (s *GoesTestSuite) TestDeleteByQuery(c *C) {
func (s *GoesTestSuite) TestGet(c *C) { func (s *GoesTestSuite) TestGet(c *C) {
indexName := "testget" indexName := "testget"
docType := "tweet" docType := "tweet"
docId := "111"
docID := "111"
source := map[string]interface{}{ source := map[string]interface{}{
"f1": "foo", "f1": "foo",
"f2": "foo", "f2": "foo",
} }


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)


_, err := conn.CreateIndex(indexName, map[string]interface{}{}) _, err := conn.CreateIndex(indexName, map[string]interface{}{})
@@ -648,21 +648,21 @@ func (s *GoesTestSuite) TestGet(c *C) {
d := Document{ d := Document{
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Fields: source, Fields: source,
} }


_, err = conn.Index(d, url.Values{}) _, err = conn.Index(d, url.Values{})
c.Assert(err, IsNil) c.Assert(err, IsNil)


response, err := conn.Get(indexName, docType, docId, url.Values{})
response, err := conn.Get(indexName, docType, docID, url.Values{})
c.Assert(err, IsNil) c.Assert(err, IsNil)


expectedResponse := &Response{ expectedResponse := &Response{
Status: 200, Status: 200,
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Version: 1, Version: 1,
Found: true, Found: true,
Source: source, Source: source,
@@ -673,14 +673,14 @@ func (s *GoesTestSuite) TestGet(c *C) {


fields := make(url.Values, 1) fields := make(url.Values, 1)
fields.Set("fields", "f1") fields.Set("fields", "f1")
response, err = conn.Get(indexName, docType, docId, fields)
response, err = conn.Get(indexName, docType, docID, fields)
c.Assert(err, IsNil) c.Assert(err, IsNil)


expectedResponse = &Response{ expectedResponse = &Response{
Status: 200, Status: 200,
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Version: 1, Version: 1,
Found: true, Found: true,
Fields: map[string]interface{}{ Fields: map[string]interface{}{
@@ -695,13 +695,13 @@ func (s *GoesTestSuite) TestGet(c *C) {
func (s *GoesTestSuite) TestSearch(c *C) { func (s *GoesTestSuite) TestSearch(c *C) {
indexName := "testsearch" indexName := "testsearch"
docType := "tweet" docType := "tweet"
docId := "1234"
docID := "1234"
source := map[string]interface{}{ source := map[string]interface{}{
"user": "foo", "user": "foo",
"message": "bar", "message": "bar",
} }


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)


_, err := conn.CreateIndex(indexName, map[string]interface{}{}) _, err := conn.CreateIndex(indexName, map[string]interface{}{})
@@ -711,7 +711,7 @@ func (s *GoesTestSuite) TestSearch(c *C) {
d := Document{ d := Document{
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Fields: source, Fields: source,
} }


@@ -733,7 +733,7 @@ func (s *GoesTestSuite) TestSearch(c *C) {
}, },
}, },
} }
response, err := conn.Search(query, []string{indexName}, []string{docType}, url.Values{})
response, _ := conn.Search(query, []string{indexName}, []string{docType}, url.Values{})


expectedHits := Hits{ expectedHits := Hits{
Total: 1, Total: 1,
@@ -742,7 +742,7 @@ func (s *GoesTestSuite) TestSearch(c *C) {
{ {
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Score: 1.0, Score: 1.0,
Source: source, Source: source,
}, },
@@ -755,13 +755,13 @@ func (s *GoesTestSuite) TestSearch(c *C) {
func (s *GoesTestSuite) TestCount(c *C) { func (s *GoesTestSuite) TestCount(c *C) {
indexName := "testcount" indexName := "testcount"
docType := "tweet" docType := "tweet"
docId := "1234"
docID := "1234"
source := map[string]interface{}{ source := map[string]interface{}{
"user": "foo", "user": "foo",
"message": "bar", "message": "bar",
} }


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)


_, err := conn.CreateIndex(indexName, map[string]interface{}{}) _, err := conn.CreateIndex(indexName, map[string]interface{}{})
@@ -771,7 +771,7 @@ func (s *GoesTestSuite) TestCount(c *C) {
d := Document{ d := Document{
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Fields: source, Fields: source,
} }


@@ -793,14 +793,14 @@ func (s *GoesTestSuite) TestCount(c *C) {
}, },
}, },
} }
response, err := conn.Count(query, []string{indexName}, []string{docType}, url.Values{})
response, _ := conn.Count(query, []string{indexName}, []string{docType}, url.Values{})


c.Assert(response.Count, Equals, 1) c.Assert(response.Count, Equals, 1)
} }


func (s *GoesTestSuite) TestIndexStatus(c *C) { func (s *GoesTestSuite) TestIndexStatus(c *C) {
indexName := "testindexstatus" indexName := "testindexstatus"
conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)


mapping := map[string]interface{}{ mapping := map[string]interface{}{
@@ -876,10 +876,10 @@ func (s *GoesTestSuite) TestScroll(c *C) {


tweets := []Document{ tweets := []Document{
{ {
Id: nil,
ID: nil,
Index: indexName, Index: indexName,
Type: docType, Type: docType,
BulkCommand: BULK_COMMAND_INDEX,
BulkCommand: BulkCommandIndex,
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"user": "foo", "user": "foo",
"message": "some foo message", "message": "some foo message",
@@ -887,10 +887,10 @@ func (s *GoesTestSuite) TestScroll(c *C) {
}, },


{ {
Id: nil,
ID: nil,
Index: indexName, Index: indexName,
Type: docType, Type: docType,
BulkCommand: BULK_COMMAND_INDEX,
BulkCommand: BulkCommandIndex,
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"user": "bar", "user": "bar",
"message": "some bar message", "message": "some bar message",
@@ -898,10 +898,10 @@ func (s *GoesTestSuite) TestScroll(c *C) {
}, },


{ {
Id: nil,
ID: nil,
Index: indexName, Index: indexName,
Type: docType, Type: docType,
BulkCommand: BULK_COMMAND_INDEX,
BulkCommand: BulkCommandIndex,
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"user": "foo", "user": "foo",
"message": "another foo message", "message": "another foo message",
@@ -909,7 +909,7 @@ func (s *GoesTestSuite) TestScroll(c *C) {
}, },
} }


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)


mapping := map[string]interface{}{ mapping := map[string]interface{}{
"settings": map[string]interface{}{ "settings": map[string]interface{}{
@@ -943,30 +943,30 @@ func (s *GoesTestSuite) TestScroll(c *C) {


scan, err := conn.Scan(query, []string{indexName}, []string{docType}, "1m", 1) scan, err := conn.Scan(query, []string{indexName}, []string{docType}, "1m", 1)
c.Assert(err, IsNil) c.Assert(err, IsNil)
c.Assert(len(scan.ScrollId) > 0, Equals, true)
c.Assert(len(scan.ScrollID) > 0, Equals, true)


searchResults, err := conn.Scroll(scan.ScrollId, "1m")
searchResults, err := conn.Scroll(scan.ScrollID, "1m")
c.Assert(err, IsNil) c.Assert(err, IsNil)


// some data in first chunk // some data in first chunk
c.Assert(searchResults.Hits.Total, Equals, uint64(2)) c.Assert(searchResults.Hits.Total, Equals, uint64(2))
c.Assert(len(searchResults.ScrollId) > 0, Equals, true)
c.Assert(len(searchResults.ScrollID) > 0, Equals, true)
c.Assert(len(searchResults.Hits.Hits), Equals, 1) c.Assert(len(searchResults.Hits.Hits), Equals, 1)


searchResults, err = conn.Scroll(searchResults.ScrollId, "1m")
searchResults, err = conn.Scroll(searchResults.ScrollID, "1m")
c.Assert(err, IsNil) c.Assert(err, IsNil)


// more data in second chunk // more data in second chunk
c.Assert(searchResults.Hits.Total, Equals, uint64(2)) c.Assert(searchResults.Hits.Total, Equals, uint64(2))
c.Assert(len(searchResults.ScrollId) > 0, Equals, true)
c.Assert(len(searchResults.ScrollID) > 0, Equals, true)
c.Assert(len(searchResults.Hits.Hits), Equals, 1) c.Assert(len(searchResults.Hits.Hits), Equals, 1)


searchResults, err = conn.Scroll(searchResults.ScrollId, "1m")
searchResults, err = conn.Scroll(searchResults.ScrollID, "1m")
c.Assert(err, IsNil) c.Assert(err, IsNil)


// nothing in third chunk // nothing in third chunk
c.Assert(searchResults.Hits.Total, Equals, uint64(2)) c.Assert(searchResults.Hits.Total, Equals, uint64(2))
c.Assert(len(searchResults.ScrollId) > 0, Equals, true)
c.Assert(len(searchResults.ScrollID) > 0, Equals, true)
c.Assert(len(searchResults.Hits.Hits), Equals, 0) c.Assert(len(searchResults.Hits.Hits), Equals, 0)
} }


@@ -976,10 +976,10 @@ func (s *GoesTestSuite) TestAggregations(c *C) {


tweets := []Document{ tweets := []Document{
{ {
Id: nil,
ID: nil,
Index: indexName, Index: indexName,
Type: docType, Type: docType,
BulkCommand: BULK_COMMAND_INDEX,
BulkCommand: BulkCommandIndex,
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"user": "foo", "user": "foo",
"message": "some foo message", "message": "some foo message",
@@ -988,10 +988,10 @@ func (s *GoesTestSuite) TestAggregations(c *C) {
}, },


{ {
Id: nil,
ID: nil,
Index: indexName, Index: indexName,
Type: docType, Type: docType,
BulkCommand: BULK_COMMAND_INDEX,
BulkCommand: BulkCommandIndex,
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"user": "bar", "user": "bar",
"message": "some bar message", "message": "some bar message",
@@ -1000,10 +1000,10 @@ func (s *GoesTestSuite) TestAggregations(c *C) {
}, },


{ {
Id: nil,
ID: nil,
Index: indexName, Index: indexName,
Type: docType, Type: docType,
BulkCommand: BULK_COMMAND_INDEX,
BulkCommand: BulkCommandIndex,
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"user": "foo", "user": "foo",
"message": "another foo message", "message": "another foo message",
@@ -1011,7 +1011,7 @@ func (s *GoesTestSuite) TestAggregations(c *C) {
}, },
} }


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)


mapping := map[string]interface{}{ mapping := map[string]interface{}{
"settings": map[string]interface{}{ "settings": map[string]interface{}{
@@ -1056,7 +1056,7 @@ func (s *GoesTestSuite) TestAggregations(c *C) {
}, },
} }


resp, err := conn.Search(query, []string{indexName}, []string{docType}, url.Values{})
resp, _ := conn.Search(query, []string{indexName}, []string{docType}, url.Values{})


user, ok := resp.Aggregations["user"] user, ok := resp.Aggregations["user"]
c.Assert(ok, Equals, true) c.Assert(ok, Equals, true)
@@ -1084,7 +1084,7 @@ func (s *GoesTestSuite) TestPutMapping(c *C) {
indexName := "testputmapping" indexName := "testputmapping"
docType := "tweet" docType := "tweet"


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
// just in case // just in case
conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)


@@ -1125,7 +1125,7 @@ func (s *GoesTestSuite) TestPutMapping(c *C) {
func (s *GoesTestSuite) TestIndicesExist(c *C) { func (s *GoesTestSuite) TestIndicesExist(c *C) {
indices := []string{"testindicesexist"} indices := []string{"testindicesexist"}


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
// just in case // just in case
conn.DeleteIndex(indices[0]) conn.DeleteIndex(indices[0])


@@ -1137,20 +1137,20 @@ func (s *GoesTestSuite) TestIndicesExist(c *C) {
defer conn.DeleteIndex(indices[0]) defer conn.DeleteIndex(indices[0])
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)


exists, err = conn.IndicesExist(indices)
exists, _ = conn.IndicesExist(indices)
c.Assert(exists, Equals, true) c.Assert(exists, Equals, true)


indices = append(indices, "nonexistent") indices = append(indices, "nonexistent")
exists, err = conn.IndicesExist(indices)
exists, _ = conn.IndicesExist(indices)
c.Assert(exists, Equals, false) c.Assert(exists, Equals, false)
} }


func (s *GoesTestSuite) TestUpdate(c *C) { func (s *GoesTestSuite) TestUpdate(c *C) {
indexName := "testupdate" indexName := "testupdate"
docType := "tweet" docType := "tweet"
docId := "1234"
docID := "1234"


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
// just in case // just in case
conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)


@@ -1161,7 +1161,7 @@ func (s *GoesTestSuite) TestUpdate(c *C) {
d := Document{ d := Document{
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Fields: map[string]interface{}{ Fields: map[string]interface{}{
"user": "foo", "user": "foo",
"message": "bar", "message": "bar",
@@ -1177,7 +1177,7 @@ func (s *GoesTestSuite) TestUpdate(c *C) {
expectedResponse := &Response{ expectedResponse := &Response{
Status: 201, Status: 201,
Index: indexName, Index: indexName,
Id: docId,
ID: docID,
Type: docType, Type: docType,
Version: 1, Version: 1,
} }
@@ -1208,20 +1208,20 @@ func (s *GoesTestSuite) TestUpdate(c *C) {


c.Assert(err, Equals, nil) c.Assert(err, Equals, nil)


response, err = conn.Get(indexName, docType, docId, url.Values{})
response, err = conn.Get(indexName, docType, docID, url.Values{})
c.Assert(err, Equals, nil) c.Assert(err, Equals, nil)
c.Assert(response.Source["counter"], Equals, float64(6)) c.Assert(response.Source["counter"], Equals, float64(6))
c.Assert(response.Source["user"], Equals, "foo") c.Assert(response.Source["user"], Equals, "foo")
c.Assert(response.Source["message"], Equals, "bar") c.Assert(response.Source["message"], Equals, "bar")


// Test another document, non-existent // Test another document, non-existent
docId = "555"
d.Id = docId
docID = "555"
d.ID = docID
response, err = conn.Update(d, query, extraArgs) response, err = conn.Update(d, query, extraArgs)
c.Assert(err, Equals, nil) c.Assert(err, Equals, nil)
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)


response, err = conn.Get(indexName, docType, docId, url.Values{})
response, err = conn.Get(indexName, docType, docID, url.Values{})
c.Assert(err, Equals, nil) c.Assert(err, Equals, nil)
c.Assert(response.Source["user"], Equals, "admin") c.Assert(response.Source["user"], Equals, "admin")
c.Assert(response.Source["message"], Equals, "candybar") c.Assert(response.Source["message"], Equals, "candybar")
@@ -1231,7 +1231,7 @@ func (s *GoesTestSuite) TestGetMapping(c *C) {
indexName := "testmapping" indexName := "testmapping"
docType := "tweet" docType := "tweet"


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
// just in case // just in case
conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)


@@ -1267,7 +1267,7 @@ func (s *GoesTestSuite) TestDeleteMapping(c *C) {
indexName := "testdeletemapping" indexName := "testdeletemapping"
docType := "tweet" docType := "tweet"


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
// just in case // just in case
conn.DeleteIndex(indexName) conn.DeleteIndex(indexName)


@@ -1313,13 +1313,13 @@ func (s *GoesTestSuite) TestAddAlias(c *C) {
aliasName := "testAlias" aliasName := "testAlias"
indexName := "testalias_1" indexName := "testalias_1"
docType := "testDoc" docType := "testDoc"
docId := "1234"
docID := "1234"
source := map[string]interface{}{ source := map[string]interface{}{
"user": "foo", "user": "foo",
"message": "bar", "message": "bar",
} }


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
defer conn.DeleteIndex(indexName) defer conn.DeleteIndex(indexName)


_, err := conn.CreateIndex(indexName, map[string]interface{}{}) _, err := conn.CreateIndex(indexName, map[string]interface{}{})
@@ -1329,7 +1329,7 @@ func (s *GoesTestSuite) TestAddAlias(c *C) {
d := Document{ d := Document{
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Fields: source, Fields: source,
} }


@@ -1342,14 +1342,14 @@ func (s *GoesTestSuite) TestAddAlias(c *C) {
c.Assert(err, IsNil) c.Assert(err, IsNil)


// Get document via alias // Get document via alias
response, err := conn.Get(aliasName, docType, docId, url.Values{})
response, err := conn.Get(aliasName, docType, docID, url.Values{})
c.Assert(err, IsNil) c.Assert(err, IsNil)


expectedResponse := &Response{ expectedResponse := &Response{
Status: 200, Status: 200,
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Version: 1, Version: 1,
Found: true, Found: true,
Source: source, Source: source,
@@ -1363,13 +1363,13 @@ func (s *GoesTestSuite) TestRemoveAlias(c *C) {
aliasName := "testAlias" aliasName := "testAlias"
indexName := "testalias_1" indexName := "testalias_1"
docType := "testDoc" docType := "testDoc"
docId := "1234"
docID := "1234"
source := map[string]interface{}{ source := map[string]interface{}{
"user": "foo", "user": "foo",
"message": "bar", "message": "bar",
} }


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
defer conn.DeleteIndex(indexName) defer conn.DeleteIndex(indexName)


_, err := conn.CreateIndex(indexName, map[string]interface{}{}) _, err := conn.CreateIndex(indexName, map[string]interface{}{})
@@ -1379,7 +1379,7 @@ func (s *GoesTestSuite) TestRemoveAlias(c *C) {
d := Document{ d := Document{
Index: indexName, Index: indexName,
Type: docType, Type: docType,
Id: docId,
ID: docID,
Fields: source, Fields: source,
} }


@@ -1396,7 +1396,7 @@ func (s *GoesTestSuite) TestRemoveAlias(c *C) {
c.Assert(err, IsNil) c.Assert(err, IsNil)


// Get document via alias // Get document via alias
_, err = conn.Get(aliasName, docType, docId, url.Values{})
_, err = conn.Get(aliasName, docType, docID, url.Values{})
c.Assert(err.Error(), Equals, "[404] IndexMissingException[["+aliasName+"] missing]") c.Assert(err.Error(), Equals, "[404] IndexMissingException[["+aliasName+"] missing]")
} }


@@ -1404,7 +1404,7 @@ func (s *GoesTestSuite) TestAliasExists(c *C) {
index := "testaliasexist_1" index := "testaliasexist_1"
alias := "testaliasexists" alias := "testaliasexists"


conn := NewClient(ES_HOST, ES_PORT)
conn := NewClient(ESHost, ESPort)
// just in case // just in case
conn.DeleteIndex(index) conn.DeleteIndex(index)


@@ -1421,6 +1421,6 @@ func (s *GoesTestSuite) TestAliasExists(c *C) {
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
defer conn.RemoveAlias(alias, []string{index}) defer conn.RemoveAlias(alias, []string{index})


exists, err = conn.AliasExists(alias)
exists, _ = conn.AliasExists(alias)
c.Assert(exists, Equals, true) c.Assert(exists, Equals, true)
} }

+ 8
- 5
structs.go View File

@@ -66,7 +66,7 @@ type Response struct {
Shards Shard `json:"_shards"` Shards Shard `json:"_shards"`
Hits Hits Hits Hits
Index string `json:"_index"` Index string `json:"_index"`
Id string `json:"_id"`
ID string `json:"_id"`
Type string `json:"_type"` Type string `json:"_type"`
Version int `json:"_version"` Version int `json:"_version"`
Found bool Found bool
@@ -86,7 +86,7 @@ type Response struct {
Indices map[string]IndexStatus Indices map[string]IndexStatus


// Scroll id for iteration // Scroll id for iteration
ScrollId string `json:"_scroll_id"`
ScrollID string `json:"_scroll_id"`


Aggregations map[string]Aggregation `json:"aggregations,omitempty"` Aggregations map[string]Aggregation `json:"aggregations,omitempty"`


@@ -104,7 +104,7 @@ type Document struct {
// XXX : interface as we can support nil values // XXX : interface as we can support nil values
Index interface{} Index interface{}
Type string Type string
Id interface{}
ID interface{}
BulkCommand string BulkCommand string
Fields interface{} Fields interface{}
} }
@@ -112,7 +112,7 @@ type Document struct {
// Item holds an item from the "items" field in a _bulk response // Item holds an item from the "items" field in a _bulk response
type Item struct { type Item struct {
Type string `json:"_type"` Type string `json:"_type"`
Id string `json:"_id"`
ID string `json:"_id"`
Index string `json:"_index"` Index string `json:"_index"`
Version int `json:"_version"` Version int `json:"_version"`
Error string `json:"error"` Error string `json:"error"`
@@ -126,10 +126,12 @@ type All struct {
Primaries map[string]StatPrimary `json:"primaries"` Primaries map[string]StatPrimary `json:"primaries"`
} }


// StatIndex contains stats for a specific index
type StatIndex struct { type StatIndex struct {
Primaries map[string]StatPrimary `json:"primaries"` Primaries map[string]StatPrimary `json:"primaries"`
} }


// StatPrimary contains stats for a primary index
type StatPrimary struct { type StatPrimary struct {
// primary/docs: // primary/docs:
Count int Count int
@@ -147,7 +149,7 @@ type Shard struct {
type Hit struct { type Hit struct {
Index string `json:"_index"` Index string `json:"_index"`
Type string `json:"_type"` Type string `json:"_type"`
Id string `json:"_id"`
ID string `json:"_id"`
Score float64 `json:"_score"` Score float64 `json:"_score"`
Source map[string]interface{} `json:"_source"` Source map[string]interface{} `json:"_source"`
Highlight map[string]interface{} `json:"highlight"` Highlight map[string]interface{} `json:"highlight"`
@@ -162,6 +164,7 @@ type Hits struct {
Hits []Hit Hits []Hit
} }


// SearchError holds errors returned from an ES search
type SearchError struct { type SearchError struct {
Msg string Msg string
StatusCode uint64 StatusCode uint64


Loading…
Cancel
Save