search_aggs_value_count_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2012-2015 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 TestValueCountAggregation(t *testing.T) {
  10. agg := NewValueCountAggregation().Field("grade")
  11. data, err := json.Marshal(agg.Source())
  12. if err != nil {
  13. t.Fatalf("marshaling to JSON failed: %v", err)
  14. }
  15. got := string(data)
  16. expected := `{"value_count":{"field":"grade"}}`
  17. if got != expected {
  18. t.Errorf("expected\n%s\n,got:\n%s", expected, got)
  19. }
  20. }
  21. func TestValueCountAggregationWithFormat(t *testing.T) {
  22. // Format comes with 1.5.0+
  23. agg := NewValueCountAggregation().Field("grade").Format("0000.0")
  24. data, err := json.Marshal(agg.Source())
  25. if err != nil {
  26. t.Fatalf("marshaling to JSON failed: %v", err)
  27. }
  28. got := string(data)
  29. expected := `{"value_count":{"field":"grade","format":"0000.0"}}`
  30. if got != expected {
  31. t.Errorf("expected\n%s\n,got:\n%s", expected, got)
  32. }
  33. }