# Optimizing search requests for speed and relevance, score "margin"

**URL:** <https://discuss.elastic.co/t/optimizing-search-requests-for-speed-and-relevance-score-margin/93277>\
**Category:** Elasticsearch\
**Created:** [July 15, 2017, 10:37pm UTC](https://discuss.elastic.co/t/optimizing-search-requests-for-speed-and-relevance-score-margin/93277 "2017-07-15T22:37:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kradem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kradem/32/17895_2.png) [@kradem](https://discuss.elastic.co/u/kradem)\
**Post date:** [July 15, 2017, 10:37pm UTC](https://discuss.elastic.co/t/optimizing-search-requests-for-speed-and-relevance-score-margin/93277/1 "2017-07-15T22:37:35Z")

</div>

I have a custom app using elasticsearch-py and my searches are way slower than the production app should be. Those queries include function\_score with stored scripts side by side with bool should queries. And that's only half of the problem as I don't know how to accomplish base functionality too.

That base functionality means that major branch of my for now large and complex query should have at least predefined score and if it doesn't then that document doesn't qualify.

Let's say that major "branch" is a function\_score and if it returns score greater or equal 0.5 then the search should continue to the next branch. The very next branch is a bool should query and it qualifies for every score greater than 20.0, and so on.

Is there any way I could limit score if it reaches some value? For example whole search could be done in one request with boost on major branch with value of 20 or so, but the problem is that second branch could have score for example 150.0 and I want it to count as it is just 20.0 (margin is 20). In combination with the perfect result of the major branch (1.0 script result boosted with 20) it qualifies the same as original result of 20.0 (that's not "truncated" from 150.0).

Another approach would be that the branches participate with the percentage. For example major branch score participate with 40% to the final result, second branch participate with 20% to the final score, and so on. Is there any way to accomplish that?

Please let me know if you want me to explain more (or simpler 🙂 ) what I want to achieve!

Best regards!

---

<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 12, 2017, 10:37pm UTC](https://discuss.elastic.co/t/optimizing-search-requests-for-speed-and-relevance-score-margin/93277/2 "2017-08-12T22:37:55Z")

</div>

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