How to stop score calculating?

I have a couple of questions in my mind regarding query tuning in Elastic search

  1. Sometimes score for result hits are null, though the query written in Query Context , why?
  2. Is there any configuration in Elastic search to disable score calculation?
  3. Generally speaking, how expensive score calculation is?
  4. I am used to wrapping all my queries in a bool { filter } to take them into the filter context, Is this a right strategy to force queries to run in a filter context or there are better ways?

Thanks in advance

  1. I believe this happens if the document doesn't have any fields that are in the query. There's nothing to score so the score is null. I might be wrong about this though, would have to look at the docs and query in question

  2. Putting all the query components in a filtering context will entirely disable scoring. It'll just be looking for match/no-match

  3. Scoring is fairly cheap, it's essentially a few extra math operations per document (you can see the BM-25 algorithm here: https://www.elastic.co/blog/practical-bm25-part-2-the-bm25-algorithm-and-its-variables). But if you're repeating that scoring operation for a dozen query components times a few billion matching documents... it can add up.

    If scoring adds just 1 nanosecond per document and your query matches a billion docs, that adds up to an extra second of latency. I completely made up those numbers, but it does illustrate how even a tiny amount per doc can have a big impact over many documents.

    In practice scoring doesn't have that big of an impact, because most queries don't match a billion docs and the scoring itself is highly optimized and probably well under 1ns. But it's a good way to think about it

  4. That's the correct strategy. If something doesn't need scoring, put it in the filter clause of a boolean query. Or you can use the filter clause of a constant_score query for the same effect.

2 Likes

Thank you so much

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