Skip to content

Conversation

@pquentin
Copy link
Member

Reverts #5576

Turns out this is not supported by Elasticsearch! See elastic/elasticsearch#137421. Sorry.

@github-actions
Copy link
Contributor

Following you can find the validation changes against the target branch for the API.

API Status Request Response
search 🔴 2647/2659 → 2641/2659 2659/2659

You can validate this API yourself by using the make validate target.

@pquentin
Copy link
Member Author

To clarify what is going on, there are two ways to use function_score, either with a shortcut (that we don't support):

GET /_search
{
  "query": {
    "function_score": {
      "query": { "match_all": {} },
      "boost": "5",
      "random_score": {},
      "boost_mode": "multiply"
    }
  }
}

Or with a functions array (that we support):

GET /_search
{
  "query": {
    "function_score": {
      "query": { "match_all": {} },
      "boost": "5",
      "functions": [
        {
          "filter": { "match": { "test": "bar" } },
          "random_score": {},
          "weight": 23
        },
        {
          "filter": { "match": { "test": "cat" } },
          "weight": 42
        }
      ],
      "max_boost": 42,
      "score_mode": "max",
      "boost_mode": "multiply",
      "min_score": 42
    }
  }
}

However, those are complex examples; in many YAML tests, we just see this:

GET /_search
{
  "query": {
    "function_score": {
      "random_score": {},
    }
  }
}

Which passes validation on the main branch, thanks to the current definition of FunctionScoreQuery. Here are the relevant bits:

/**
 * @shortcut_property functions
 */
export class FunctionScoreQuery extends QueryBase {
  /**
   * One or more functions that compute a new score for each document returned by the query.
   */
  functions?: FunctionScoreContainer | FunctionScoreContainer[]
}

The fact that 1/ we allow FunctionScoreContainer in functions and 2/ shortcut_property is still defined on functions makes all YAML tests about function_score pass, even though it is technically wrong. I think we have two options:

  1. Remove the shortcut_property and define functions as FunctionScoreContainer[] - clarifying that we don't support the shortcut form at all.
  2. Keep both the shortcut_property and keep defining functions as FunctionScoreContainer | FunctionScoreContainer[], which makes the easy case work while allowing wrong things.

@pquentin pquentin merged commit ea95e94 into main Oct 31, 2025
13 of 14 checks passed
@pquentin pquentin deleted the revert-5576-functions-score-single-function branch October 31, 2025 10:37
github-actions bot pushed a commit that referenced this pull request Oct 31, 2025
github-actions bot pushed a commit that referenced this pull request Oct 31, 2025
github-actions bot pushed a commit that referenced this pull request Oct 31, 2025
pquentin added a commit that referenced this pull request Oct 31, 2025
#5589) (#5592)

This reverts commit 9bd939c.

(cherry picked from commit ea95e94)

Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co>
pquentin added a commit that referenced this pull request Oct 31, 2025
#5589) (#5591)

This reverts commit 9bd939c.

(cherry picked from commit ea95e94)

Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co>
pquentin added a commit that referenced this pull request Oct 31, 2025
#5589) (#5590)

This reverts commit 9bd939c.

(cherry picked from commit ea95e94)

Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co>
margaretjgu pushed a commit that referenced this pull request Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants