Extract the year from a date

(marwa) #1

i have data stored in elasticsearch with a field called transaction_date mapped as a date ,this is its structure in the csv file 2/24/2017;14:15:43 and this how it is viewed in kibana April 18th 2016, 15:15:44.000 .In fact , i want to perform calculations using aggregatiuons with scripted field but i want to extract only data of the year 2016 .how can i extract only the year from the date field ???? any help

(David Pilato) #2

It's better to solve this problem at index time.

If your field is a date field, you can just generate a date histogram with a year size bucket and that will do what you expect.

(marwa) #3

Hi , thank you for your reply but i didn't get it are you talking about a bucket using kibana ???
in fact i need to divide my data into two bucket one for the year 2016 and one for the year 2017 , i know i can make it with aggregations using kibana visualization but i need to extract a metric from the buckets i mentionned then perform an other calculation with both results obtained .

I am trying to use scripted metrics with elasticsearch ? i don't know even if this can lead me to my goal ?? i need your consult !!! even more i am confused between aggregations and using painless to perform this calculation !! any help

(marwa) #4

Any suggestions please ???

(David Pilato) #5

Please read be patient section at

May be your question is more for Kibana? So may be move it to #kibana instead?
I believe you can do something similar with time series visual builder.

(marwa) #6

sorry if i hadn't been patient :wink:

(Ravi Shanker Reddy) #7

Its better to show some sample data along with the output format you need. No one can help with these type of inputs. Be more specific.

(marwa) #8

hi ,
thankyou for you reply, maybe i get into details in my question but my main purpose is to perform calculations with elasticsearch then store the results . is there any API that allow me to do this ?

(system) closed #9

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