I want to fetch some logs data from elasticsearch and return it to the UI using graphql. I am using the nestjs/elasticsearch client in my nest.js backend which is a wrapper of 'elastic/elasticsearch'. I have also mapped the timestamp field in the elasticsearch index as 'date'.
"mappings": {
"properties": {
"timestamp": {
"type": "date"
},
"message": {
"type": "keyword"
},
}
}
I have created the @ObjectType class as follows:
@ObjectType()
export class LogMessage {
@Field()
message: string;
@Field()
timestamp: Date;
}
But, while getting the documents from Elasticsearch, the timestamp is getting returned as a 'string'.
And because the ObjectType expects 'timestamp' to be a Date, I get 'null' on the 'graphql' response for the 'timestamp' field.
Changing to 'timestamp: string', I see the timestamp in the response.
How do I debug this issue and make sure that elasticsearch client returns the 'timestamp' as a 'Date'? Or Is this expected behavior and I need to convert the string to Date type manually?