Cannot use transform rank op in Vega-Lite

Hi all,

I created a horizontal bar in Kibana using Vega-lite which works fine (Kibana v6.2.3). Next task was to add ranking so that I can filter the results based on their rank. This seems to be trickier as I cannot seem to make it work and I receive error

Ignoring an invalid transform: {"sort":[{"field":"1.value","order":"descending"}],"window":[{"as":"rank","op":"rank"}]}.

Below is the JSON.stringify(VEGA_DEBUG.vegalite_spec) export from the browser:

"{"$schema":"https://vega.github.io/schema/vega-lite/v2.json","title":"Daily Data","data":{"format":{"property":"aggregations.3.buckets"},"values":{"took":33,"timed_out":false,"_shards":{"total":20,"successful":20,"skipped":0,"failed":0},"hits":{"total":32403,"max_score":0,"hits":},"aggregations":{"3":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"1":{"value":16367.13454108499},"key":374150,"doc_count":2610},{"1":{"value":80775.62767555192},"key":369854,"doc_count":15175},{"1":{"value":2526.117695760913},"key":0,"doc_count":14618}]}}}},"transform":[{"window":[{"op":"rank","as":"rank"}],"sort":[{"field":"1.value","order":"descending"}]},{"filter":"datum.rank <= 5"}],"layer":[{"mark":{"type":"bar"},"encoding":{"y":{"field":"key","type":"ordinal","axis":{"title":"Id"}},"x":{"field":"1.value","type":"quantitative","axis":{"title":"Amount"}}}}],"config":{"range":{"category":{"scheme":"elastic"}},"mark":{"color":"#00A69B"}},"autosize":{"type":"fit","contains":"padding"}}"

The transform snippet was copied from the top rank example available here:

Any ideas will be greatly appreciated!

@nyuriks help please? I tried but not sure whats happening.

Bhavya

@georgeRD I do not know what your ES query looks like, but it seems you just copied it from what Kibana generates automatically for some other vis. I would recommend a few changes:

  • rename "1", "2", and "3" into proper names. E.g. rename "1" into first_agg or something more meaningful. Being a number might cause some unintended issues (I'm not sure about this, but just to be safer), but more importantly it makes your code more readable.
  • add a transform like {"calculate": "datum.first_agg.value", "as": "my_value"}, as the very first transformation
  • use my_value instead of 1.value everywhere from thereon.

@Nyu Many thanks for your response and also for this great plugin!

I applied all your enhancements suggested but still no luck, the same error appears regarding ignoring an invalid transformation.

Below is the JSON.stringify(VEGA_DEBUG.vegalite_spec) export from the browser:

"{"$schema":"https://vega.github.io/schema/vega-lite/v2.json","title":"Ranking","data":{"format":{"property":"aggregations.id.buckets"},"values":{"took":57,"timed_out":false,"_shards":{"total":20,"successful":20,"skipped":0,"failed":0},"hits":{"total":527628,"max_score":0,"hits":[]},"aggregations":{"id":{"doc_count_error_upper_bound":0,"sum_other_doc_count":527531,"buckets":[{"key":377967,"doc_count":2,"amount":{"value":2.190000057220459}},{"key":377876,"doc_count":36,"amount":{"value":847.3799840211868}},{"key":377874,"doc_count":5,"amount":{"value":-2.3100000116974115}},{"key":377851,"doc_count":1,"amount":{"value":4.730000019073486}},{"key":377836,"doc_count":2,"amount":{"value":0.07999999821186066}},{"key":377805,"doc_count":1,"amount":{"value":1.2000000476837158}},{"key":377784,"doc_count":4,"amount":{"value":-27.341851145029068}},{"key":377777,"doc_count":6,"amount":{"value":2.7900001406669617}},{"key":377767,"doc_count":32,"amount":{"value":91.16363054513931}},{"key":377762,"doc_count":8,"amount":{"value":4.100000038743019}}]}}}},"transform":[{"calculate":"datum.amount.value","as":"my_value"},{"window":[{"op":"rank","as":"rank"}],"sort":[{"field":"my_value","order":"descending"}]},{"filter":"datum.rank <= 3"}],"mark":{"type":"bar"},"encoding":{"y":{"field":"key","type":"ordinal","axis":{"title":"Id"}},"x":{"field":"my_value","type":"quantitative","axis":{"title":"Amount"}}},"config":{"range":{"category":{"scheme":"elastic"}},"mark":{"color":"#00A69B"}},"autosize":{"type":"fit","contains":"padding"}}"

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