- 
                Notifications
    
You must be signed in to change notification settings  - Fork 25.6k
 
ES\QL: Fix scoring for non full text functions #124540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            carlosdelest
  merged 30 commits into
  elastic:main
from
carlosdelest:bugfix/esql-fix-scoring-full-text-functions
  
      
      
   
  Mar 18, 2025 
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            30 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      338e82b
              
                Score for match all is 0.0 now
              
              
                carlosdelest af11e3b
              
                Add scorable() method to Query class, and take it into account for cr…
              
              
                carlosdelest 0a2bb77
              
                Add integration tests
              
              
                carlosdelest 3fdce04
              
                Use boost() in queries according to whether they're scorable or not
              
              
                carlosdelest ddd2efb
              
                Update docs/changelog/124540.yaml
              
              
                carlosdelest 82b5432
              
                [CI] Auto commit changes from spotless
              
              
                 1a2f653
              
                Fix tests
              
              
                carlosdelest 4f7a308
              
                Fix tests
              
              
                carlosdelest 86e7563
              
                Fix tests
              
              
                carlosdelest da0701a
              
                Fix tests
              
              
                carlosdelest 30a052e
              
                Fix tests
              
              
                carlosdelest bd7f4f6
              
                Spotless
              
              
                carlosdelest 65c863c
              
                Merge remote-tracking branch 'carlosdelest/bugfix/esql-fix-scoring-fu…
              
              
                carlosdelest 48b4495
              
                Fix changelog
              
              
                carlosdelest 7fb6d10
              
                Add all full text functions to scoring tests
              
              
                carlosdelest bf330f0
              
                Minor changes
              
              
                carlosdelest 0c9f80a
              
                Fix scores in tests, add capability for bwc
              
              
                carlosdelest 0913f82
              
                Add docs
              
              
                carlosdelest 92436af
              
                Fix forbidden APIs
              
              
                carlosdelest bf8474c
              
                Merge remote-tracking branch 'origin/main' into bugfix/esql-fix-scori…
              
              
                carlosdelest c0b622b
              
                Fix merges, add some testing
              
              
                carlosdelest 5f25b97
              
                [CI] Auto commit changes from spotless
              
              
                 f932406
              
                Fix test merges
              
              
                carlosdelest 347c651
              
                Merge remote-tracking branch 'carlosdelest/bugfix/esql-fix-scoring-fu…
              
              
                carlosdelest 967d0fe
              
                Fix test merges
              
              
                carlosdelest afab198
              
                Add Query.unscore() to remove scores from a QueryBuilder, use it from…
              
              
                carlosdelest c7cd78c
              
                Merge remote-tracking branch 'origin/main' into bugfix/esql-fix-scori…
              
              
                carlosdelest 2a618e1
              
                Fix bwc test capability
              
              
                carlosdelest 66935a0
              
                Merge remote-tracking branch 'origin/main' into bugfix/esql-fix-scori…
              
              
                carlosdelest e641e38
              
                Use filter again in PushFiltersToSource when no scoring is needed
              
              
                carlosdelest File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 124540 | ||
| summary: "ES|QL: Fix scoring for full text functions" | ||
| area: ES|QL | ||
| type: bug | ||
| issues: [] | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -28,6 +28,10 @@ | |
| * </p> | ||
| */ | ||
| public abstract class Query { | ||
| 
     | 
||
| // Boosting used to remove scoring from queries that don't contribute to it | ||
| public static final float NO_SCORE_BOOST = 0.0f; | ||
| 
     | 
||
| private final Source source; | ||
| 
     | 
||
| protected Query(Source source) { | ||
| 
        
          
        
         | 
    @@ -46,9 +50,20 @@ public Source source() { | |
| 
     | 
||
| /** | ||
| * Convert to an Elasticsearch {@link QueryBuilder} all set up to execute | ||
| * the query. | ||
| * the query. This ensures that queries have appropriate boosting for scoring. | ||
| */ | ||
| public final QueryBuilder toQueryBuilder() { | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the method changed to include boosting information according to the query being scorable.   | 
||
| QueryBuilder builder = asBuilder(); | ||
| if (scorable() == false) { | ||
| builder = unscore(builder); | ||
| } | ||
| return builder; | ||
| } | ||
| 
     | 
||
| /** | ||
| * Used internally to convert to retrieve a {@link QueryBuilder} by queries. | ||
| */ | ||
| public abstract QueryBuilder asBuilder(); | ||
| protected abstract QueryBuilder asBuilder(); | ||
| 
     | 
||
| /** | ||
| * Used by {@link Query#toString()} to produce a pretty string. | ||
| 
          
            
          
           | 
    @@ -85,4 +100,18 @@ public String toString() { | |
| public Query negate(Source source) { | ||
| return new NotQuery(source, this); | ||
| } | ||
| 
     | 
||
| /** | ||
| * Defines whether a query should contribute to the overall score | ||
| */ | ||
| public boolean scorable() { | ||
| return false; | ||
| } | ||
| 
     | 
||
| /** | ||
| * Removes score from a query builder, so score is not affected by the query | ||
| */ | ||
| public static QueryBuilder unscore(QueryBuilder builder) { | ||
| return builder.boost(NO_SCORE_BOOST); | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asBuilder()is replaced bytoQueryBuilder()- see below