- 
                Notifications
    
You must be signed in to change notification settings  - Fork 25.6k
 
Rewrite more queries to match_none when they target an unmapped field #132987
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
base: main
Are you sure you want to change the base?
Changes from 10 commits
14042d0
              fd6c01f
              d14cac7
              51b6f9f
              6241fd3
              e592c6c
              9f20af9
              b54fff7
              e466d94
              3e304b2
              f96eb8f
              d733d12
              d6440b4
              2bad98d
              282732d
              e62fdf2
              edfeae3
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pr: 132987 | ||
| summary: Rewrite more queries to `match_none` when they target an unmapped field | ||
| area: Search | ||
| type: enhancement | ||
| issues: | ||
| - 97129 | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -473,7 +473,7 @@ public void testTermQueryBigInt() throws Exception { | |
| 
     | 
||
| public void testTooLongRegexInRegexpQuery() throws Exception { | ||
| createIndex("idx"); | ||
| indexRandom(true, prepareIndex("idx").setSource("{}", XContentType.JSON)); | ||
| indexRandom(true, prepareIndex("idx").setSource("num", "value")); | ||
| 
         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. no more failure when targeting an unmapped field, the test needs fixing to target a mapped field.  | 
||
| 
     | 
||
| int defaultMaxRegexLength = IndexSettings.MAX_REGEX_LENGTH_SETTING.get(Settings.EMPTY); | ||
| StringBuilder regexp = new StringBuilder(defaultMaxRegexLength); | ||
| 
          
            
          
           | 
    ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -460,6 +460,15 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws | |
| }); | ||
| return newShapeQueryBuilder(this.fieldName, supplier::get, this.indexedShapeId).relation(relation); | ||
| } | ||
| return super.doRewrite(queryRewriteContext); | ||
| } | ||
| 
     | 
||
| @Override | ||
| protected QueryBuilder doIndexMetadataRewrite(QueryRewriteContext context) throws IOException { | ||
| MappedFieldType fieldType = context.getFieldType(fieldName); | ||
| if (fieldType == null) { | ||
| return new MatchNoneQueryBuilder("The \"" + getName() + "\" query was rewritten to a \"match_none\" query."); | ||
| } | ||
| return this; | ||
| } | ||
| 
         
      Comment on lines
    
      +467
     to 
      473
    
   
  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. 
 There are a bunch of these (HasChildQueryBuilder, HasParentQueryBuilder, NestedQueryBuilder, GeoGridQueryBuilder,ParentIdQueryBuilder, and maybe more..but these are the ones I found quickly).  | 
||
| 
     | 
||
| 
          
            
          
           | 
    ||
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.
configuring the context was missing, hence the configuration values were not available to the underlying query rewrite. This fixes it.