Getting the below exception while indexing the document into datastream
org.elasticsearch.ElasticsearchException: Elasticsearch exception [type=illegal_argument_exception, reason=data stream timestamp field [@timestamp] is missing]
Injest Pipeline
PUT _ingest/pipeline/auto_now_add
{
"description": "Assigns the current date if not yet present and if the index name is whitelisted",
"processors": [
{
"script": {
"source": """
// skip if not whitelisted
if (![ "cp_monitoring_data_tenantid"
].contains(ctx['_index'])) { return; }
// always update updated_at
ctx['@timestamp'] = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date());
// don't overwrite if present
if (ctx != null && ctx['created_at'] != null) { return; }
ctx['created_at'] = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date());
"""
}
}
]
}
Model Object
public class Message {
@Id
private String id;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
@Field(type= FieldType.Date)
Date date;
@Field(type = FieldType.Keyword)
private String message;
@Field(type= FieldType.Date)
private Date timestamp;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
Mappings
<code>{
"dynamic": true,
"properties": {
"date": {
"format": "strict_date_time",
"type": "date"
},
"index_age": {
"type": "long"
},
"@timestamp": {
"format": "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
"type": "date"
},
"timestamp": {
"format": "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
"type": "date"
}
}
}
</>
Please let me know why is it failing how to fix it.