Challenge - 5 Problems
Date Field Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this date mapping query?
Given this Elasticsearch mapping for a date field, what will be the stored format of the date?
{
"mappings": {
"properties": {
"created_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||epoch_millis"
}
}
}
}Elasticsearch
POST /my_index/_doc
{
"created_at": "2024-06-15 14:30:00"
}Attempts:
2 left
💡 Hint
Check the format property and how Elasticsearch parses dates.
✗ Incorrect
Elasticsearch parses the date string using the specified format and stores it internally as epoch milliseconds for efficient range queries and sorting.
❓ Predict Output
intermediate2:00remaining
What happens if a date does not match the format?
Consider this mapping:
What happens if you index a document with:
{
"mappings": {
"properties": {
"event_date": {
"type": "date",
"format": "yyyy/MM/dd"
}
}
}
}What happens if you index a document with:
{ "event_date": "2024-06-15" }Attempts:
2 left
💡 Hint
The date format must exactly match the input string.
✗ Incorrect
Since the input date "2024-06-15" does not match the format "yyyy/MM/dd", Elasticsearch cannot parse it and rejects the document with an error.
🔧 Debug
advanced2:00remaining
Why does this date mapping cause an error?
This mapping causes an error when creating the index:
What is the cause of the error?
{
"mappings": {
"properties": {
"log_time": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis||yyyy-MM-dd HH:mm:ss"
}
}
}
}What is the cause of the error?
Attempts:
2 left
💡 Hint
Check how strict_date_optional_time interacts with other formats.
✗ Incorrect
Using strict_date_optional_time with other formats in the same format string causes conflicts because strict formats enforce strict parsing rules that clash with others.
🧠 Conceptual
advanced2:00remaining
How does Elasticsearch handle multiple date formats in one field?
If a date field mapping specifies multiple formats separated by ||, how does Elasticsearch process an incoming date string?
Attempts:
2 left
💡 Hint
Think about how flexible date parsing works.
✗ Incorrect
Elasticsearch attempts to parse the date string using each format in order until one succeeds, allowing flexible input formats for the same field.
❓ Predict Output
expert2:00remaining
What is the output of this date range query?
Given this mapping and documents:
What documents match this query?
{
"mappings": {
"properties": {
"timestamp": {
"type": "date",
"format": "epoch_millis"
}
}
}
}
POST /my_index/_bulk
{ "index": {} }
{ "timestamp": 1686787200000 }
{ "index": {} }
{ "timestamp": 1686873600000 }What documents match this query?
{
"query": {
"range": {
"timestamp": {
"gte": "1686787200000",
"lt": "1686873600000"
}
}
}
}Attempts:
2 left
💡 Hint
Check the range boundaries and timestamp values carefully.
✗ Incorrect
The range query includes documents with timestamp >= 1686787200000 and < 1686873600000. The first document matches exactly the lower bound, the second equals the upper bound which is exclusive, so it does not match.