Results ranking on empty query ""

Hi there :wave:

I wanted to know how EAP ranks / orders results when we perform a search with an empty query, for example, like so:

POST /api/as/v1/engines/my-engine/search.json

{"query":"", "page":{"size":50}}

From the documentation it is clear that it matches all documents but would like to understand the order in which they are returned.

Furthermore, would boosting rules that are configured in the engine continue to be respected in such scenario ?

Thanks in advance.

Hi @Gerardo_Zenobi, since the empty query string equally matches all documents, the assigned score is 1.0 for each document (you can check this under the _meta.score property of the resulting hits). Therefore the sorting is not deterministic.

If you want to sort the results in this scenario, check out the sorting controls documentation.

Hope this helps!

Thanks for the answer @demjened.

I did notice the scores on my empty query results were all the same.

In my case, the value is 21. I believe that it is because I have 2 value boosts on two different fields set to 10 which would explain the 20 points. And would confirm boosts take place in empty query searches.

However, I have multiple searchable fields in my engine schema, does the document only get's a 1 on empty queries even though we might have multiple fields to search in ?

Thanks in advance.

Hmm, interesting. I replicated your setup on Elastic Cloud version 8.7:

  • Created a search engine with an underlying index
  • Set the weight of two fields to 10, left the others at the default 1
  • Ran this query:
{"query":"", "page":{"size":50}}

I checked the native Elasticsearch query that was generated and executed by the engine, and found no trace of the configured weights (boosts):

{
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      }
    }
  },
  "sort": [
    {
      "_score": "desc"
    },
    {
      "_doc": "desc"
    }
  ],
  "size": 50,
  "from": 0
  // Other controls such as _source, highlight...
}

All hits in the resultset have a constant score of 1.0.

It is only when I pass an actual value in query that the generated query includes various boosts on the weighted fields and subfields, and the hits' scores differ.

Is your experience different from this? If so, let me know what version you are on.

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