Complete the code to search all documents in the index.
GET /my-index/_search
{
"[1]": {
"match_all": {}
}
}filter instead of query causes no results.sort or aggs in place of query causes errors.The query key is used to specify the search criteria. Using match_all inside query returns all documents.
Complete the code to return only the first 5 documents.
GET /my-index/_search
{
"size": [1],
"query": { "match_all": {} }
}size to 0 returns no documents.The size parameter controls how many documents are returned. Setting it to 5 returns the first five documents.
Fix the error in the query to filter documents where the field 'status' is 'active'.
GET /my-index/_search
{
"query": {
"term": { "[1]": "active" }
}
}The term query requires the exact field name. Here, the field is status, so it must be used as the key.
Fill both blanks to sort documents by 'timestamp' in descending order.
GET /my-index/_search
{
"sort": [
{ "[1]": { "order": "[2]" } }
]
}date instead of timestamp if the field is named differently.asc instead of desc to get newest first.Sorting requires the field name and the order. Here, sorting by timestamp in desc order shows newest documents first.
Fill all three blanks to aggregate the average 'price' of products where 'category' is 'books'.
GET /my-index/_search
{
"query": {
"term": { "[1]": "books" }
},
"aggs": {
"average_price": { "avg": { "field": "[2]" } }
},
"size": [3]
}size to a positive number shows documents instead of only aggregation.The term query filters by category 'books'. The aggregation calculates the average of the price field. Setting size to 0 hides document hits, showing only aggregation results.