Kibana and groovy scripting -
i looking way calculate ratio on kibana. after many researches found way : using "json input" feature in visualisation.
i have informations in index, 2 types of documents (boots , reboots). i looking script count number of documents type boots, same reboots type divide second first. sounds easy, not find way after researches, , not used groovy enough yet myself.
i found many ways manipulate documents values (doc['mydocname'].values etc), nothing type.
thanks in advance.
edit : tried this
{ "aggs" : { "boots_count" : { "value_count" : { "_type" : "boots" } } }
} supposed count number of fields (here field _type) in index. when put "json input" in visualisation, results in error :
error: request elasticsearch failed: {"error":"searchphaseexecutionexception[failed execute phase [query], shards failed; shardfailures {[bbxj0o6trxa_ocybfycgjq][informationbe][0]: searchparseexception[[informationbe][0]: from[-1],size[0]: parse failure [failed parse source [{\"size\":0,\"aggs\":{\"2\":{\"terms\":{\"field\":\"@siteposte\",\"size\":5,\"order\":{\"1\":\"desc\"}},\"aggs\":{\"1\":{\"avg\":{\"script\":\"0\",\"lang\":\"expression\",\"ratio\":{\"boots_count\":{\"value_count\":{\"_type\":\"boots\"}}}}}}}}
i wrong. ?
edit2 : in other hand, trying scripted fields, using lucene expression :
doc['_type:boots'].count / doc['_type:reboots'].count
but doesnt work more, pretty confident "doc['_type:boots']" part, guess problem on "xxx.count" part.
after many attempts, understand better , better how works. default scripted fields scope on document, not on whole index, cant count action of whole values of index documents in it. looking workaround, i'll post it if find interesting.
i solved problem :
i added scripted field, if type of document boots, scripted field = 1, else 0. created search boots , reboots documents (filter _type:boots _type:reboots) , calculated average of scripted field in metric.
everything works !
Comments
Post a Comment