0
0
Elasticsearchquery~10 mins

Range query in Elasticsearch - Interactive Code Practice

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

Complete the code to create a range query that finds documents with a field "age" greater than 30.

Elasticsearch
{
  "query": {
    "range": {
      "age": {
        "[1]": 30
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Alt
Bgte
Cgt
Dlte
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'gte' instead of 'gt' will include age 30, not strictly greater.
Using 'lt' or 'lte' will find ages less than 30, which is wrong.
2fill in blank
medium

Complete the code to create a range query that finds documents with a field "price" less than or equal to 100.

Elasticsearch
{
  "query": {
    "range": {
      "price": {
        "[1]": 100
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Alte
Bgte
Clt
Dgt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lt' excludes 100, but the question wants less than or equal.
Using 'gte' or 'gt' will find prices greater than 100, which is wrong.
3fill in blank
hard

Fix the error in the range query to find documents with "date" between "2023-01-01" and "2023-12-31" inclusive.

Elasticsearch
{
  "query": {
    "range": {
      "date": {
        "gte": "2023-01-01",
        "[1]": "2023-12-31"
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Alte
Blt
Cgt
Dgte
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lt' excludes the last date, which is not what we want.
Using 'gte' twice is incorrect syntax.
4fill in blank
hard

Fill both blanks to create a range query that finds documents with "score" between 50 and 100, excluding 50 but including 100.

Elasticsearch
{
  "query": {
    "range": {
      "score": {
        "[1]": 50,
        "[2]": 100
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Agt
Bgte
Clte
Dlt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'gte' for the lower bound includes 50, which is wrong here.
Using 'lt' for the upper bound excludes 100, which is wrong here.
5fill in blank
hard

Fill all three blanks to create a range query that finds documents with "temperature" greater than 20, less than 30, and includes the field "boost" set to 2.0.

Elasticsearch
{
  "query": {
    "range": {
      "temperature": {
        "[1]": 20,
        "[2]": 30,
        "[3]": 2.0
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Agt
Blt
Cboost
Dgte
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'gte' or 'lte' changes the inclusiveness of the range.
Putting 'boost' as a comparison operator causes errors.