Test
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

search_aggs_pipeline_percentiles_bucket_test.go 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 TestPercentilesBucketAggregation(t *testing.T) {
  10. agg := NewPercentilesBucketAggregation().BucketsPath("the_sum").GapPolicy("skip")
  11. src, err := agg.Source()
  12. if err != nil {
  13. t.Fatal(err)
  14. }
  15. data, err := json.Marshal(src)
  16. if err != nil {
  17. t.Fatalf("marshaling to JSON failed: %v", err)
  18. }
  19. got := string(data)
  20. expected := `{"percentiles_bucket":{"buckets_path":"the_sum","gap_policy":"skip"}}`
  21. if got != expected {
  22. t.Errorf("expected\n%s\n,got:\n%s", expected, got)
  23. }
  24. }
  25. func TestPercentilesBucketAggregationWithPercents(t *testing.T) {
  26. agg := NewPercentilesBucketAggregation().BucketsPath("the_sum").Percents(0.1, 1.0, 5.0, 25, 50)
  27. src, err := agg.Source()
  28. if err != nil {
  29. t.Fatal(err)
  30. }
  31. data, err := json.Marshal(src)
  32. if err != nil {
  33. t.Fatalf("marshaling to JSON failed: %v", err)
  34. }
  35. got := string(data)
  36. expected := `{"percentiles_bucket":{"buckets_path":"the_sum","percents":[0.1,1,5,25,50]}}`
  37. if got != expected {
  38. t.Errorf("expected\n%s\n,got:\n%s", expected, got)
  39. }
  40. }