Parsing timestamp with gson for retrofit2 - gson

I have a very simple question regarding JSON parsing. My JSON has a find with name creation and value, for example, 1456923693921, it's timestamp. How to configure Gson to parse it into Date field. Currently I have an error: java.text.ParseException: Unparseable date: 1456923693921.
Thanks in advance!

Related

How to parse timestamp as date in opensearch?

I have some logs like this:
2022-12-07 17:22:53,838 [INFO]: {"status_code": 304, "method": "GET", "url": "/backend/some/url", "remote_ip": "rem.ote.ip.add", "response_time": 101.61018371582031} - tornado.access
I use an aggregator to parse those logs into the fields timestamp, loglevel, status_code etc. and send them to my opensearch instance. The problem is that the timestamp field is of type string in opensearch, so it cannot be sorted by in the Discover page. Oddly enough, it also has a field date of type float.
I then tried creating a new index with a changed timestamp format as per this answer (second option).
The problem here is that opensearch either uses the date it received the logs as the timestamp, or it just doesn't recognize any timestamp field:
If you follow this solution, the timestamp field type should be the date.
Can you share the mapping of the index?
GET index_name
Can you check the index_pattern and make sure the log-9 index_pattern date is set to timestamp

Convert HTTPDATE timestamp to correct format in Graylog

I have Squid writing logs with a timestamp as dd/MMM/yyyy:HH:mm:ss ZZZZ
"27/Jul/2022:11:55:40 +0100"
I'm sending these logs into Graylog using Filebeat, then parsing the timestamp into individual fields using HTTPDATE in a Grok extractor, so I can get separate Month, Monthday, Year etc fields.
I need to replace the "message received" #timestamp field with the actual "event occurred" timestamp when the event is indexed in Elasticsearch.
How can I convert the Squid timestamp from HTTPDATE into yyyy-MM-dd HH:mm:ss format?
"2022-07-27 11:55:40"
Thanks
EDIT:
Actually I think I have this now. In case it helps anyone else, this was done with a Regex Replacement Extractor:
Extractor Part1
Extractor Part 2
Extractor Part 3
This is an excellent question for the community. Try it there.

Need info in getting the date from filename in logstash

currently i have filename with the below format
[XXXXXXXX][YYYYYYYYYY][2016_07_21][19_21_12][160721T192103][ZZZZ]AB_RTRT.0.log.
is there a way, i can extract the datetimestamp and index it to a specific field in elastic search.
thanks
Subbu

Elasticsearch date field: epoch millis input, string output?

Steps:
1. Define a date field in a mapping.
2. Insert a epoch millisecond (long) value into that field.
Can elastic search returns a string value (yyyy-MM-ddTHH:mm:SS) of that field for a search?
From what I understand of the date-format documentation of ElasticSearch, it will always accept a milliseconds-since-epoch input next to input in the format given by the format, and it will produce a String output using the (first) format given. If you don't provide a format, then the "date_optional_time" format will be used (yyyy-MM-dd’T'HH:mm:ss.SSSZZ).
If the time zone in there is a problem for you, you'd need to give ElasticSearch your intended format.
I don't have the code to hand, but in my testing I believe I managed to do the following:
I used the date formatter on the field and the query fields definition to do this:
curl -XGET 'http://localhost:9200/twitter/tweet/1?fields=title,date_field.date_time'
using the date formats specified here: http://www.elasticsearch.org/guide/reference/mapping/date-format/
If you want a full document returned, this may be onerous. In which case is it possible to use an alias 'view' mapping to get the result to return differently from your primary mapping? Possibly this has become a half-answer.

Storing date field from JSON to MongoDB using Java API

I am using java api for mongodb to parse the JSON string into Java object and storing it into MongoDB.
My JSON string will have fields that are date like the one given below.
"created":"2012-10-17 21:39:06.385987 +0000"
When I try to save the parsed java object into MongoDB it stores the value as String. I would like to store it has a datetime field. Can someone shed some light on this?
Thanks and Regards,
Balaji.R
Java driver, as other default drivers, maps basic language types to MongoDB types, so to save date to mongo, you just need to save the Date object, not date string.
Here's simple sample from MongoDB documentation.

Resources