Skip to content

Commit

Permalink
Fix scripting tests
Browse files Browse the repository at this point in the history
The parameters now need a `params.` prefix before the variable name.
  • Loading branch information
olivere committed Sep 23, 2016
1 parent eec6868 commit eb03ee7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
5 changes: 2 additions & 3 deletions bulk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import (
)

func TestBulk(t *testing.T) {
// client := setupTestClientAndCreateIndex(t, SetTraceLog(log.New(os.Stdout, "", log.LstdFlags)))
client := setupTestClientAndCreateIndex(t)
client := setupTestClientAndCreateIndex(t) //, SetTraceLog(log.New(os.Stdout, "", 0)))

tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
tweet2 := tweet{User: "sandrae", Message: "Dancing all night long. Yeah."}
Expand Down Expand Up @@ -113,7 +112,7 @@ func TestBulk(t *testing.T) {
// Update with script
update2Req := NewBulkUpdateRequest().Index(testIndexName).Type("tweet").Id("2").
RetryOnConflict(3).
Script(NewScript("ctx._source.retweets += v").Param("v", 1))
Script(NewScript("ctx._source.retweets += params.v").Param("v", 1))
bulkRequest = client.Bulk()
bulkRequest = bulkRequest.Add(update2Req)
if bulkRequest.NumberOfActions() != 1 {
Expand Down
9 changes: 4 additions & 5 deletions search_aggs_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,7 @@ func TestAggsIntegrationCumulativeSum(t *testing.T) {
}

func TestAggsIntegrationBucketScript(t *testing.T) {
//client := setupTestClientAndCreateIndexAndAddDocs(t, SetTraceLog(log.New(os.Stdout, "", log.LstdFlags)))
client := setupTestClientAndCreateIndexAndAddDocs(t)
client := setupTestClientAndCreateIndexAndAddDocs(t) //, SetTraceLog(log.New(os.Stdout, "", log.LstdFlags)))

esversion, err := client.ElasticsearchVersion(DefaultURL)
if err != nil {
Expand Down Expand Up @@ -680,10 +679,10 @@ func TestAggsIntegrationBucketScript(t *testing.T) {
GapPolicy("insert_zeros").
AddBucketsPath("appleSales", "apple_sales>sales").
AddBucketsPath("totalSales", "total_sales").
Script(NewScript("appleSales / totalSales * 100")))
Script(NewScript("params.appleSales / params.totalSales * 100")))
builder = builder.Aggregation("sales_per_month", h)

res, err := builder.Do(context.TODO())
res, err := builder.Pretty(true).Do(context.TODO())
if err != nil {
t.Fatalf("%v (maybe scripting is disabled?)", err)
}
Expand Down Expand Up @@ -833,7 +832,7 @@ func TestAggsIntegrationBucketSelector(t *testing.T) {
h = h.SubAggregation("sales_bucket_filter",
NewBucketSelectorAggregation().
AddBucketsPath("totalSales", "total_sales").
Script(NewScript("totalSales <= 100")))
Script(NewScript("params.totalSales <= 100")))
builder = builder.Aggregation("sales_per_month", h)

res, err := builder.Do(context.TODO())
Expand Down

0 comments on commit eb03ee7

Please sign in to comment.