search_aggs_pipeline_bucket_selector_test.go 811 B

1234567891011121314151617181920212223242526272829
  1. // Copyright 2012-present Oliver Eilhard. All rights reserved.
  2. // Use of this source code is governed by a MIT-license.
  3. // See http://olivere.mit-license.org/license.txt for details.
  4. package elastic
  5. import (
  6. "encoding/json"
  7. "testing"
  8. )
  9. func TestBucketSelectorAggregation(t *testing.T) {
  10. agg := NewBucketSelectorAggregation().
  11. AddBucketsPath("totalSales", "total_sales").
  12. Script(NewScript("totalSales >= 1000"))
  13. src, err := agg.Source()
  14. if err != nil {
  15. t.Fatal(err)
  16. }
  17. data, err := json.Marshal(src)
  18. if err != nil {
  19. t.Fatalf("marshaling to JSON failed: %v", err)
  20. }
  21. got := string(data)
  22. expected := `{"bucket_selector":{"buckets_path":{"totalSales":"total_sales"},"script":{"inline":"totalSales \u003e= 1000"}}}`
  23. if got != expected {
  24. t.Errorf("expected\n%s\n,got:\n%s", expected, got)
  25. }
  26. }