# Sort results by size of array

**URL:** <https://discuss.elastic.co/t/sort-results-by-size-of-array/9339>\
**Category:** Elasticsearch\
**Created:** [October 12, 2012, 3:48pm UTC](https://discuss.elastic.co/t/sort-results-by-size-of-array/9339 "2012-10-12T15:48:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![banderon1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/banderon1/32/2689_2.png) [@banderon1](https://discuss.elastic.co/u/banderon1)\
**Post date:** [October 12, 2012, 3:48pm UTC](https://discuss.elastic.co/t/sort-results-by-size-of-array/9339/1 "2012-10-12T15:48:24Z")

</div>

In my index, I have some numeric id values in an array. Is it possible to  
sort (or boost) docs that have more items in this array?

For example, a doc that has 10 values in the array would be at the top of  
the list, while a doc with an empty array would be at the bottom.

--

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [October 12, 2012, 6:37pm UTC](https://discuss.elastic.co/t/sort-results-by-size-of-array/9339/2 "2012-10-12T18:37:59Z")

</div>

why don't you index the array size into a different field and sort on that?

On Friday, October 12, 2012 5:48:25 PM UTC+2, banderon1 wrote:

> In my index, I have some numeric id values in an array. Is it possible to  
> sort (or boost) docs that have more items in this array?
> 
> For example, a doc that has 10 values in the array would be at the top of  
> the list, while a doc with an empty array would be at the bottom.

--

---

<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:** [July 6, 2017, 3:09am UTC](https://discuss.elastic.co/t/sort-results-by-size-of-array/9339/3 "2017-07-06T03:09:02Z")

</div>


