search_aggs_bucket_diversified_sampler_test.go 887 B

12345678910111213141516171819202122232425262728293031
  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 TestDiversifiedSamplerAggregation(t *testing.T) {
  10. keywordsAgg := NewSignificantTermsAggregation().Field("text")
  11. agg := NewDiversifiedSamplerAggregation().
  12. ShardSize(200).
  13. Field("author").
  14. SubAggregation("keywords", keywordsAgg)
  15. src, err := agg.Source()
  16. if err != nil {
  17. t.Fatal(err)
  18. }
  19. data, err := json.Marshal(src)
  20. if err != nil {
  21. t.Fatalf("marshaling to JSON failed: %v", err)
  22. }
  23. got := string(data)
  24. expected := `{"aggregations":{"keywords":{"significant_terms":{"field":"text"}}},"diversified_sampler":{"field":"author","shard_size":200}}`
  25. if got != expected {
  26. t.Errorf("expected\n%s\n,got:\n%s", expected, got)
  27. }
  28. }