# Determine ranking result

**URL:** <https://discuss.elastic.co/t/determine-ranking-result/88906>\
**Category:** Elasticsearch\
**Created:** [June 10, 2017, 5:03am UTC](https://discuss.elastic.co/t/determine-ranking-result/88906 "2017-06-10T05:03:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pman](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@pman](https://discuss.elastic.co/u/pman)\
**Post date:** [June 10, 2017, 5:03am UTC](https://discuss.elastic.co/t/determine-ranking-result/88906/1 "2017-06-10T05:03:36Z")

</div>

I am running ES and PHP. I am trying to display stats when I view a specific document.

Suppose you have any search result in Elasticsearch, like this list of big cities sorted by population desc:

sort order ranking - name - population

rank 1 - CITY A - pop. 5m

rank 2 - CITY B - pop. 4m

rank 3 - CITY C - pop. 3m

When I now view CITY B (rank 2) on a web page (by its \_id) I want to show 'next city' (rank 3) and 'previous city' (rank 1) links when I view the city ranked 2 -- taking into account the original query.

How can this be done? I could not find anything about this topic.

---

<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:** [June 12, 2017, 7:20am UTC](https://discuss.elastic.co/t/determine-ranking-result/88906/2 "2017-06-12T07:20:58Z")

</div>

You can use `search_after`:  
[https://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-search-after.html](https://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-search-after.html)

With this feature you can return the documents that are ranked "before" or "after" another document.

---

<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 10, 2017, 7:21am UTC](https://discuss.elastic.co/t/determine-ranking-result/88906/3 "2017-07-10T07:21:01Z")

</div>

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