Help in Parsing date from timestamp using painless

Hi, Could any one please help me getting the date from the timestamp using painless in the scripted field and group the data-set based on date,

doc['timestamp'].date.monthOfYear + '/' + doc['timestamp'].date.dayOfMonth + '/' + doc['timestamp'].date.year

I am trying to the get the count based on the date as below.

11/17/2018 11/16/2018 11/15/2018
Row1 10 25 333
Row2 21 44 35
Row3 22 11 24

Thanks.

@Dhana ,

that painless script looks correct, or am I missing something?

you can create a scripted-field with that script. https://www.elastic.co/guide/en/kibana/current/scripted-fields.html. You'll create a new string-field on the fly.

Then, you'll be able to do a terms-aggregation on that field and do a count by date.

Hi,

Thanks for confirming. So I can create a field name " test_scripted_field1" as string and use that for count.

Could you please verify the below configuration parameters and confirm.

Name - test_scripted_field1
Language - painless
Type - String
Transform - none
Popularity - 0
Script
doc['timestamp'].date.monthOfYear + '/' + doc['timestamp'].date.dayOfMonth + '/' + doc['timestamp'].date.year

Thanks,
Dhana

yes that looks good I think.

you can verify if this works in the "Discover" application of Kibana. Select your index-pattern there and look for that new test_scripted_field1 on the left-side. Select it, and see what the results look like.

Hi, I tried the steps provided but I was getting the error on the discover page, and I was not getting any result on the logs. So I have to delete the created field and the log started loading on the discover screen on discover.

Could you please help me to resolve the issue.

Thanks.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.