Message Boards
How to store date in S.d.f(08/20/2019) instead of timestamp in elasticsearc
lokesh gorrela, modified 4 Years ago.
How to store date in S.d.f(08/20/2019) instead of timestamp in elasticsearc
Regular Member Posts: 173 Join Date: 3/9/16 Recent Posts
Hi All
I created custom entity using elasticsearch module in liferay 7.1. In my table in database , date column having 2018-07-09 00:00:00 format date, but while indexing that date, It is stored as timestamp in elasticsearch. How I can store 04-20-2019 (Simple date format) instead of timestamp in elasticsearch.
Anyone knows about this requirement please give reply to me.
Thanks
Lokesh
I created custom entity using elasticsearch module in liferay 7.1. In my table in database , date column having 2018-07-09 00:00:00 format date, but while indexing that date, It is stored as timestamp in elasticsearch. How I can store 04-20-2019 (Simple date format) instead of timestamp in elasticsearch.
Anyone knows about this requirement please give reply to me.
Thanks
Lokesh
David H Nebinger, modified 4 Years ago.
RE: How to store date in S.d.f(08/20/2019) instead of timestamp in elastics
Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent Posts
Sure, just store as text in the doc and format it as you like in your custom indexing code.
lokesh gorrela, modified 4 Years ago.
RE: How to store date in S.d.f(08/20/2019) instead of timestamp in elastics
Regular Member Posts: 173 Join Date: 3/9/16 Recent Posts
Hi David
Thanks for your reply.
I followed your suggestion and tested the functionality but it stored data in 20190420442288 (yyyyMMddHHmmss) only. But i need to store data in 04/20/2019 format. See below mapping of date field in index.
In my Index date field mapping like this below
"modified" : {
"type" : "date",
"store" : true,
"format" : "yyyyMMddHHmmss"
},
I need to update the above date field format in mapping like this below
"modified" : {
"type" : "date",
"store" : true,
"format" : "MM/dd/yyyy"
},
Please give any suggestion for this requirement.
Thanks
Lokesh
Thanks for your reply.
I followed your suggestion and tested the functionality but it stored data in 20190420442288 (yyyyMMddHHmmss) only. But i need to store data in 04/20/2019 format. See below mapping of date field in index.
In my Index date field mapping like this below
"modified" : {
"type" : "date",
"store" : true,
"format" : "yyyyMMddHHmmss"
},
I need to update the above date field format in mapping like this below
"modified" : {
"type" : "date",
"store" : true,
"format" : "MM/dd/yyyy"
},
Please give any suggestion for this requirement.
Thanks
Lokesh
David H Nebinger, modified 4 Years ago.
RE: How to store date in S.d.f(08/20/2019) instead of timestamp in elastics
Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent Posts
That was not my suggestion at all. I never said the index should be modified to use a different format.
What I said was that the index field should be text and your custom IndexPostProcessor would itself do the formatting in the way you wanted and set the text field that way.
What I said was that the index field should be text and your custom IndexPostProcessor would itself do the formatting in the way you wanted and set the text field that way.
Jorge Díaz, modified 4 Years ago.
RE: How to store date in S.d.f(08/20/2019) instead of timestamp in elastics
Liferay Master Posts: 753 Join Date: 1/9/14 Recent Posts
Hi Lokesh gorrela,
In my opinion, it is better to store all date information as timestamp in Elasticsearch, as you will be able to do operations like sorting or search by date intervals.
If you want to index it with other format, it is better to create a different field, as David said, for example "modified_mmddyyy" and store/retrieve that field instead.
Nevertheless: Why do you want to store dates with that non-timestamp format? If you want to retrieve it from the index and display it somewhere, it is better to convert the date before displaying it.
Regards,
Jorge
In my opinion, it is better to store all date information as timestamp in Elasticsearch, as you will be able to do operations like sorting or search by date intervals.
If you want to index it with other format, it is better to create a different field, as David said, for example "modified_mmddyyy" and store/retrieve that field instead.
Nevertheless: Why do you want to store dates with that non-timestamp format? If you want to retrieve it from the index and display it somewhere, it is better to convert the date before displaying it.
Regards,
Jorge