# How search with limit and top results?

**URL:** <https://discuss.elastic.co/t/how-search-with-limit-and-top-results/33556>\
**Category:** Elasticsearch\
**Created:** [November 2, 2015, 6:35pm UTC](https://discuss.elastic.co/t/how-search-with-limit-and-top-results/33556 "2015-11-02T18:35:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tenaz3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tenaz3/32/5648_2.png) [@tenaz3](https://discuss.elastic.co/u/tenaz3)\
**Post date:** [November 2, 2015, 6:35pm UTC](https://discuss.elastic.co/t/how-search-with-limit-and-top-results/33556/1 "2015-11-02T18:35:22Z")

</div>

I want to sort 7 most expansive products with validate time ascending. I did:

```
{
"from": 0,
"size": 7,
"query": {
    "filtered": {
        "query": {
            "match_all": {}
        }
    }
},
"sort": [{
    "price": {
        "order": "desc"
    }
}, {
    "validate_time": {
        "order": "asc"
    }
}]
}

```

But I want this top 7 expansive products ordered by validate\_time

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [November 2, 2015, 7:02pm UTC](https://discuss.elastic.co/t/how-search-with-limit-and-top-results/33556/2 "2015-11-02T19:02:15Z")

</div>

What you've got will sort products by price, breaking ties with validation\_time. I don't believe there is a way to get the top 7 by price and then sort them by something else.

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 2, 2015, 7:58pm UTC](https://discuss.elastic.co/t/how-search-with-limit-and-top-results/33556/3 "2015-11-02T19:58:29Z")

</div>

Perhaps with the query rescorer?  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-rescore.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-rescore.html)

There is no explicit sorting in the query scorer, your scorer will need to  
submit a score based on the field. Should be easy with a date field.

Ivan

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [November 2, 2015, 8:16pm UTC](https://discuss.elastic.co/t/how-search-with-limit-and-top-results/33556/4 "2015-11-02T20:16:22Z")

</div>

> [@Ivan](#):
>
> Perhaps with the query rescorer?

Yes! That'll do it! I'd forgotten about the rescorer.

---

<div class="post-metadata">

**Author:** ![tenaz3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tenaz3/32/5648_2.png) [@tenaz3](https://discuss.elastic.co/u/tenaz3)\
**Post date:** [November 2, 2015, 10:44pm UTC](https://discuss.elastic.co/t/how-search-with-limit-and-top-results/33556/5 "2015-11-02T22:44:33Z")

</div>

Thanks, Ill take a look! =D

---

<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 5, 2017, 11:41pm UTC](https://discuss.elastic.co/t/how-search-with-limit-and-top-results/33556/6 "2017-07-05T23:41:11Z")

</div>


