# Multiple ways to provide sort order corresponding to a field name?

**URL:** <https://discuss.elastic.co/t/multiple-ways-to-provide-sort-order-corresponding-to-a-field-name/68712>\
**Category:** Elasticsearch\
**Created:** [December 12, 2016, 12:35pm UTC](https://discuss.elastic.co/t/multiple-ways-to-provide-sort-order-corresponding-to-a-field-name/68712 "2016-12-12T12:35:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amit\_saxena](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@amit\_saxena](https://discuss.elastic.co/u/amit_saxena)\
**Post date:** [December 12, 2016, 12:35pm UTC](https://discuss.elastic.co/t/multiple-ways-to-provide-sort-order-corresponding-to-a-field-name/68712/1 "2016-12-12T12:35:25Z")

</div>

Hi all,

In case of querying the data, while going through the documentation, I found two references to specify the sort order corresponding to a field.

1. Option 1

2. Option 2

In first option, the sort order was provided as a value to the field name. However in case of second option, the sorting details to a specific field name was provided as a document with static key as "order" and the value corresponding to the sort order.

In case both the options are correct, I want to know when should we use the second option compared to the first.

Please help and suggest.

Regards,  
Amit Saxena

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [December 12, 2016, 2:45pm UTC](https://discuss.elastic.co/t/multiple-ways-to-provide-sort-order-corresponding-to-a-field-name/68712/2 "2016-12-12T14:45:00Z")

</div>

Option 1 is just shorter and should be used when nothing else than the sort order is specified. If you need to specify more options (`missing`, ...) then you have option 2.  
You also have a third option when you want to specify a field name and that the default options are fine for your use case:

```auto
GET /bank/_search { "query": { "match_all": {} }, "sort": ["balance"] }

```

[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort)

---

<div class="post-metadata">

**Author:** ![amit\_saxena](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@amit\_saxena](https://discuss.elastic.co/u/amit_saxena)\
**Post date:** [December 13, 2016, 9:56am UTC](https://discuss.elastic.co/t/multiple-ways-to-provide-sort-order-corresponding-to-a-field-name/68712/3 "2016-12-13T09:56:39Z")

</div>

Hi Jimferenczi,

Thanks for the details, it helped a lot.

Regards,  
Amit Saxena

---

<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 10, 2017, 9:56am UTC](https://discuss.elastic.co/t/multiple-ways-to-provide-sort-order-corresponding-to-a-field-name/68712/4 "2017-01-10T09:56:49Z")

</div>

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