# Canvas: visualize with two different fields within the same index

**URL:** <https://discuss.elastic.co/t/canvas-visualize-with-two-different-fields-within-the-same-index/224689>\
**Category:** Kibana\
**Created:** [March 23, 2020, 3:19pm UTC](https://discuss.elastic.co/t/canvas-visualize-with-two-different-fields-within-the-same-index/224689 "2020-03-23T15:19:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![emad101](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emad101/32/82338_2.png) [@emad101](https://discuss.elastic.co/u/emad101)\
**Post date:** [March 23, 2020, 3:19pm UTC](https://discuss.elastic.co/t/canvas-visualize-with-two-different-fields-within-the-same-index/224689/1 "2020-03-23T15:19:51Z")

</div>

Hello,  
I am trying to make a bar chart in Canvas with two fields. I want the Y-axis to have the unique count on 'filed A' and the X-axis to display the top six names in 'field B' that has the most unique count in 'field A' while also excluding some names from the count

I tried the following with ELastic SQL, but it does not seem to give me all the records and I can't limit it to 6

```
SELECT component_name AS value, app_code AS appcode	 
FROM "index**" WHERE NOT (app_code = 'xxxx' 
OR app_code = 'yyyy' OR app_code = 'zzzz' ) 

```

I am able to get the correct result with the visualization tab, but not in canves.  
Any help will be appreciated?

---

<div class="post-metadata">

**Author:** ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)\
**Post date:** [March 23, 2020, 4:32pm UTC](https://discuss.elastic.co/t/canvas-visualize-with-two-different-fields-within-the-same-index/224689/2 "2020-03-23T16:32:03Z")

</div>

You should check [https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-functions-aggs.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-functions-aggs.html) and apply a `GROUP BY` and an aggregation function into your code.  
With the SQL provided you are just selecting all the documents you have, you instead have to group by your app\_code, apply a count aggregation function, and then filter out with WHERE clause.  
You can also add `LIMIT 6` at the end of the query to limit directly on the SQL

---

<div class="post-metadata">

**Author:** ![emad101](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emad101/32/82338_2.png) [@emad101](https://discuss.elastic.co/u/emad101)\
**Post date:** [March 23, 2020, 8:53pm UTC](https://discuss.elastic.co/t/canvas-visualize-with-two-different-fields-within-the-same-index/224689/4 "2020-03-23T20:53:06Z")

</div>

Great, that was very helpful.  
Thank you

---

<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:** [April 20, 2020, 8:53pm UTC](https://discuss.elastic.co/t/canvas-visualize-with-two-different-fields-within-the-same-index/224689/5 "2020-04-20T20:53:15Z")

</div>

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