Bird
0
0

Which of the following is the correct way to define a date field with a custom format in an Elasticsearch mapping?

easy📝 Syntax Q12 of 15
Elasticsearch - Mappings and Data Types
Which of the following is the correct way to define a date field with a custom format in an Elasticsearch mapping?
A{ "mappings": { "properties": { "created_at": {"type": "integer", "format": "yyyy-MM-dd"} } } }
B{ "mappings": { "properties": { "created_at": {"type": "date", "format": "yyyy-MM-dd HH:mm:ss"} } } }
C{ "mappings": { "properties": { "created_at": {"type": "date"} } } }
D{ "mappings": { "properties": { "created_at": {"type": "text", "format": "yyyy-MM-dd"} } } }
Step-by-Step Solution
Solution:
  1. Step 1: Check the field type for date

    The field must have type set to date to store dates.
  2. Step 2: Verify the format property

    Custom date formats are specified with the format key inside the date field definition.
  3. Final Answer:

    Mapping with type 'date' and format 'yyyy-MM-dd HH:mm:ss' -> Option B
  4. Quick Check:

    Date type + format key = correct mapping [OK]
Quick Trick: Date fields need type 'date' and format string [OK]
Common Mistakes:
MISTAKES
  • Using type 'text' or 'integer' for date fields
  • Omitting the format when using custom date strings
  • Placing format outside the date field definition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes