0
0
Elasticsearchquery~10 mins

Nested queries for nested objects 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 start a nested query on the field 'comments'.

Elasticsearch
{
  "query": {
    "nested": {
      "path": "[1]"
    }
  }
}
Drag options to blanks, or click blank then click option'
Acomments
Buser
Cposts
Dtags
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-nested field name in the path.
Forgetting to specify the path.
2fill in blank
medium

Complete the code to add a match query inside the nested query for 'comments.author'.

Elasticsearch
{
  "query": {
    "nested": {
      "path": "comments",
      "query": {
        "match": {
          "comments.[1]": "Alice"
        }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Atext
Bauthor
Cdate
Dlikes
Attempts:
3 left
💡 Hint
Common Mistakes
Using a field not inside the nested object.
Using the nested path name instead of the nested field.
3fill in blank
hard

Fix the error in the nested query by completing the missing key for the inner query.

Elasticsearch
{
  "query": {
    "nested": {
      "path": "comments",
      "query": {
        "[1]": {
          "must": {
            "match": {
              "comments.text": "great"
            }
          }
        }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Abool
Bmatch
Cterm
Drange
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'match' as the key instead of 'bool'.
Using 'term' or 'range' which are not container queries.
4fill in blank
hard

Fill both blanks to create a nested query that filters comments with 'likes' greater than 10.

Elasticsearch
{
  "query": {
    "nested": {
      "path": "comments",
      "query": {
        "range": {
          "comments.[1]": {
            "[2]": 10
          }
        }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Alikes
Bgt
Clt
Dauthor
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lt' instead of 'gt' for greater than.
Using a wrong field name like 'author'.
5fill in blank
hard

Fill all three blanks to create a nested query that matches comments by 'author' 'Bob' and filters by 'date' after '2023-01-01'.

Elasticsearch
{
  "query": {
    "nested": {
      "path": "comments",
      "query": {
        "bool": {
          "must": [
            { "match": { "comments.[1]": "Bob" } },
            { "range": { "comments.[2]": { "[3]": "2023-01-01" } } }
          ]
        }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Aauthor
Bdate
Cgte
Dlikes
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'gt' instead of 'gte' for inclusive date filtering.
Mixing up field names like 'likes' instead of 'date'.