forked from olivere/elastic
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsearch_aggs_nested_test.go
More file actions
33 lines (30 loc) · 943 Bytes
/
search_aggs_nested_test.go
File metadata and controls
33 lines (30 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package elastic
import (
"encoding/json"
"testing"
)
func TestNestedAggregation(t *testing.T) {
agg := NewNestedAggregation().Path("resellers")
data, err := json.Marshal(agg.Source())
if err != nil {
t.Fatalf("marshaling to JSON failed: %v", err)
}
got := string(data)
expected := `{"nested":{"path":"resellers"}}`
if got != expected {
t.Errorf("expected\n%s\n,got:\n%s", expected, got)
}
}
func TestNestedAggregationWithSubAggregation(t *testing.T) {
minPriceAgg := NewMinAggregation().Field("resellers.price")
agg := NewNestedAggregation().Path("resellers").SubAggregation("min_price", minPriceAgg)
data, err := json.Marshal(agg.Source())
if err != nil {
t.Fatalf("marshaling to JSON failed: %v", err)
}
got := string(data)
expected := `{"aggregations":{"min_price":{"min":{"field":"resellers.price"}}},"nested":{"path":"resellers"}}`
if got != expected {
t.Errorf("expected\n%s\n,got:\n%s", expected, got)
}
}