2020-10-17 19:42:50 +00:00
|
|
|
package esquery
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestFilterAggs(t *testing.T) {
|
|
|
|
runMapTests(t, []mapTest{
|
|
|
|
{
|
|
|
|
"filter agg: simple",
|
2020-10-17 19:46:37 +00:00
|
|
|
FilterAgg("filtered", Term("type", "t-shirt")),
|
2020-10-17 19:42:50 +00:00
|
|
|
map[string]interface{}{
|
|
|
|
"filter": map[string]interface{}{
|
2020-10-17 19:46:37 +00:00
|
|
|
"term": map[string]interface{}{
|
|
|
|
"type": map[string]interface{}{
|
2020-10-17 19:42:50 +00:00
|
|
|
"value": "t-shirt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"filter agg: with aggs",
|
2020-10-17 19:46:37 +00:00
|
|
|
FilterAgg("filtered", Term("type", "t-shirt")).
|
|
|
|
Aggs(Avg("avg_price", "price")),
|
2020-10-17 19:42:50 +00:00
|
|
|
map[string]interface{}{
|
|
|
|
"filter": map[string]interface{}{
|
2020-10-17 19:46:37 +00:00
|
|
|
"term": map[string]interface{}{
|
|
|
|
"type": map[string]interface{}{
|
2020-10-17 19:42:50 +00:00
|
|
|
"value": "t-shirt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-10-17 19:46:37 +00:00
|
|
|
"aggs": map[string]interface{}{
|
|
|
|
"avg_price": map[string]interface{}{
|
2020-10-17 19:42:50 +00:00
|
|
|
"avg": map[string]interface{}{
|
|
|
|
"field": "price",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|