Complete the code to perform a basic match query in Elasticsearch.
{
"query": {
"match": {
"message": "[1]"
}
}
}The match query searches for the term error in the message field.
Complete the code to filter documents where the status is 'active'.
{
"query": {
"bool": {
"filter": {
"term": {
"status": "[1]"
}
}
}
}
}The term filter matches documents where the status field is exactly active.
Fix the error in the aggregation to count documents by user.
{
"aggs": {
"users_count": {
"terms": {
"field": "[1]"
}
}
}
}Aggregations on text fields require the keyword subfield for exact terms. user.keyword is correct.
Fill both blanks to create a range query filtering documents with age between 20 and 30.
{
"query": {
"range": {
"age": {
"gte": [1],
"lte": [2]
}
}
}
}The range query filters documents where age is greater than or equal to 20 and less than or equal to 30.
Fill the two blanks to create a script that calculates a new field 'total' as price times quantity if quantity is greater than 0.
{
"script_fields": {
"total": {
"script": {
"source": "if (doc['quantity'].value [1] 0) { return doc['price'].value [2] doc['quantity'].value; } else { return 0; }"
}
}
}
}The script checks if quantity is greater than 0, then multiplies price by quantity. The operator * is used for multiplication.