# \_source sorting while retrieving the data from es

**URL:** <https://discuss.elastic.co/t/source-sorting-while-retrieving-the-data-from-es/321189>\
**Category:** Elasticsearch\
**Created:** [December 14, 2022, 7:56am UTC](https://discuss.elastic.co/t/source-sorting-while-retrieving-the-data-from-es/321189 "2022-12-14T07:56:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gojo](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Gojo](https://discuss.elastic.co/u/Gojo)\
**Post date:** [December 14, 2022, 7:56am UTC](https://discuss.elastic.co/t/source-sorting-while-retrieving-the-data-from-es/321189/1 "2022-12-14T07:56:53Z")

</div>

hi if iam a query like this

```auto
query = {"query":{"bool":{"must":[{
            "range":{
                "timestamp":{
                    from_time_key:from_time,
                    to_time_key:to_time
                    }
                }
            }
            ]}},"_source":["timestamp","host","program","severity","severity_code","facility","facility_code","pri","tag","message"]}

```

iam getting the data but not in the order which i have given in the source field , how can i sort it according to the format which i have given above

---

<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:** [December 14, 2022, 11:47pm UTC](https://discuss.elastic.co/t/source-sorting-while-retrieving-the-data-from-es/321189/2 "2022-12-14T23:47:35Z")

</div>

JSON is not an ordered data structure, so there's no way to do that sorry.

---

<div class="post-metadata">

**Author:** ![Gojo](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Gojo](https://discuss.elastic.co/u/Gojo)\
**Post date:** [December 19, 2022, 8:40am UTC](https://discuss.elastic.co/t/source-sorting-while-retrieving-the-data-from-es/321189/3 "2022-12-19T08:40:36Z")

</div>

> [@warkolm](#):
>
> JSON is not an ordered data structure, so there's no way to do that sorry.

ok cool

---

<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:** [January 16, 2023, 8:40am UTC](https://discuss.elastic.co/t/source-sorting-while-retrieving-the-data-from-es/321189/4 "2023-01-16T08:40:38Z")

</div>

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