I've got this custom query for Elasticsearch:
{
"query": { "match_all": {} },
"size": 0,
"aggs": {
"hour": {
"histogram": {
"script": "doc['startTime'].date.hourOfDay",
"interval": 1,
"min_doc_count": 0,
"extended_bounds": {
"min": 0,
"max": 23
},
"lang":"groovy"
}
}
}
}
Which, when ran through postman, gives the following result (not complete):
"aggregations": {
"hour": {
"buckets": [
{
"key": 0,
"doc_count": 18359
},
{
"key": 1,
"doc_count": 18361
},
{
"key": 2,
"doc_count": 18183
},
{
"key": 3,
"doc_count": 19729
},
Thing is, now I want to visualise these buckets in Kibana. The goal is to show 24 bars each with their respective doc_count.
If I put the query into the search bar however I get the error:
Visualize: [filtered] query does not support [query]
.
Going into the visualize tab and adding an x-asis of aggregation type "Date histogram", field "startTime" (which is my date field), interval auto and the following json:
{
"histogram": {
"script": "doc['startTime'].date.hourOfDay",
"interval": 1,
"min_doc_count": 0,
"extended_bounds": {
"min": 0,
"max": 23
},
"lang":"groovy"
}
}
also produces an error:
Visualize: Unknown key for a START_OBJECT in [2]: [histogram].
Been reading up on different solutions for the past 3 hours and haven't stumbled accross any working solutions.
Some more info:
"version": {
"number": "2.3.3",
"build_hash": "218bdf10790eef486ff2c41a3df5cfa32dadcfde",
"build_timestamp": "2016-05-17T15:40:04Z",
"build_snapshot": false,
"lucene_version": "5.5.0"
}
Anyone out there that can give me a hand :)?
You can do this by using the 'JSON Input' option in Kibana:
{
"script": "doc['startTime'].date.hourOfDay",
"interval": 1,
"min_doc_count": 0,
"extended_bounds": {
"min": 0,
"max": 23
},
"lang": "groovy"
}
Another option is to create a new scripted field and use that:
startTime_hourofday
doc['startTime'].getHourOfDay()
startTime_hourofday
from the field list.