Complete the code to create a filter aggregation that matches documents where the field "status" is "active".
{
"aggs": {
"active_users": {
"filter": {
"term": { "status": [1] }
}
}
}
}The filter aggregation uses a term query to match documents where the field status equals "active".
Complete the code to add a filter aggregation that matches documents where the "age" field is greater than 30.
{
"aggs": {
"age_filter": {
"filter": {
"range": { "age": { "[1]": 30 } }
}
}
}
}The range filter uses "gt" to select documents where the field is greater than the given value.
Fix the error in the filter aggregation to correctly filter documents where "category" is "books".
{
"aggs": {
"books_filter": {
"filter": {
"term": { "category": [1] }
}
}
}
}The term query value must be a string enclosed in double quotes in JSON, so "books" is correct.
Fill both blanks to create a filter aggregation that matches documents where "price" is between 10 and 50 inclusive.
{
"aggs": {
"price_range": {
"filter": {
"range": { "price": { [1]: 10, [2]: 50 } }
}
}
}
}Use "gte" for greater than or equal to 10 and "lte" for less than or equal to 50 to include both ends.
Fill all three blanks to create a filter aggregation that matches documents where "tags" contain "python" and the "rating" is greater than 4.
{
"aggs": {
"python_high_rating": {
"filter": {
"bool": {
"must": [
{ "term": { "tags": [1] } },
{ "range": { "rating": { [2]: [3] } } }
]
}
}
}
}
}The term filter matches documents with the tag "python". The range filter uses "gt" to select ratings greater than 4.