Complete the code to define a date field in Elasticsearch mapping.
{
"mappings": {
"properties": {
"created_at": { "type": "[1]" }
}
}
}The date type is used to store date fields in Elasticsearch mappings.
Complete the code to specify a custom date format in the mapping.
{
"mappings": {
"properties": {
"event_date": {
"type": "date",
"format": "[1]"
}
}
}
}The format property defines the date pattern Elasticsearch expects, such as yyyy-MM-dd HH:mm:ss.
Fix the error in the date format specification.
{
"mappings": {
"properties": {
"publish_date": {
"type": "date",
"format": "[1]"
}
}
}
}The correct ISO 8601 date format with timezone is yyyy-MM-dd'T'HH:mm:ssZ, which Elasticsearch expects for date fields with timezone.
Fill both blanks to create a mapping with a date field that accepts multiple formats.
{
"mappings": {
"properties": {
"start_date": {
"type": "date",
"format": "[1]||[2]"
}
}
}
}Elasticsearch allows multiple date formats separated by ||. Here, yyyy-MM-dd and epoch_millis are valid formats.
Fill all three blanks to define a date field with a custom format, ignore malformed dates, and store dates as long.
{
"mappings": {
"properties": {
"log_date": {
"type": "date",
"format": "[1]",
"ignore_malformed": [2],
"store": [3]
}
}
}
}The format defines the date pattern, ignore_malformed set to true skips bad dates, and store set to true stores the field separately for faster retrieval.