# Filter by current score

**URL:** <https://discuss.elastic.co/t/filter-by-current-score/70344>\
**Category:** Elasticsearch\
**Created:** [January 2, 2017, 9:18am UTC](https://discuss.elastic.co/t/filter-by-current-score/70344 "2017-01-02T09:18:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Florian\_Wilhelm](https://avatars.discourse-cdn.com/v4/letter/f/e36b37/32.png) [@Florian\_Wilhelm](https://discuss.elastic.co/u/Florian_Wilhelm)\
**Post date:** [January 2, 2017, 9:18am UTC](https://discuss.elastic.co/t/filter-by-current-score/70344/1 "2017-01-02T09:18:12Z")

</div>

Assume I have a query that is quite slow due to the usage of many `should` clauses (e.g. location based decay functions) in the `bool` query on many documents. To increase the speed of the query I would like to reformulate the query in a hierarchical way so that easy to check queries like `match` in the should clause are executed on all documents but more expensive queries like 2d decay functions are executed only on the top results, i.e. scores, returned by the easier queries. So it works like a pyramid and on each level I would be able to execute the next level only on the top _n_ or top _x_% results (by score) of the current level.

How would I accomplish something like this? I read about the deprecated `filter: {limit: {value: 10}}` query but it didn't work for me and I don't want to start using deprecated features. The `terminate_after` parameter in the search api is interesting but seems to work only on the top level of the whole query. There is also the advanced `min_score` parameter but that would require that I have a clue at query construction time about the range of my scores. In most cases this is not possible to know in advance. Also I'd like to avoid scripts if possible since on many productive ES installation this feature is disabled due to security concerns.

Does anyone know how I would do that? Thanks!

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [January 2, 2017, 9:38am UTC](https://discuss.elastic.co/t/filter-by-current-score/70344/2 "2017-01-02T09:38:01Z")

</div>

Hi,

maybe the [Rescoring](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-rescore.html) functionality can help you here. You can place all "cheap" query conditions (like filters etc.) in the main query and then re-arrange the top-N results based on a more expensive second query that is only executed on the results of the first. It is also possible to execute multiple rescores in sequence, although I haven't tried that one yet.

---

<div class="post-metadata">

**Author:** ![Florian\_Wilhelm](https://avatars.discourse-cdn.com/v4/letter/f/e36b37/32.png) [@Florian\_Wilhelm](https://discuss.elastic.co/u/Florian_Wilhelm)\
**Post date:** [January 2, 2017, 2:31pm UTC](https://discuss.elastic.co/t/filter-by-current-score/70344/3 "2017-01-02T14:31:52Z")

</div>

Really cool, that is exactly what I was looking for and speeds up my query dramatically. Thanks! How could I miss that in the docs? Dooh!?

---

<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 30, 2017, 2:32pm UTC](https://discuss.elastic.co/t/filter-by-current-score/70344/4 "2017-01-30T14:32:04Z")

</div>

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