Merge branch 'master' of https://github.com/belogik/goes into pointer_response

This commit is contained in:
Paul Bonser 2015-07-14 10:02:38 -05:00
commit 3f6bbaec1f
3 changed files with 26 additions and 14 deletions

View File

@ -4,18 +4,25 @@ go:
- 1.1 - 1.1
- 1.2 - 1.2
- 1.3 - 1.3
- 1.4.2
- tip - tip
env: env:
matrix: matrix:
- ES_VERSION=1.0.3 - ES_VERSION=1.0.3 GROOVY_VER=2.0.0
- ES_VERSION=1.1.2 - ES_VERSION=1.1.2 GROOVY_VER=2.0.0
- ES_VERSION=1.2.1 - ES_VERSION=1.2.1 GROOVY_VER=2.2.0
- ES_VERSION=1.3.4
- ES_VERSION=1.4.4
- ES_VERSION=1.5.2
- ES_VERSION=1.6.0
before_script: before_script:
- mkdir ${HOME}/elasticsearch - mkdir ${HOME}/elasticsearch
- wget http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz - wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz
- tar -xzf elasticsearch-${ES_VERSION}.tar.gz -C ${HOME}/elasticsearch - tar -xzf elasticsearch-${ES_VERSION}.tar.gz -C ${HOME}/elasticsearch
- "echo 'script.groovy.sandbox.enabled: true' >> ${HOME}/elasticsearch/elasticsearch-${ES_VERSION}/config/elasticsearch.yml"
- 'if [[ "${ES_VERSION}" < "1.3" ]]; then ${HOME}/elasticsearch/elasticsearch-${ES_VERSION}/bin/plugin --install elasticsearch/elasticsearch-lang-groovy/${GROOVY_VER}; fi'
- ${HOME}/elasticsearch/elasticsearch-${ES_VERSION}/bin/elasticsearch >/dev/null & - ${HOME}/elasticsearch/elasticsearch-${ES_VERSION}/bin/elasticsearch >/dev/null &
install: install:

16
goes.go
View File

@ -41,7 +41,7 @@ func (c *Connection) WithClient(cl *http.Client) *Connection {
} }
// CreateIndex creates a new index represented by a name and a mapping // CreateIndex creates a new index represented by a name and a mapping
func (c *Connection) CreateIndex(name string, mapping map[string]interface{}) (*Response, error) { func (c *Connection) CreateIndex(name string, mapping interface{}) (*Response, error) {
r := Request{ r := Request{
Conn: c, Conn: c,
Query: mapping, Query: mapping,
@ -196,7 +196,7 @@ func (c *Connection) BulkSend(documents []Document) (*Response, error) {
} }
// Search executes a search query against an index // Search executes a search query against an index
func (c *Connection) Search(query map[string]interface{}, indexList []string, typeList []string, extraArgs url.Values) (*Response, error) { func (c *Connection) Search(query interface{}, indexList []string, typeList []string, extraArgs url.Values) (*Response, error) {
r := Request{ r := Request{
Conn: c, Conn: c,
Query: query, Query: query,
@ -211,7 +211,7 @@ func (c *Connection) Search(query map[string]interface{}, indexList []string, ty
} }
// Count executes a count query against an index, use the Count field in the response for the result // Count executes a count query against an index, use the Count field in the response for the result
func (c *Connection) Count(query map[string]interface{}, indexList []string, typeList []string, extraArgs url.Values) (*Response, error) { func (c *Connection) Count(query interface{}, indexList []string, typeList []string, extraArgs url.Values) (*Response, error) {
r := Request{ r := Request{
Conn: c, Conn: c,
Query: query, Query: query,
@ -228,7 +228,7 @@ func (c *Connection) Count(query map[string]interface{}, indexList []string, typ
//Query runs a query against an index using the provided http method. //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" //This method can be used to execute a delete by query, just pass in "DELETE"
//for the HTTP method. //for the HTTP method.
func (c *Connection) Query(query map[string]interface{}, indexList []string, typeList []string, httpMethod string, extraArgs url.Values) (*Response, error) { func (c *Connection) Query(query interface{}, indexList []string, typeList []string, httpMethod string, extraArgs url.Values) (*Response, error) {
r := Request{ r := Request{
Conn: c, Conn: c,
Query: query, Query: query,
@ -243,7 +243,7 @@ func (c *Connection) Query(query map[string]interface{}, indexList []string, typ
} }
// Scan starts scroll over an index // Scan starts scroll over an index
func (c *Connection) Scan(query map[string]interface{}, indexList []string, typeList []string, timeout string, size int) (*Response, error) { func (c *Connection) Scan(query interface{}, indexList []string, typeList []string, timeout string, size int) (*Response, error) {
v := url.Values{} v := url.Values{}
v.Add("search_type", "scan") v.Add("search_type", "scan")
v.Add("scroll", timeout) v.Add("scroll", timeout)
@ -354,7 +354,7 @@ func (req *Request) Run() (*Response, error) {
} }
if req.method == "POST" || req.method == "PUT" { if req.method == "POST" || req.method == "PUT" {
newReq.Header.Set("Content-Type", "application/x-www-form-urlencoded") newReq.Header.Set("Content-Type", "application/json")
} }
resp, err := req.Conn.Client.Do(newReq) resp, err := req.Conn.Client.Do(newReq)
@ -459,7 +459,7 @@ func (b Bucket) Aggregation(name string) 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
func (c *Connection) PutMapping(typeName string, mapping map[string]interface{}, indexes []string) (*Response, error) { func (c *Connection) PutMapping(typeName string, mapping interface{}, indexes []string) (*Response, error) {
r := Request{ r := Request{
Conn: c, Conn: c,
@ -498,7 +498,7 @@ func (c *Connection) IndicesExist(indexes []string) (bool, error) {
return resp.Status == 200, err return resp.Status == 200, err
} }
func (c *Connection) Update(d Document, query map[string]interface{}, extraArgs url.Values) (*Response, error) { func (c *Connection) Update(d Document, query interface{}, extraArgs url.Values) (*Response, error) {
r := Request{ r := Request{
Conn: c, Conn: c,
Query: query, Query: query,

View File

@ -788,6 +788,8 @@ func (s *GoesTestSuite) TestIndexStatus(c *C) {
// gives ES some time to do its job // gives ES some time to do its job
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
_, err = conn.RefreshIndex(indexName)
c.Assert(err, IsNil)
response, err := conn.IndexStatus([]string{"testindexstatus"}) response, err := conn.IndexStatus([]string{"testindexstatus"})
c.Assert(err, IsNil) c.Assert(err, IsNil)
@ -797,9 +799,11 @@ func (s *GoesTestSuite) TestIndexStatus(c *C) {
primarySizeInBytes := response.Indices[indexName].Index["primary_size_in_bytes"].(float64) primarySizeInBytes := response.Indices[indexName].Index["primary_size_in_bytes"].(float64)
sizeInBytes := response.Indices[indexName].Index["size_in_bytes"].(float64) sizeInBytes := response.Indices[indexName].Index["size_in_bytes"].(float64)
refreshTotal := response.Indices[indexName].Refresh["total"].(float64)
c.Assert(primarySizeInBytes > 0, Equals, true) c.Assert(primarySizeInBytes > 0, Equals, true)
c.Assert(sizeInBytes > 0, Equals, true) c.Assert(sizeInBytes > 0, Equals, true)
c.Assert(refreshTotal > 0, Equals, true)
expectedIndices := map[string]IndexStatus{ expectedIndices := map[string]IndexStatus{
indexName: { indexName: {
@ -825,7 +829,7 @@ func (s *GoesTestSuite) TestIndexStatus(c *C) {
"total_size_in_bytes": float64(0), "total_size_in_bytes": float64(0),
}, },
Refresh: map[string]interface{}{ Refresh: map[string]interface{}{
"total": float64(1), "total": refreshTotal,
"total_time_in_millis": float64(0), "total_time_in_millis": float64(0),
}, },
Flush: map[string]interface{}{ Flush: map[string]interface{}{
@ -1155,6 +1159,7 @@ func (s *GoesTestSuite) TestUpdate(c *C) {
// Now that we have an ordinary document indexed, try updating it // Now that we have an ordinary document indexed, try updating it
query := map[string]interface{}{ query := map[string]interface{}{
"script": "ctx._source.counter += count", "script": "ctx._source.counter += count",
"lang": "groovy",
"params": map[string]interface{}{ "params": map[string]interface{}{
"count": 5, "count": 5,
}, },
@ -1166,7 +1171,7 @@ func (s *GoesTestSuite) TestUpdate(c *C) {
} }
response, err = conn.Update(d, query, extraArgs) response, err = conn.Update(d, query, extraArgs)
if err != nil && strings.Contains(err.(*SearchError).Msg, "dynamic scripting disabled") { if err != nil && strings.Contains(err.(*SearchError).Msg, "dynamic scripting") {
c.Skip("Scripting is disabled on server, skipping this test") c.Skip("Scripting is disabled on server, skipping this test")
return return
} }