ES|QL FUSE command
The FUSE processing command merges rows from multiple result sets and assigns
new relevance scores.
FUSE enables hybrid search to combine and score results from multiple queries, together with the FORK command.
FUSE works by:
- Merging rows with matching
<key_columns>values - Assigning new relevance scores using the specified
<fuse_method>algorithm and the values from the<group_column>and<score_column>
FUSE is for search use cases: it merges ranked result sets and computes relevance.
Learn more about how search works in ES|QL.
A LIMIT is required before FUSE, because FUSE can only work with a finite set of rows.
FORK branches do not have an implicit LIMIT 1000.
When using FUSE after FORK, a LIMIT must be added to each FORK branch.
An implicit LIMIT 1000 is added to each FORK branch.
When using FUSE after FORK, FUSE does not require an explicit LIMIT in each FORK branch.
However, as a best practice and to avoid issues when upgrading to newer versions, it is advised to still add an explicit LIMIT before FUSE.
Use default parameters:
FUSE
Specify custom parameters:
FUSE <fuse_method> SCORE BY <score_column> GROUP BY <group_column> KEY BY <key_columns> WITH <options>
fuse_method- Defaults to
RRF. Can be one ofRRF(for Reciprocal Rank Fusion) orLINEAR(for linear combination of scores). Designates which method to use to assign new relevance scores. options- Options for the
fuse_method.
When fuse_method is RRF, options supports the following parameters:
rank_constant- Defaults to
60. Represents therank_constantused in the RRF formula. weights- Defaults to
{}. Allows you to set different weights for RRF scores based ongroup_columnvalues. Refer to the Set custom weights example.
When fuse_method is LINEAR, options supports the following parameters:
normalizer- Defaults to
none. Can be one ofnoneorminmax. Specifies which score normalization method to apply. weights- Defaults to
{}. Allows you to different weights for scores based ongroup_columnvalues. Refer to the Set custom weights example.
score_column- Defaults to
_score. Designates which column to use to retrieve the relevance scores of the input row and where to output the new relevance scores of the merged rows. group_column- Defaults to
_fork. Designates which column represents the result set. key_columns- Defaults to
_id, _index. Rows with matchingkey_columnsvalues are merged.
The following examples use FORK to run parallel queries and FUSE to merge the results.
Run a lexical and a semantic query in parallel with FORK, then merge with FUSE (applies RRF by default):
FROM books METADATA _id, _index, _score
| FORK (WHERE title:"Shakespeare" | SORT _score DESC | LIMIT 100)
(WHERE semantic_title:"Shakespeare" | SORT _score DESC | LIMIT 100)
| FUSE
| SORT _score DESC
- Include document ID, index name, and relevance score
- Fork 1: Lexical search on title field, sorted by relevance score
- Fork 2: Semantic search on semantic_title field, sorted by relevance score
- Merge results using RRF algorithm by default
- sort results by the new scores, since `FUSE` does not do any sorting.
FUSE can also use linear score combination:
FROM books METADATA _id, _index, _score
| FORK (WHERE title:"Shakespeare" | SORT _score DESC | LIMIT 100)
(WHERE semantic_title:"Shakespeare" | SORT _score DESC | LIMIT 100)
| FUSE LINEAR
| SORT _score DESC
- Fork 1: Lexical search on title
- Fork 2: Semantic search on semantic_title
- Merge results using linear combination of scores (equal weights by default)
- sort results by the new scores, since `FUSE` does not do any sorting.
When combining results from semantic and lexical queries through linear combination, we recommend first normalizing the scores from each result set.
The following example uses minmax score normalization.
This means the scores normalize and assign values between 0 and 1, before combining the rows:
FROM books METADATA _id, _index, _score
| FORK (WHERE title:"Shakespeare" | SORT _score DESC | LIMIT 100)
(WHERE semantic_title:"Shakespeare" | SORT _score DESC | LIMIT 100)
| FUSE LINEAR WITH { "normalizer": "minmax" }
| SORT _score DESC
- Fork 1: Lexical search
- Fork 2: Semantic search
- Linear combination with min-max normalization (scales scores to 0-1 range)
- sort results by the new scores, since `FUSE` does not do any sorting.
FUSE allows you to specify different weights to scores, based on the _fork column values, enabling you to control the relative importance of each query branch in the final results.
FROM books METADATA _id, _index, _score
| FORK (WHERE title:"Shakespeare" | SORT _score DESC | LIMIT 100)
(WHERE semantic_title:"Shakespeare" | SORT _score DESC | LIMIT 100)
| FUSE LINEAR WITH { "weights": { "fork1": 0.7, "fork2": 0.3 }, "normalizer": "minmax" }
| SORT _score DESC
- Fork 1: Lexical search
- Fork 2: Semantic search
- Weighted linear combination: 70% lexical, 30% semantic, with min-max normalization
- sort results by the new scores, since `FUSE` does not do any sorting.
These limitations can be present either when:
FUSEis not combined withFORKFUSEdoesn't use the default metadata columns_id,_index,_scoreand_forkFUSEassumes thatkey_columnsare single valued. Whenkey_columnsare multivalued,FUSEcan produce unreliable relevance scores.FUSEautomatically assigns a score value ofNULLif the<score_column>or<group_column>are multivalued.FUSEassumes that the combination ofkey_columnsandgroup_columnis unique. If not,FUSEcan produce unreliable relevance scores.