0
0
Elasticsearchquery~10 mins

Why advanced patterns solve production needs in Elasticsearch - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to perform a basic match query in Elasticsearch.

Elasticsearch
{
  "query": {
    "match": {
      "message": "[1]"
    }
  }
}
Drag options to blanks, or click blank then click option'
Aerror
Bsearch
Cstatus
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using a field name instead of a search term.
Putting the query keyword in the wrong place.
2fill in blank
medium

Complete the code to filter documents where the status is 'active'.

Elasticsearch
{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "status": "[1]"
        }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Adeleted
Binactive
Cactive
Dpending
Attempts:
3 left
💡 Hint
Common Mistakes
Using a value that does not exist in the data.
Confusing filter with query clauses.
3fill in blank
hard

Fix the error in the aggregation to count documents by user.

Elasticsearch
{
  "aggs": {
    "users_count": {
      "terms": {
        "field": "[1]"
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Auser.text
Buser.keyword
Cusername
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using the analyzed text field which cannot be aggregated.
Using a field name that does not exist.
4fill in blank
hard

Fill both blanks to create a range query filtering documents with age between 20 and 30.

Elasticsearch
{
  "query": {
    "range": {
      "age": {
        "gte": [1],
        "lte": [2]
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A20
B30
C25
D35
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the lower and upper bounds.
Using values outside the desired range.
5fill in blank
hard

Fill the two blanks to create a script that calculates a new field 'total' as price times quantity if quantity is greater than 0.

Elasticsearch
{
  "script_fields": {
    "total": {
      "script": {
        "source": "if (doc['quantity'].value [1] 0) { return doc['price'].value [2] doc['quantity'].value; } else { return 0; }"
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A==
B>
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>' for the condition.
Using '+' instead of '*' for multiplication.