# Cannot use transform rank op in Vega-Lite

**URL:** <https://discuss.elastic.co/t/cannot-use-transform-rank-op-in-vega-lite/153586>\
**Category:** Kibana\
**Created:** [October 23, 2018, 10:59am UTC](https://discuss.elastic.co/t/cannot-use-transform-rank-op-in-vega-lite/153586 "2018-10-23T10:59:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![georgeRD](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/georgerd/32/77165_2.png) [@georgeRD](https://discuss.elastic.co/u/georgeRD)\
**Post date:** [October 23, 2018, 10:59am UTC](https://discuss.elastic.co/t/cannot-use-transform-rank-op-in-vega-lite/153586/1 "2018-10-23T10:59:35Z")

</div>

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](https://vega.github.io/schema/vega-lite/v2.json%22,%22title%22:%22Daily) 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:

> **[Window](https://vega.github.io/vega-lite/docs/window.html#top-k)**
>
> Vega-Lite - a high-level grammar for statistical graphics. Vega-Lite provides a higher-level grammar for visual analysis, comparable to ggplot or Tableau, that generates complete Vega specifications. Vega-Lite specifications consist of simple...

Any ideas will be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)\
**Post date:** [October 29, 2018, 2:37pm UTC](https://discuss.elastic.co/t/cannot-use-transform-rank-op-in-vega-lite/153586/2 "2018-10-29T14:37:12Z")

</div>

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

Bhavya

---

<div class="post-metadata">

**Author:** ![nyuriks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nyuriks/32/26171_2.png) [@nyuriks](https://discuss.elastic.co/u/nyuriks)\
**Post date:** [November 2, 2018, 4:52pm UTC](https://discuss.elastic.co/t/cannot-use-transform-rank-op-in-vega-lite/153586/3 "2018-11-02T16:52:00Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![georgeRD](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/georgerd/32/77165_2.png) [@georgeRD](https://discuss.elastic.co/u/georgeRD)\
**Post date:** [November 6, 2018, 10:29pm UTC](https://discuss.elastic.co/t/cannot-use-transform-rank-op-in-vega-lite/153586/4 "2018-11-06T22:29:29Z")

</div>

@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](https://vega.github.io/schema/vega-lite/v2.json%22,%22title%22:%22Ranking%22,%22data%22:%7B%22format%22:%7B%22property%22:%22aggregations.id.buckets%22%7D,%22values%22:%7B%22took%22:57,%22timed_out%22:false,%22_shards%22:%7B%22total%22:20,%22successful%22:20,%22skipped%22:0,%22failed%22:0%7D,%22hits%22:%7B%22total%22:527628,%22max_score%22:0,%22hits%22:%5B%5D%7D,%22aggregations%22:%7B%22id%22:%7B%22doc_count_error_upper_bound%22:0,%22sum_other_doc_count%22:527531,%22buckets%22:%5B%7B%22key%22:377967,%22doc_count%22:2,%22amount%22:%7B%22value%22:2.190000057220459%7D%7D,%7B%22key%22:377876,%22doc_count%22:36,%22amount%22:%7B%22value%22:847.3799840211868%7D%7D,%7B%22key%22:377874,%22doc_count%22:5,%22amount%22:%7B%22value%22:-2.3100000116974115%7D%7D,%7B%22key%22:377851,%22doc_count%22:1,%22amount%22:%7B%22value%22:4.730000019073486%7D%7D,%7B%22key%22:377836,%22doc_count%22:2,%22amount%22:%7B%22value%22:0.07999999821186066%7D%7D,%7B%22key%22:377805,%22doc_count%22:1,%22amount%22:%7B%22value%22:1.2000000476837158%7D%7D,%7B%22key%22:377784,%22doc_count%22:4,%22amount%22:%7B%22value%22:-27.341851145029068%7D%7D,%7B%22key%22:377777,%22doc_count%22:6,%22amount%22:%7B%22value%22:2.7900001406669617%7D%7D,%7B%22key%22:377767,%22doc_count%22:32,%22amount%22:%7B%22value%22:91.16363054513931%7D%7D,%7B%22key%22:377762,%22doc_count%22:8,%22amount%22:%7B%22value%22:4.100000038743019%7D%7D%5D%7D%7D%7D%7D,%22transform%22:%5B%7B%22calculate%22:%22datum.amount.value%22,%22as%22:%22my_value%22%7D,%7B%22window%22:%5B%7B%22op%22:%22rank%22,%22as%22:%22rank%22%7D%5D,%22sort%22:%5B%7B%22field%22:%22my_value%22,%22order%22:%22descending%22%7D%5D%7D,%7B%22filter%22:%22datum.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"}}"

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 4, 2018, 10:29pm UTC](https://discuss.elastic.co/t/cannot-use-transform-rank-op-in-vega-lite/153586/5 "2018-12-04T22:29:34Z")

</div>

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