From 58075eeb3554c28cd86263ecc5ca2520a5bcb49d Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Tue, 23 Jun 2015 13:54:16 -0500 Subject: [PATCH 01/12] Use interface{} so any JSON-encodable value can be passed in --- goes.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/goes.go b/goes.go index 5637228..d889d93 100644 --- a/goes.go +++ b/goes.go @@ -41,7 +41,7 @@ func (c *Connection) WithClient(cl *http.Client) *Connection { } // 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{ Conn: c, Query: mapping, @@ -196,7 +196,7 @@ func (c *Connection) BulkSend(documents []Document) (Response, error) { } // 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{ Conn: c, 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 -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{ Conn: c, 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. //This method can be used to execute a delete by query, just pass in "DELETE" //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{ Conn: c, Query: query, @@ -243,7 +243,7 @@ func (c *Connection) Query(query map[string]interface{}, indexList []string, typ } // 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.Add("search_type", "scan") v.Add("scroll", timeout) @@ -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 -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{ Conn: c, @@ -498,7 +498,7 @@ func (c *Connection) IndicesExist(indexes []string) (bool, error) { 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{ Conn: c, Query: query, From 7a434d562fbfba6ca9522942df589220cc671049 Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Tue, 23 Jun 2015 14:21:03 -0500 Subject: [PATCH 02/12] Call _refresh to ensure index is refreshed before getting the status --- goes_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/goes_test.go b/goes_test.go index 3334d30..944205b 100644 --- a/goes_test.go +++ b/goes_test.go @@ -5,13 +5,14 @@ package goes import ( - . "gopkg.in/check.v1" "net/http" "net/url" "os" "strings" "testing" "time" + + . "gopkg.in/check.v1" ) var ( @@ -787,6 +788,8 @@ func (s *GoesTestSuite) TestIndexStatus(c *C) { // gives ES some time to do its job time.Sleep(1 * time.Second) + _, err = conn.RefreshIndex(indexName) + c.Assert(err, IsNil) response, err := conn.IndexStatus([]string{"testindexstatus"}) c.Assert(err, IsNil) From 2372cfaf30df053f0bf282ef57c1cf6b5f2a62b0 Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Tue, 23 Jun 2015 14:45:45 -0500 Subject: [PATCH 03/12] Set content-type to application/json, since that's what is being passed to ElasticSearch --- goes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/goes.go b/goes.go index 5637228..0cf0471 100644 --- a/goes.go +++ b/goes.go @@ -354,7 +354,7 @@ func (req *Request) Run() (Response, error) { } 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) From 538861b257989a5b4a0a089e1ee3f025f8d0920b Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Tue, 23 Jun 2015 17:54:45 -0500 Subject: [PATCH 04/12] Update ES and Go versions in the matrix --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 18e7b30..f02a429 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ go: - 1.1 - 1.2 - 1.3 + - 1.4.2 - tip env: @@ -11,10 +12,14 @@ env: - ES_VERSION=1.0.3 - ES_VERSION=1.1.2 - ES_VERSION=1.2.1 + - ES_VERSION=1.3.4 + - ES_VERSION=1.4.4 + - ES_VERSION=1.5.2 + - ES_VERSION=1.6.0 before_script: - 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 - ${HOME}/elasticsearch/elasticsearch-${ES_VERSION}/bin/elasticsearch >/dev/null & From c4704e7261f5c52f386ba948aea1261625e0be19 Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Tue, 23 Jun 2015 17:57:44 -0500 Subject: [PATCH 05/12] Missing dollar sign --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f02a429..a0655f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ env: before_script: - mkdir ${HOME}/elasticsearch - - wget https://download.elastic.co/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 - ${HOME}/elasticsearch/elasticsearch-${ES_VERSION}/bin/elasticsearch >/dev/null & From bf23e36aa24ebd420b551513798c3cdffc9f38d0 Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Tue, 23 Jun 2015 18:21:38 -0500 Subject: [PATCH 06/12] Enable ES groovy sandbox --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a0655f3..931aeb5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,7 @@ before_script: - mkdir ${HOME}/elasticsearch - wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz - tar -xzf elasticsearch-${ES_VERSION}.tar.gz -C ${HOME}/elasticsearch + - echo 'script.groovy.sandbox.enabled: true' >> ${HOME}/elasticsearch/elasticsearch-${ES_VERSION}/config/elasticsearch.yml - ${HOME}/elasticsearch/elasticsearch-${ES_VERSION}/bin/elasticsearch >/dev/null & install: From 51df70436b75df923207270eb192318aefd5ce9b Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Wed, 24 Jun 2015 09:21:06 -0500 Subject: [PATCH 07/12] Wrap command in quotes so it is treated as a single command --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 931aeb5..91aecf3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ before_script: - mkdir ${HOME}/elasticsearch - wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz - tar -xzf elasticsearch-${ES_VERSION}.tar.gz -C ${HOME}/elasticsearch - - echo 'script.groovy.sandbox.enabled: true' >> ${HOME}/elasticsearch/elasticsearch-${ES_VERSION}/config/elasticsearch.yml + - "echo 'script.groovy.sandbox.enabled: true' >> ${HOME}/elasticsearch/elasticsearch-${ES_VERSION}/config/elasticsearch.yml" - ${HOME}/elasticsearch/elasticsearch-${ES_VERSION}/bin/elasticsearch >/dev/null & install: From 953759da481b990c98006a64017d3d4cc4096399 Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Wed, 24 Jun 2015 10:32:01 -0500 Subject: [PATCH 08/12] Handle variance in refresh count between ES versions --- goes_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/goes_test.go b/goes_test.go index 944205b..868b5fe 100644 --- a/goes_test.go +++ b/goes_test.go @@ -799,9 +799,11 @@ func (s *GoesTestSuite) TestIndexStatus(c *C) { primarySizeInBytes := response.Indices[indexName].Index["primary_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(sizeInBytes > 0, Equals, true) + c.Assert(refreshTotal > 0, Equals, true) expectedIndices := map[string]IndexStatus{ indexName: { @@ -827,7 +829,7 @@ func (s *GoesTestSuite) TestIndexStatus(c *C) { "total_size_in_bytes": float64(0), }, Refresh: map[string]interface{}{ - "total": float64(1), + "total": refreshTotal, "total_time_in_millis": float64(0), }, Flush: map[string]interface{}{ From 06c82c2420736558ed6f4e97cbc4f550ff6c45a4 Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Wed, 24 Jun 2015 13:56:01 -0500 Subject: [PATCH 09/12] Select scripting lang as groovy for older ES versions --- goes_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/goes_test.go b/goes_test.go index 868b5fe..704783e 100644 --- a/goes_test.go +++ b/goes_test.go @@ -1159,6 +1159,7 @@ func (s *GoesTestSuite) TestUpdate(c *C) { // Now that we have an ordinary document indexed, try updating it query := map[string]interface{}{ "script": "ctx._source.counter += count", + "lang": "groovy", "params": map[string]interface{}{ "count": 5, }, @@ -1170,7 +1171,7 @@ func (s *GoesTestSuite) TestUpdate(c *C) { } 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") return } From f41e425728461e05ac28f760a0e264abb9b26418 Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Wed, 24 Jun 2015 14:23:04 -0500 Subject: [PATCH 10/12] Make sure groovy is installed for older ES versions --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 91aecf3..3e6c705 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,7 @@ before_script: - wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz - 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 lang-groovy; fi' - ${HOME}/elasticsearch/elasticsearch-${ES_VERSION}/bin/elasticsearch >/dev/null & install: From 00b9bbc858251e74d2cd4a1c23dc6d4376423a18 Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Wed, 24 Jun 2015 16:27:37 -0500 Subject: [PATCH 11/12] Use correct comparison brackets --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3e6c705..b978ba4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ before_script: - wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz - 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 lang-groovy; fi' + - 'if [[ "${ES_VERSION}" < "1.3" ]]; then ${HOME}/elasticsearch/elasticsearch-${ES_VERSION}/bin/plugin --install lang-groovy; fi' - ${HOME}/elasticsearch/elasticsearch-${ES_VERSION}/bin/elasticsearch >/dev/null & install: From 2f906c980ed589a60c4d11d726132e27db77976e Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Wed, 24 Jun 2015 18:44:13 -0500 Subject: [PATCH 12/12] Different groovy plugin versions depending on ES version --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index b978ba4..9fd3745 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,9 @@ go: env: matrix: - - ES_VERSION=1.0.3 - - ES_VERSION=1.1.2 - - ES_VERSION=1.2.1 + - ES_VERSION=1.0.3 GROOVY_VER=2.0.0 + - ES_VERSION=1.1.2 GROOVY_VER=2.0.0 + - 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 @@ -22,7 +22,7 @@ before_script: - wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz - 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 lang-groovy; fi' + - '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 & install: