Now, I would like to use the same type of dynamic calculation for the visualization:
created a scripted field for the according index in kibana named 'custom.timestamp.dayofweek'
created a new visualization with x axis type: "term", field: 'custom.timestamp.dayofweek'
I have opened the advanced section for the bucket and typed in the following json to override the original dummy scripting of the scripted field:
{
"script": "doc['@timestamp'].date.dayOfWeek().getAsText()",
"lang" : "groovy"
}
As a result, I do not receive a bar chart according to the buckets returned by sense. Instead, I receive error messages such as
"Visualize: Unsupported script value [Donnerstag] Unsupported script value [Dienstag] Unsupported script value [Freitag]"
By this, I know, the calculation worked out as expected, but the Kibana Visualization does not work properly. I assume I have to change any configuration.
Then, in the visualization editor, in the advanced section for the terms aggregation on the scripted field, you only need to specify { "lang": "groovy", "valueType": "string" }:
Thanks a lot Shaunak!
Defining the valueType did the the job!
Now, there is only thing missing. Is there any chance to tight the buckets to a defined order?
The buckets are named according to the weekdays (monday, tuesday,...)
But the buckets are either ordered by term (i.e. friday, moday, saturday, subday, tuesday, thursday, wednesday)
or by count which is the number of items in the bucket,...
However, what the user would need is the natural order of the weekdays.
There might be a better way to achieve natural ordering of the weekdays but the best I could think of was this:
Change your script expression to doc['@timestamp'].date.dayOfWeek().get() + "_" + doc['@timestamp'].date.dayOfWeek().getAsText() and then in the visualization editor, order by term in ascending order. That'll show you the days in their natural order but as 1_Monday, 2_Tuesday, etc.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.