# Sorting with variable names instead of fixed fields

**URL:** <https://discuss.elastic.co/t/sorting-with-variable-names-instead-of-fixed-fields/140976>\
**Category:** Elasticsearch\
**Created:** [July 21, 2018, 3:38am UTC](https://discuss.elastic.co/t/sorting-with-variable-names-instead-of-fixed-fields/140976 "2018-07-21T03:38:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vandanachadha](https://avatars.discourse-cdn.com/v4/letter/v/ccd318/32.png) [@vandanachadha](https://discuss.elastic.co/u/vandanachadha)\
**Post date:** [July 21, 2018, 3:38am UTC](https://discuss.elastic.co/t/sorting-with-variable-names-instead-of-fixed-fields/140976/1 "2018-07-21T03:38:14Z")

</div>

Sorting with a specified fieldname works. But Is there any way I can use a variable name to provide the sorting field. For example:

This works:  
"sort": [

```
   {

     "venue.price": {
       "order": "asc",
       "missing" : "_last"

```

}  
}

BUT this below doesnt:  
let varsort="venue.price";

```
"sort": [

   {

     "field":varsort,
       "order": "asc",
       "missing" : "_last"

     

   }
  }

```

Above gives me error No enum constant org.elasticsearch.search.sort.SortOrder.VENUE.PRICE.TIER"  
I have tried replacing "field" with "by", same problem.

---

<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:** [August 18, 2018, 3:38am UTC](https://discuss.elastic.co/t/sorting-with-variable-names-instead-of-fixed-fields/140976/2 "2018-08-18T03:38:14Z")

</div>

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