0
0
Prompt Engineering / GenAIml~10 mins

Parent-child document retrieval in Prompt Engineering / GenAI - Interactive Code Practice

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

Complete 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'
A'12345'
B'parent_id'
C'children'
D'parent_doc'
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.
2fill in blank
medium

Complete 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'
Astatus
Bparent_id
Cchild_id
Dtype
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'parent_id' which is not a child attribute.
Using 'type' which is a fixed value.
3fill in blank
hard

Fix 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'
Achild_id
Bpriority
Cparent_id
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'parent_id' which is not a child field.
Using 'status' which may not indicate urgency.
4fill in blank
hard

Fill 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'
A>
Bin
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for score comparison.
Using '==' instead of 'in' to check key existence.
5fill in blank
hard

Fill 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'
Acomment
Btext
C>
Dcontent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'content' instead of 'text' for the field name.
Using '<' instead of '>' for length comparison.