0
0
Elasticsearchquery~10 mins

Saved searches and filters 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 saved search with a name.

Elasticsearch
{
  "name": "[1]",
  "query": {
    "match_all": {}
  }
}
Drag options to blanks, or click blank then click option'
Aquery
Bsearch
Cfilter
DMySavedSearch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'query' or 'filter' as the name instead of a string.
Omitting the name field.
2fill in blank
medium

Complete the code to add a filter that matches documents where 'status' is 'active'.

Elasticsearch
{
  "query": {
    "bool": {
      "filter": {
        "term": { "status": "[1]" }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Aactive
Bpending
Cinactive
Ddeleted
Attempts:
3 left
💡 Hint
Common Mistakes
Using a status value that does not exist in the data.
Using the wrong field name.
3fill in blank
hard

Fix the error in the saved search filter to correctly filter documents with 'age' greater than 30.

Elasticsearch
{
  "query": {
    "range": {
      "age": { "[1]": 30 }
    }
  }
}
Drag options to blanks, or click blank then click option'
Alt
Blte
Cgt
Deq
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lt' or 'lte' which filter for less than or equal.
Using 'eq' which is not valid in range queries.
4fill in blank
hard

Fill both blanks to create a saved search that filters documents where 'category' is 'books' and 'price' is less than 20.

Elasticsearch
{
  "query": {
    "bool": {
      "filter": [
        { "term": { "category": "[1]" } },
        { "range": { "price": { "[2]": 20 } } }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
Abooks
Bgt
Clt
Delectronics
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'gt' instead of 'lt' for price filter.
Using wrong category name.
5fill in blank
hard

Fill all three blanks to create a saved search that filters documents where 'author' is 'Alice', 'year' is greater than 2015, and 'rating' is at least 4.

Elasticsearch
{
  "query": {
    "bool": {
      "filter": [
        { "term": { "author": "[1]" } },
        { "range": { "year": { "[2]": 2015 } } },
        { "range": { "rating": { "[3]": 4 } } }
      ]
    }
  }
}
Drag options to blanks, or click blank then click option'
AAlice
Bgt
Cgte
DBob
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lt' or 'lte' operators incorrectly.
Using wrong author name.