# Iterate by rows on an essql query

**URL:** <https://discuss.elastic.co/t/iterate-by-rows-on-an-essql-query/216892>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [January 28, 2020, 5:23pm UTC](https://discuss.elastic.co/t/iterate-by-rows-on-an-essql-query/216892 "2020-01-28T17:23:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luis.montecatine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luis.montecatine/32/48432_2.png) [@luis.montecatine](https://discuss.elastic.co/u/luis.montecatine)\
**Post date:** [January 28, 2020, 5:23pm UTC](https://discuss.elastic.co/t/iterate-by-rows-on-an-essql-query/216892/1 "2020-01-28T17:23:11Z")

</div>

Hello,  
I'm using essql queries.  
I need to iterate the result by row.

I just found the way to iterate it on markdown. But I need to iterate on canvas, not in markdown.  
Because using markdown #each, I can't use if conditions like:  
rows.country='UK'

Just like:  
| essql query="Select name from index"  
for (r in rows) {  
r.name  
}

Is it possible to do that?

Thanks in advance.  
Luis.

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [January 30, 2020, 9:19am UTC](https://discuss.elastic.co/t/iterate-by-rows-on-an-essql-query/216892/2 "2020-01-30T09:19:16Z")

</div>

Hi @luis.montecatine,

Yes, that's possible in canvas, but the syntax is different - you are basically chaining functions separated by `|` and the data passes through them from the first one to the last one. You can look through all functions in the documentation: [https://www.elastic.co/guide/en/kibana/current/canvas-function-reference.html](https://www.elastic.co/guide/en/kibana/current/canvas-function-reference.html)

For your specific example (using conditions), you can use `filterrows`:

```auto
filters
| essql 
  query="Select name, country from index"
| filterrows {getCell "country" | eq "UK"}
| table
| render

```

This will query the index `index` for the name and the country field and then filter out all rows that don't have the `country` value `UK`. You can do this specific example completely within the essql query (`Select name, country from index where country = "UK"`), but the provided functions are very flexible because you can arrange and nest them freely.

---

<div class="post-metadata">

**Author:** ![luis.montecatine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luis.montecatine/32/48432_2.png) [@luis.montecatine](https://discuss.elastic.co/u/luis.montecatine)\
**Post date:** [January 30, 2020, 1:03pm UTC](https://discuss.elastic.co/t/iterate-by-rows-on-an-essql-query/216892/3 "2020-01-30T13:03:19Z")

</div>

Hello Joe,  
First of all, thanks for the answer.

I tried to use filterrows too but I think I won't works for me.  
My goal is to iterate the query rows in order to only do one query at the beginning and then apply some different filters (exclusive between then).  
And then use markdown to show then.

I tried used mapColumn too in order to use then like filters and then use markdown conditionals to print then.  
I haven't tried too much but I think is my best option at this moment. Any alternative?  
Maybe can I use filterrows and clean, or It'll be very inefficient?

Thanks for all.  
Luis

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [January 31, 2020, 8:21am UTC](https://discuss.elastic.co/t/iterate-by-rows-on-an-essql-query/216892/4 "2020-01-31T08:21:57Z")

</div>

I'm not sure I completely understand your use case, could you elaborate on what you are trying to achieve from a user perspective and how your data roughly looks like?

---

<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:** [February 28, 2020, 8:30am UTC](https://discuss.elastic.co/t/iterate-by-rows-on-an-essql-query/216892/5 "2020-02-28T08:30:32Z")

</div>

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