- 
                Notifications
    You must be signed in to change notification settings 
- Fork 25.6k
Add BWC test for field-caps #84455
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
      
      
    
  
     Merged
                    Add BWC test for field-caps #84455
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      e9f9b22
              
                Add BWC test for field-caps
              
              
                dnhatn bd744fa
              
                Merge remote-tracking branch 'elastic/master' into bwc_field_caps
              
              
                dnhatn f2a9f1c
              
                Merge remote-tracking branch 'elastic/master' into bwc_field_caps
              
              
                dnhatn 9ef28d9
              
                spotless
              
              
                dnhatn 11568e6
              
                Merge branch 'master' into bwc_field_caps
              
              
                dnhatn b877845
              
                Wording
              
              
                dnhatn c5fb732
              
                Split into multiple tests
              
              
                dnhatn 22e6549
              
                Merge branch 'master' into bwc_field_caps
              
              
                elasticmachine 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
        
          
          
            255 changes: 255 additions & 0 deletions
          
          255 
        
  qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/FieldCapsIT.java
  
  
      
      
   
        
      
      
    
  
    
      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,255 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|  | ||
| package org.elasticsearch.upgrades; | ||
|  | ||
| import org.elasticsearch.action.fieldcaps.FieldCapabilitiesResponse; | ||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.index.query.QueryBuilder; | ||
| import org.elasticsearch.index.query.QueryBuilders; | ||
| import org.elasticsearch.xcontent.json.JsonXContent; | ||
| import org.junit.Before; | ||
|  | ||
| import java.util.List; | ||
|  | ||
| import static org.hamcrest.Matchers.contains; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
|  | ||
| /** | ||
| * Since ES 8.2, field-caps internal responses are shared between indices that have the same index mapping hash to | ||
| * reduce the transport message size between nodes and clusters, and the memory usage to hold these internal responses. | ||
| * As the optimization is applied for only field-caps requests without index-filter and nodes on 8.2 or later, | ||
| * these BWC tests verify these combinations of field-caps requests: (old|new|mixed indices) and (with|without index filter) | ||
| */ | ||
| public class FieldCapsIT extends AbstractRollingTestCase { | ||
| private static boolean indicesCreated = false; | ||
|  | ||
| @Before | ||
| public void setupIndices() throws Exception { | ||
| if (indicesCreated) { | ||
| return; | ||
| } | ||
| indicesCreated = true; | ||
| final String redMapping = """ | ||
| "properties": { | ||
| "red_field": { "type": "keyword" }, | ||
| "yellow_field": { "type": "integer" }, | ||
| "blue_field": { "type": "keyword" }, | ||
| "timestamp": {"type": "date"} | ||
| } | ||
| """; | ||
| final String greenMapping = """ | ||
| "properties": { | ||
| "green_field": { "type": "keyword" }, | ||
| "yellow_field": { "type": "long" }, | ||
|         
                  dnhatn marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| "blue_field": { "type": "keyword" }, | ||
| "timestamp": {"type": "date"} | ||
| } | ||
| """; | ||
| if (CLUSTER_TYPE == ClusterType.OLD) { | ||
| createIndex("old_red_1", Settings.EMPTY, redMapping); | ||
| createIndex("old_red_2", Settings.EMPTY, redMapping); | ||
| createIndex("old_red_empty", Settings.EMPTY, redMapping); | ||
| createIndex("old_green_1", Settings.EMPTY, greenMapping); | ||
| createIndex("old_green_2", Settings.EMPTY, greenMapping); | ||
| createIndex("old_green_empty", Settings.EMPTY, greenMapping); | ||
| for (String index : List.of("old_red_1", "old_red_2", "old_green_1", "old_green_2")) { | ||
| final Request indexRequest = new Request("POST", "/" + index + "/" + "_doc/1"); | ||
| indexRequest.addParameter("refresh", "true"); | ||
| indexRequest.setJsonEntity( | ||
| Strings.toString(JsonXContent.contentBuilder().startObject().field("timestamp", "2020-01-01").endObject()) | ||
| ); | ||
| assertOK(client().performRequest(indexRequest)); | ||
| } | ||
| } else if (CLUSTER_TYPE == ClusterType.MIXED && FIRST_MIXED_ROUND) { | ||
| createIndex("new_red_1", Settings.EMPTY, redMapping); | ||
| createIndex("new_red_2", Settings.EMPTY, redMapping); | ||
| createIndex("new_red_empty", Settings.EMPTY, redMapping); | ||
| createIndex("new_green_1", Settings.EMPTY, greenMapping); | ||
| createIndex("new_green_2", Settings.EMPTY, greenMapping); | ||
| createIndex("new_green_empty", Settings.EMPTY, greenMapping); | ||
| for (String index : List.of("new_red_1", "new_red_2", "new_green_1", "new_green_2")) { | ||
| final Request indexRequest = new Request("POST", "/" + index + "/" + "_doc/1"); | ||
| indexRequest.addParameter("refresh", "true"); | ||
| indexRequest.setJsonEntity( | ||
| Strings.toString(JsonXContent.contentBuilder().startObject().field("timestamp", "2020-10-10").endObject()) | ||
| ); | ||
| assertOK(client().performRequest(indexRequest)); | ||
| } | ||
| } | ||
| } | ||
|  | ||
| public void testOldIndicesOnly() throws Exception { | ||
| { | ||
| FieldCapabilitiesResponse resp = fieldCaps(List.of("old_red_*"), List.of("*"), null); | ||
| assertThat(resp.getIndices(), equalTo(new String[] { "old_red_1", "old_red_2", "old_red_empty" })); | ||
| assertThat(resp.getField("red_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("red_field").get("keyword").isSearchable()); | ||
| assertThat(resp.getField("yellow_field").keySet(), contains("integer")); | ||
| assertTrue(resp.getField("yellow_field").get("integer").isSearchable()); | ||
| assertThat(resp.getField("blue_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("blue_field").get("keyword").isSearchable()); | ||
| } | ||
| { | ||
| FieldCapabilitiesResponse resp = fieldCaps(List.of("old_*"), List.of("*"), null); | ||
| assertThat( | ||
| resp.getIndices(), | ||
| equalTo(new String[] { "old_green_1", "old_green_2", "old_green_empty", "old_red_1", "old_red_2", "old_red_empty" }) | ||
| ); | ||
| assertThat(resp.getField("red_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("red_field").get("keyword").isSearchable()); | ||
| assertThat(resp.getField("yellow_field").keySet(), contains("integer", "long")); | ||
| assertTrue(resp.getField("yellow_field").get("integer").isSearchable()); | ||
| assertTrue(resp.getField("yellow_field").get("long").isSearchable()); | ||
| assertThat(resp.getField("blue_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("blue_field").get("keyword").isSearchable()); | ||
| } | ||
| } | ||
|  | ||
| public void testOldIndicesWithIndexFilter() throws Exception { | ||
| final QueryBuilder indexFilter = QueryBuilders.rangeQuery("timestamp").gte("2020-01-01").lte("2020-12-12"); | ||
| { | ||
| FieldCapabilitiesResponse resp = fieldCaps(List.of("old_red_*"), List.of("*"), indexFilter); | ||
| assertThat(resp.getIndices(), equalTo(new String[] { "old_red_1", "old_red_2" })); | ||
| assertThat(resp.getField("red_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("red_field").get("keyword").isSearchable()); | ||
| assertThat(resp.getField("yellow_field").keySet(), contains("integer")); | ||
| assertTrue(resp.getField("yellow_field").get("integer").isSearchable()); | ||
| assertThat(resp.getField("blue_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("blue_field").get("keyword").isSearchable()); | ||
| } | ||
| { | ||
| FieldCapabilitiesResponse resp = fieldCaps(List.of("old_*"), List.of("*"), indexFilter); | ||
| assertThat(resp.getIndices(), equalTo(new String[] { "old_green_1", "old_green_2", "old_red_1", "old_red_2" })); | ||
| assertThat(resp.getField("red_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("red_field").get("keyword").isSearchable()); | ||
| assertThat(resp.getField("yellow_field").keySet(), contains("integer", "long")); | ||
| assertTrue(resp.getField("yellow_field").get("integer").isSearchable()); | ||
| assertTrue(resp.getField("yellow_field").get("long").isSearchable()); | ||
| assertThat(resp.getField("blue_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("blue_field").get("keyword").isSearchable()); | ||
| } | ||
| } | ||
|  | ||
| public void testNewIndicesOnly() throws Exception { | ||
| assumeFalse("required mixed or upgraded cluster", CLUSTER_TYPE == ClusterType.OLD); | ||
| { | ||
| FieldCapabilitiesResponse resp = fieldCaps(List.of("new_red_*"), List.of("*"), null); | ||
| assertThat(resp.getIndices(), equalTo(new String[] { "new_red_1", "new_red_2", "new_red_empty" })); | ||
| assertThat(resp.getField("red_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("red_field").get("keyword").isSearchable()); | ||
| assertThat(resp.getField("yellow_field").keySet(), contains("integer")); | ||
| assertTrue(resp.getField("yellow_field").get("integer").isSearchable()); | ||
| assertThat(resp.getField("blue_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("blue_field").get("keyword").isSearchable()); | ||
| } | ||
| { | ||
| FieldCapabilitiesResponse resp = fieldCaps(List.of("new_*"), List.of("*"), null); | ||
| assertThat( | ||
| resp.getIndices(), | ||
| equalTo(new String[] { "new_green_1", "new_green_2", "new_green_empty", "new_red_1", "new_red_2", "new_red_empty" }) | ||
| ); | ||
| assertThat(resp.getField("red_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("red_field").get("keyword").isSearchable()); | ||
| assertThat(resp.getField("yellow_field").keySet(), contains("integer", "long")); | ||
| assertTrue(resp.getField("yellow_field").get("integer").isSearchable()); | ||
| assertTrue(resp.getField("yellow_field").get("long").isSearchable()); | ||
| assertThat(resp.getField("blue_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("blue_field").get("keyword").isSearchable()); | ||
| } | ||
| } | ||
|  | ||
| public void testNewIndicesOnlyWithIndexFilter() throws Exception { | ||
| assumeFalse("required mixed or upgraded cluster", CLUSTER_TYPE == ClusterType.OLD); | ||
| final QueryBuilder indexFilter = QueryBuilders.rangeQuery("timestamp").gte("2020-01-01").lte("2020-12-12"); | ||
| { | ||
| FieldCapabilitiesResponse resp = fieldCaps(List.of("new_red_*"), List.of("*"), indexFilter); | ||
| assertThat(resp.getIndices(), equalTo(new String[] { "new_red_1", "new_red_2" })); | ||
| assertThat(resp.getField("red_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("red_field").get("keyword").isSearchable()); | ||
| assertThat(resp.getField("yellow_field").keySet(), contains("integer")); | ||
| assertTrue(resp.getField("yellow_field").get("integer").isSearchable()); | ||
| assertThat(resp.getField("blue_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("blue_field").get("keyword").isSearchable()); | ||
| } | ||
| { | ||
| FieldCapabilitiesResponse resp = fieldCaps(List.of("new_*"), List.of("*"), indexFilter); | ||
| assertThat(resp.getIndices(), equalTo(new String[] { "new_green_1", "new_green_2", "new_red_1", "new_red_2" })); | ||
| assertThat(resp.getField("red_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("red_field").get("keyword").isSearchable()); | ||
| assertThat(resp.getField("yellow_field").keySet(), contains("integer", "long")); | ||
| assertTrue(resp.getField("yellow_field").get("integer").isSearchable()); | ||
| assertTrue(resp.getField("yellow_field").get("long").isSearchable()); | ||
| assertThat(resp.getField("blue_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("blue_field").get("keyword").isSearchable()); | ||
| } | ||
| } | ||
|  | ||
| public void testAllIndices() throws Exception { | ||
| assumeFalse("required mixed or upgraded cluster", CLUSTER_TYPE == ClusterType.OLD); | ||
| FieldCapabilitiesResponse resp = fieldCaps(List.of("old_*", "new_*"), List.of("*"), null); | ||
| assertThat( | ||
| resp.getIndices(), | ||
| equalTo( | ||
| new String[] { | ||
| "new_green_1", | ||
| "new_green_2", | ||
| "new_green_empty", | ||
| "new_red_1", | ||
| "new_red_2", | ||
| "new_red_empty", | ||
| "old_green_1", | ||
| "old_green_2", | ||
| "old_green_empty", | ||
| "old_red_1", | ||
| "old_red_2", | ||
| "old_red_empty" } | ||
| ) | ||
| ); | ||
| assertThat(resp.getField("red_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("red_field").get("keyword").isSearchable()); | ||
| assertThat(resp.getField("green_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("green_field").get("keyword").isSearchable()); | ||
| assertThat(resp.getField("yellow_field").keySet(), contains("integer", "long")); | ||
| assertTrue(resp.getField("yellow_field").get("integer").isSearchable()); | ||
| assertTrue(resp.getField("yellow_field").get("long").isSearchable()); | ||
| assertThat(resp.getField("blue_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("blue_field").get("keyword").isSearchable()); | ||
| } | ||
|  | ||
| public void testAllIndicesWithIndexFilter() throws Exception { | ||
| assumeFalse("required mixed or upgraded cluster", CLUSTER_TYPE == ClusterType.OLD); | ||
| final QueryBuilder indexFilter = QueryBuilders.rangeQuery("timestamp").gte("2020-01-01").lte("2020-12-12"); | ||
| FieldCapabilitiesResponse resp = fieldCaps(List.of("old_*", "new_*"), List.of("*"), indexFilter); | ||
| assertThat( | ||
| resp.getIndices(), | ||
| equalTo( | ||
| new String[] { | ||
| "new_green_1", | ||
| "new_green_2", | ||
| "new_red_1", | ||
| "new_red_2", | ||
| "old_green_1", | ||
| "old_green_2", | ||
| "old_red_1", | ||
| "old_red_2" } | ||
| ) | ||
| ); | ||
| assertThat(resp.getField("red_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("red_field").get("keyword").isSearchable()); | ||
| assertThat(resp.getField("green_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("green_field").get("keyword").isSearchable()); | ||
| assertThat(resp.getField("yellow_field").keySet(), contains("integer", "long")); | ||
| assertTrue(resp.getField("yellow_field").get("integer").isSearchable()); | ||
| assertTrue(resp.getField("yellow_field").get("long").isSearchable()); | ||
| assertThat(resp.getField("blue_field").keySet(), contains("keyword")); | ||
| assertTrue(resp.getField("blue_field").get("keyword").isSearchable()); | ||
| } | ||
| } | ||
  
    
      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
    
  
  
    
              
  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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.