search_aggs_date_histogram_test.go 676 B

1234567891011121314151617181920212223
  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 TestDateHistogramAggregation(t *testing.T) {
  10. agg := NewDateHistogramAggregation().Field("date").Interval("month").Format("YYYY-MM")
  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 := `{"date_histogram":{"field":"date","format":"YYYY-MM","interval":"month"}}`
  17. if got != expected {
  18. t.Errorf("expected\n%s\n,got:\n%s", expected, got)
  19. }
  20. }