Logstash conf file:
filter {
json {
source => "message"
}
}
output {
elasticsearch {
hosts =>"http://xx.xx.xx.xx.com"
index => "sample_data_%{+YYYY.MM.dd}"
user => "elastic"
password => "xxxxxxxxx"
}
}
Index Mappings:
{
"mappings": {
"_doc": {
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"order": {
"properties": {
"createdOn": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"items": {
"properties": {
"itemId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"orderID": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"totalPrice": {
"type": "long"
},
"updatedOn": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
Sample message stored in Elasticsearch:
{
"_index": "sample_data_2024.07.05",
"_type": "_doc",
"_id": "pcABgpAB1lurpuJXc5JB",
"_version": 1,
"_score": null,
"_source": {
"order": {
"createdOn": "2024-05-27 13:23:29",
"totalPrice": 120,
"items": {
"itemId": "AG000284"
},
"updatedOn": "2024-05-27 13:23:29",
"orderID": "DE--499"
},
"@timestamp": "2024-07-05T08:27:31.407Z",
"@version": "1",
},
"fields": {
"@timestamp": [
"2024-07-05T08:27:31.407Z"
]
},
"sort": [
1720168051407
]
}
*We need HELP to store the fields as date format using logstash before store the data into Index like below but createdOn & updatedOn fields stored as text format *
"createdOn": {
"type": "date"
}
"updatedOn": {
"type": "date"
}