# Essql LIMIT selecting at random

**URL:** <https://discuss.elastic.co/t/essql-limit-selecting-at-random/202316>\
**Category:** Kibana\
**Created:** [October 4, 2019, 9:22am UTC](https://discuss.elastic.co/t/essql-limit-selecting-at-random/202316 "2019-10-04T09:22:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_Louw](https://avatars.discourse-cdn.com/v4/letter/_/ee7513/32.png) [@\_Louw](https://discuss.elastic.co/u/_Louw)\
**Post date:** [October 4, 2019, 9:22am UTC](https://discuss.elastic.co/t/essql-limit-selecting-at-random/202316/1 "2019-10-04T09:22:27Z")

</div>

I am making a horisontal bar chart, and I only need the top 10 results of my data set.

My code is as follows:  
SELECT role\_, COUNT(role\_) as role\_count FROM "\*canvas" GROUP BY role\_  
ORDER BY role\_count DESC

If I preview, it orders the output perfectly:  
 ![33](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e25b40a383c9b6d34ef7312a10ceaa6861a71d6.png)

But when I add LIMIT 10 on my essql statement, it chooses 10 entries from the whole, and not the first 10:  
 ![444](https://us1.discourse-cdn.com/elastic/original/3X/c/7/c7e57636e13361473a7f14b8765e699632d249f2.png)

I can't see any system in this, and using TOP 10 after SELECT gave an error.  
Can someone please tell me what is going on with LIMIT? 🙂

---

<div class="post-metadata">

**Author:** ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)\
**Post date:** [October 4, 2019, 8:34pm UTC](https://discuss.elastic.co/t/essql-limit-selecting-at-random/202316/2 "2019-10-04T20:34:23Z")

</div>

I think you are hitting this bug: [https://github.com/elastic/elasticsearch/issues/40984](https://github.com/elastic/elasticsearch/issues/40984).  
What ES version are you testing this on?

---

<div class="post-metadata">

**Author:** ![\_Louw](https://avatars.discourse-cdn.com/v4/letter/_/ee7513/32.png) [@\_Louw](https://discuss.elastic.co/u/_Louw)\
**Post date:** [October 7, 2019, 7:10am UTC](https://discuss.elastic.co/t/essql-limit-selecting-at-random/202316/3 "2019-10-07T07:10:10Z")

</div>

I am using ES 6.8.

It sure looks like that issue - but I guess the solution has not been backported correctly thenif I'm still experiencing the bug?

---

<div class="post-metadata">

**Author:** ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)\
**Post date:** [October 7, 2019, 8:41am UTC](https://discuss.elastic.co/t/essql-limit-selecting-at-random/202316/4 "2019-10-07T08:41:55Z")

</div>

@_Louw can you be a bit more precise on the version? The 6.8 branch has 4 releases.

---

<div class="post-metadata">

**Author:** ![\_Louw](https://avatars.discourse-cdn.com/v4/letter/_/ee7513/32.png) [@\_Louw](https://discuss.elastic.co/u/_Louw)\
**Post date:** [October 7, 2019, 8:56am UTC](https://discuss.elastic.co/t/essql-limit-selecting-at-random/202316/5 "2019-10-07T08:56:59Z")

</div>

Ah, this I did not know 🙂

This is my version info:  
"version" : {  
"number" : "6.8.0",  
"build\_flavor" : "default",  
"build\_type" : "tar",  
"build\_date" : "2019-05-15T20:06:13.172855Z",  
"build\_snapshot" : false,  
"lucene\_version" : "7.7.0",  
"minimum\_wire\_compatibility\_version" : "5.6.0",  
"minimum\_index\_compatibility\_version" : "5.0.0"  
}

---

<div class="post-metadata">

**Author:** ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)\
**Post date:** [October 9, 2019, 9:43am UTC](https://discuss.elastic.co/t/essql-limit-selecting-at-random/202316/6 "2019-10-09T09:43:16Z")

</div>

@_Louw sorry for the delay, got the chance to test 6.8.0 now and I realized this is a slightly different bug that was fixed in 6.8.1: [https://github.com/elastic/elasticsearch/issues/42851](https://github.com/elastic/elasticsearch/issues/42851) with [https://github.com/elastic/elasticsearch/pull/43154](https://github.com/elastic/elasticsearch/pull/43154).

Any chance you could test your query on 6.8.1 and see if it's still present? Thanks.  
Again, sorry for the delay and the initial (wrong) assessment of the issue.

---

<div class="post-metadata">

**Author:** ![\_Louw](https://avatars.discourse-cdn.com/v4/letter/_/ee7513/32.png) [@\_Louw](https://discuss.elastic.co/u/_Louw)\
**Post date:** [October 21, 2019, 1:13pm UTC](https://discuss.elastic.co/t/essql-limit-selecting-at-random/202316/7 "2019-10-21T13:13:06Z")

</div>

Yes, I got it tested on 6.8.3, and it works there - 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:** [November 18, 2019, 1:13pm UTC](https://discuss.elastic.co/t/essql-limit-selecting-at-random/202316/8 "2019-11-18T13:13:11Z")

</div>

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