Skip to content

[BUG] function score query returned an invalid (negative) score with multi match cross fields query #7860

@snikoyo

Description

@snikoyo

Describe the bug

The cross_fields scoring type can produce negative scores when some documents are missing fields.

This bug was already reported for Elasticsearch and fixed with this MR for Elasticsearch >= 8.4.

We encounter it randomly on production for certain queries when we search a field that does not exist in all documents.
It appears deterministically for these search queries.

Error message:

{ "error": { "root_cause": [ { "type": "exception", "reason": "function score query returned an invalid score: -0.05202394 for doc: 1123896" } ], "type": "search_phase_execution_exception", "reason": "all shards failed", "phase": "query", "grouped": true, "failed_shards": [ { "shard": 0, "index": "my_index", "node": "my_node", "reason": { "type": "exception", "reason": "function score query returned an invalid score: -0.05202394 for doc: 1123896" } } ] }, "status": 500 }

The document number mentioned in the error message does not exist.

To Reproduce

The steps to reproduce are in the above mentioned bug report for Elasticsearch.

Expected behavior

The function score should never return a negative value.

Plugins

None.

Host/Environment (please complete the following information):

OpenSearch version: 2.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Search:RelevancebugSomething isn't workingv2.15.0Issues and PRs related to version 2.15.0v3.0.0Issues and PRs related to version 3.0.0

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions