# Sorting lists in painless

**URL:** <https://discuss.elastic.co/t/sorting-lists-in-painless/215530>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [January 17, 2020, 10:21pm UTC](https://discuss.elastic.co/t/sorting-lists-in-painless/215530 "2020-01-17T22:21:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ncrmro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ncrmro/32/61004_2.png) [@ncrmro](https://discuss.elastic.co/u/ncrmro)\
**Post date:** [January 17, 2020, 10:21pm UTC](https://discuss.elastic.co/t/sorting-lists-in-painless/215530/1 "2020-01-17T22:21:22Z")

</div>

In a script\_field I'm trying sort and array of objects by a sub field. What is the correct way to sort these.

Eg each locations has a distance field and i'd like to order the objects in the list by distance.

```
List locations = params['_source']['locations'];
```

---

<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 14, 2020, 10:21pm UTC](https://discuss.elastic.co/t/sorting-lists-in-painless/215530/2 "2020-02-14T22:21:25Z")

</div>

Closed on February 14, 2020, 10:21pm UTC

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