Hits relation constant value - gte - greater than or equal to

From documentation:
https://www.elastic.co/guide/en/elasticsearch/reference/7.5/search-request-body.html#request-body-search-track-total-hits

"If the total number of hits that match the query is greater than the value set in track_total_hits , the total hits in the response will indicate that the returned value is a lower bound:"

{
    "_shards": ...
    "hits" : {
        "max_score": 1.0,
        "total" : {
            "value": 100,         
            "relation": "gte"     
        },
        "hits": ...
    }
}

"gte" - means "greater than or equal to", why you are using this expression, instead of "gt" - "greater than". greater than the value - means cannot be equal

Could you please clarify the logic of this abbreviation.
Best regards, Andrey

1 Like

@jimczi Should we consider this as a bug?

The documentation is misleading, I agree. It should say "If the total number of hits that match the query is greater or equals than the value... Can you open an issue ?

1 Like

@jimczi should value "greater than or equal to" also be changed to "greater than"?

(example for 10000 default value)

according to current implementation:

  • "equal to" is for range from 1 to 10000
  • "greater than or equal to" is for range from 10001
    But 10001 is already not equal, its just "greater than"

If you just change documentation, you expect that

  • "equal to" is for range from 1 to 9999
  • "greater than or equal to" is for range from 10000
    But current implementation is different

we should never return a value that is greater than the provided track_total_hits so if you set 10000 you can only have values that range between 0 and 10000. The relation will be eq for results between 0 and 9999 and 10000 will set the relation to gte so I think we're good ?

But, I mean, that we cannot be sure in that case, if 10000 is equal or already not? E.g. if there are 10000 we got "equal".

"greater than or equal to" leads to the suspense. It can be greater OR equal
At the same time, "greater than" - just greater than the current value.

Why it cannot be just "greater than" starting when the value is more than 10000
If its 10000 and less, will be "equal"

Why it cannot be just "greater than" starting when the value is more than 10000
If its 10000 and less, will be "equal"

Because that's the limit where we stop counting, when we reach 10000 documents in your case. So we don't know if there are more documents or not, the only thing we know is that we collected 10000 documents so the value total number can be equals or greater than this value.

we got "eq" instead of "gte"

Ah sorry I forgot that we have a special handling in Elasticsearch that differs from Lucene. We count accurately up to 10,000 and return gte for values that are greater so you're right. I also agree that it can be confusing so can you open an issue in Lucene. I am on vacations now but will take a look when I come back or someone else from the team will pick that up. Thanks for catching this @Andrey_Masunov!

1 Like

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