Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to retrieve child documents linked to a parent document.
Prompt Engineering / GenAI
child_docs = client.search(index='children', query={'parent_id': [1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the field name 'parent_id' instead of the actual ID value.
Using the index name instead of the ID.
✗ Incorrect
The parent document ID '12345' is needed to find its child documents.
2fill in blank
mediumComplete the code to filter parent documents that have children with a specific attribute.
Prompt Engineering / GenAI
parents = client.search(index='parents', query={'has_child': {'type': 'child', 'query': {'term': {'[1]': 'active'}}}})
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'parent_id' which is not a child attribute.
Using 'type' which is a fixed value.
✗ Incorrect
We filter children by their 'status' field to find parents with active children.
3fill in blank
hardFix the error in the code to correctly retrieve parents with children matching a condition.
Prompt Engineering / GenAI
results = client.search(index='parents', query={'has_child': {'type': 'child', 'query': {'match': {'[1]': 'urgent'}}}})
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'parent_id' which is not a child field.
Using 'status' which may not indicate urgency.
✗ Incorrect
The 'priority' field in children is matched to find urgent child documents.
4fill in blank
hardFill both blanks to build a dictionary comprehension that maps parent IDs to counts of their children with score above 80.
Prompt Engineering / GenAI
parent_child_counts = {parent['id']: sum(1 for child in parent['children'] if child['score'][1] 80) for parent in parents if 'children' [2] parent} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for score comparison.
Using '==' instead of 'in' to check key existence.
✗ Incorrect
We count children with score > 80 and check if 'children' key exists in parent.
5fill in blank
hardFill all three blanks to create a filtered list of child documents with type 'comment' and length of text over 50.
Prompt Engineering / GenAI
filtered_children = [child for child in children if child['type'] == '[1]' and len(child['[2]']) [3] 50]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'content' instead of 'text' for the field name.
Using '<' instead of '>' for length comparison.
✗ Incorrect
We filter children of type 'comment' whose 'text' length is greater than 50 characters.