# Sorting array items within single document

**URL:** <https://discuss.elastic.co/t/sorting-array-items-within-single-document/276440>\
**Category:** Elasticsearch\
**Created:** [June 19, 2021, 5:22pm UTC](https://discuss.elastic.co/t/sorting-array-items-within-single-document/276440 "2021-06-19T17:22:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterlen](https://avatars.discourse-cdn.com/v4/letter/p/f475e1/32.png) [@peterlen](https://discuss.elastic.co/u/peterlen)\
**Post date:** [June 19, 2021, 5:22pm UTC](https://discuss.elastic.co/t/sorting-array-items-within-single-document/276440/1 "2021-06-19T17:22:36Z")

</div>

One of our indices contains documents that include an internal array. Say within a given document it contains the following:

"geoEntities" : [  
"France",  
"United States",  
"China",  
"Germany"  
]

I want to be able to do a search that will only return a single document but have Elasticsearch return the document with the countries sorted like:  
"geoEntities" : [  
"China",  
"France",  
"Germany"  
"United States"  
]

I haven't found anything that says this is possible so I am hoping that someone can verify this one way or another.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 21, 2021, 1:17am UTC](https://discuss.elastic.co/t/sorting-array-items-within-single-document/276440/2 "2021-06-21T01:17:20Z")

</div>

Welcome to our community! 😃

Elasticsearch cannot do this for you sorry to say.

---

<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 19, 2021, 1:18am UTC](https://discuss.elastic.co/t/sorting-array-items-within-single-document/276440/3 "2021-07-19T01:18:08Z")

</div>

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