0
0
Elasticsearchquery~10 mins

Document ID strategies (auto vs manual) in Elasticsearch - Interactive Practice

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

Complete the code to index a document with an automatic ID in Elasticsearch.

Elasticsearch
client.index(index='products', body=[1])
Drag options to blanks, or click blank then click option'
A{'product_id': '123', 'price': 1200}
B{'id': '123', 'name': 'Laptop'}
C{'name': 'Laptop', 'price': 1200}
D{'doc': {'name': 'Laptop'}}
Attempts:
3 left
💡 Hint
Common Mistakes
Including an 'id' field in the document body when expecting auto-generated IDs.
Using 'doc' key incorrectly when indexing a new document.
2fill in blank
medium

Complete the code to index a document with a manual ID 'abc123' in Elasticsearch.

Elasticsearch
client.index(index='products', id=[1], body={'name': 'Phone', 'price': 800})
Drag options to blanks, or click blank then click option'
ANone
B'auto_id'
C123
D'abc123'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing None or numeric values as the ID.
Forgetting to pass the ID parameter.
3fill in blank
hard

Fix the error in the code to update a document with manual ID 'xyz789' in Elasticsearch.

Elasticsearch
client.update(index='products', id=[1], body={'doc': {'price': 950}})
Drag options to blanks, or click blank then click option'
ANone
B'xyz789'
Cxyz789
D'update_id'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an unquoted ID causing a NameError.
Passing None as the ID.
4fill in blank
hard

Fill both blanks to delete a document with manual ID 'doc456' from the 'orders' index.

Elasticsearch
client.delete(index=[1], id=[2])
Drag options to blanks, or click blank then click option'
A'orders'
B'doc456'
C'products'
D'auto_id'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up index and ID values.
Not quoting string values.
5fill in blank
hard

Fill all three blanks to search documents in 'customers' index where 'age' is greater than 30.

Elasticsearch
client.search(index=[1], body={'query': {'range': {'age': {'gt': [2], size=[3])
Drag options to blanks, or click blank then click option'
A'customers'
B30
C10
D'age'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numeric values in the query.
Confusing index name with field names.