# Terms Lookup + sort

**URL:** <https://discuss.elastic.co/t/terms-lookup-sort/83084>\
**Category:** Elasticsearch\
**Created:** [April 20, 2017, 3:41pm UTC](https://discuss.elastic.co/t/terms-lookup-sort/83084 "2017-04-20T15:41:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [April 28, 2017, 1:18pm UTC](https://discuss.elastic.co/t/terms-lookup-sort/83084/2 "2017-04-28T13:18:14Z")

</div>

Not through the terms lookup functionality. You can think of that as merely grabbing the list of terms to filter from a document, rather than from the query body supplied as part of the request.

But you can [add a sort element](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html) to your query which does the sorting:

```auto
GET /users/user/_search
{
      "query":{
         "terms":{
            "id":{
               "index":"newsfeed",
               "type":"feed",
               "id":"1",
               "path":"likers.id"
            }
         }
      },
      "sort" : [
          { "likers.id" : {"order" : "asc"}},
          "_score"
      ],
}

```

Note that unless that first document is using [Nested Documents](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html) (you can also [read more here](https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-objects.html)) your relationships in the document may not be preserved like you think they are.

---

_[View the full topic](https://discuss.elastic.co/t/terms-lookup-sort/83084)._
