]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8798 prepare move from type STRING to type TEXT or KEYWORD
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 27 Jun 2017 14:20:36 +0000 (16:20 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Wed, 9 Aug 2017 13:09:54 +0000 (15:09 +0200)
15 files changed:
server/sonar-server/src/main/java/org/sonar/server/component/index/ComponentIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettings.java
server/sonar-server/src/main/java/org/sonar/server/es/DefaultIndexSettingsElement.java
server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java
server/sonar-server/src/main/java/org/sonar/server/es/metadata/MetadataIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexDefinition.java
server/sonar-server/src/test/java/org/sonar/server/es/IndexCreatorTest.java
server/sonar-server/src/test/java/org/sonar/server/es/IndexDefinitionHashTest.java
server/sonar-server/src/test/java/org/sonar/server/es/NewIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/index/FooIndexDefinition.java

index 8226567c96ee74904b52a54d0754c9205cc435d3..686577a86f09b2e340248c8eb743b26aed6c5112 100644 (file)
@@ -57,13 +57,13 @@ public class ComponentIndexDefinition implements IndexDefinition {
     NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_COMPONENT.getType())
       .requireProjectAuthorization();
 
-    mapping.stringFieldBuilder(FIELD_PROJECT_UUID).build();
-    mapping.stringFieldBuilder(FIELD_KEY).addSubFields(SORTABLE_ANALYZER).build();
-    mapping.stringFieldBuilder(FIELD_NAME)
+    mapping.keywordFieldBuilder(FIELD_PROJECT_UUID).build();
+    mapping.keywordFieldBuilder(FIELD_KEY).addSubFields(SORTABLE_ANALYZER).build();
+    mapping.keywordFieldBuilder(FIELD_NAME)
       .termVectorWithPositionOffsets()
       .addSubFields(NAME_ANALYZERS)
       .build();
 
-    mapping.stringFieldBuilder(FIELD_QUALIFIER).build();
+    mapping.keywordFieldBuilder(FIELD_QUALIFIER).build();
   }
 }
index 7f96c1bb6fe1ab2dbbed97ecb7e88d94cd9616fd..1743c3e5f41af3076dd7411bad881325153638c7 100644 (file)
@@ -44,16 +44,17 @@ public class DefaultIndexSettings {
   public static final String TYPE = "type";
   public static final String INDEX = "index";
   public static final String ANALYZED = "analyzed";
-  public static final String STRING = "string";
+  public static final String FIELD_TYPE_TEXT = "string";  // ES 5: change to text
+  public static final String FIELD_TYPE_KEYWORD = "string";  // ES 5: change to keyword
   public static final String STANDARD = "standard";
   public static final String PATTERN = "pattern";
   public static final String CUSTOM = "custom";
   public static final String KEYWORD = "keyword";
   public static final String CLASSIC = "classic";
+
   public static final String TRUNCATE = "truncate";
 
   public static final String SUB_FIELD_DELIMITER = ".";
-
   public static final String TRIM = "trim";
   public static final String LOWERCASE = "lowercase";
   public static final String WHITESPACE = "whitespace";
index 77f35b6fd8c153e4cc3c2c64d75d9a8dae54275c..2e20bd0364e71956e96ec1b1fa7933a07f532ede 100644 (file)
@@ -31,6 +31,7 @@ import static org.sonar.server.es.DefaultIndexSettings.ANALYZED;
 import static org.sonar.server.es.DefaultIndexSettings.ANALYZER;
 import static org.sonar.server.es.DefaultIndexSettings.ASCIIFOLDING;
 import static org.sonar.server.es.DefaultIndexSettings.DELIMITER;
+import static org.sonar.server.es.DefaultIndexSettings.FIELD_TYPE_TEXT;
 import static org.sonar.server.es.DefaultIndexSettings.FILTER;
 import static org.sonar.server.es.DefaultIndexSettings.INDEX;
 import static org.sonar.server.es.DefaultIndexSettings.KEYWORD;
@@ -44,7 +45,6 @@ import static org.sonar.server.es.DefaultIndexSettings.PORTER_STEM;
 import static org.sonar.server.es.DefaultIndexSettings.SEARCH_ANALYZER;
 import static org.sonar.server.es.DefaultIndexSettings.STANDARD;
 import static org.sonar.server.es.DefaultIndexSettings.STOP;
-import static org.sonar.server.es.DefaultIndexSettings.STRING;
 import static org.sonar.server.es.DefaultIndexSettings.SUB_FIELD_DELIMITER;
 import static org.sonar.server.es.DefaultIndexSettings.TOKENIZER;
 import static org.sonar.server.es.DefaultIndexSettings.TRIM;
@@ -124,7 +124,7 @@ public enum DefaultIndexSettingsElement {
     @Override
     public SortedMap<String, String> fieldMapping() {
       return ImmutableSortedMap.of(
-        TYPE, STRING,
+        TYPE, FIELD_TYPE_TEXT,
         INDEX, ANALYZED,
         ANALYZER, getName());
     }
@@ -148,7 +148,7 @@ public enum DefaultIndexSettingsElement {
     @Override
     public SortedMap<String, String> fieldMapping() {
       return ImmutableSortedMap.of(
-        TYPE, STRING,
+        TYPE, FIELD_TYPE_TEXT,
         INDEX, ANALYZED,
         ANALYZER, INDEX_GRAMS_ANALYZER.getName(),
         SEARCH_ANALYZER, getName());
@@ -173,7 +173,7 @@ public enum DefaultIndexSettingsElement {
     @Override
     public SortedMap<String, String> fieldMapping() {
       return ImmutableSortedMap.of(
-        TYPE, STRING,
+        TYPE, FIELD_TYPE_TEXT,
         INDEX, ANALYZED,
         ANALYZER, INDEX_PREFIX_ANALYZER.getName(),
         SEARCH_ANALYZER, getName());
@@ -198,7 +198,7 @@ public enum DefaultIndexSettingsElement {
     @Override
     public SortedMap<String, String> fieldMapping() {
       return ImmutableSortedMap.of(
-        TYPE, STRING,
+        TYPE, FIELD_TYPE_TEXT,
         INDEX, ANALYZED,
         ANALYZER, INDEX_PREFIX_CASE_INSENSITIVE_ANALYZER.getName(),
         SEARCH_ANALYZER, getName());
@@ -223,7 +223,7 @@ public enum DefaultIndexSettingsElement {
     @Override
     public SortedMap<String, String> fieldMapping() {
       return ImmutableSortedMap.of(
-        TYPE, STRING,
+        TYPE, FIELD_TYPE_TEXT,
         INDEX, ANALYZED,
         ANALYZER, USER_INDEX_GRAMS_ANALYZER.getName(),
         SEARCH_ANALYZER, getName());
@@ -248,7 +248,7 @@ public enum DefaultIndexSettingsElement {
     @Override
     public SortedMap<String, String> fieldMapping() {
       return ImmutableSortedMap.of(
-        TYPE, STRING,
+        TYPE, FIELD_TYPE_TEXT,
         INDEX, ANALYZED,
         ANALYZER, INDEX_WORDS_ANALYZER.getName(),
         SEARCH_ANALYZER, getName());
index 1d85732cc755fb83c16170e678f5652c71f86d2e..5941710a5ed881cec5ace9a47ea5b75044a9816c 100644 (file)
@@ -40,8 +40,9 @@ import static com.google.common.base.Preconditions.checkArgument;
 import static java.lang.String.format;
 import static org.sonar.server.es.DefaultIndexSettings.ANALYZED;
 import static org.sonar.server.es.DefaultIndexSettings.ANALYZER;
+import static org.sonar.server.es.DefaultIndexSettings.FIELD_TYPE_KEYWORD;
+import static org.sonar.server.es.DefaultIndexSettings.FIELD_TYPE_TEXT;
 import static org.sonar.server.es.DefaultIndexSettings.INDEX;
-import static org.sonar.server.es.DefaultIndexSettings.STRING;
 import static org.sonar.server.es.DefaultIndexSettings.TYPE;
 import static org.sonar.server.es.DefaultIndexSettingsElement.UUID_MODULE_ANALYZER;
 
@@ -138,8 +139,8 @@ public class NewIndex {
       return this;
     }
 
-    public StringFieldBuilder stringFieldBuilder(String fieldName) {
-      return new StringFieldBuilder(this, fieldName);
+    public KeywordFieldBuilder keywordFieldBuilder(String fieldName) {
+      return new KeywordFieldBuilder(this, fieldName);
     }
 
     public NestedFieldBuilder nestedFieldBuilder(String fieldName) {
@@ -176,7 +177,7 @@ public class NewIndex {
 
     public NewIndexType createUuidPathField(String fieldName) {
       return setProperty(fieldName, ImmutableSortedMap.of(
-        TYPE, STRING,
+        TYPE, FIELD_TYPE_TEXT,
         INDEX, ANALYZED,
         ANALYZER, UUID_MODULE_ANALYZER.getName()));
     }
@@ -194,7 +195,7 @@ public class NewIndex {
   /**
    * Helper to define a string field in mapping of index type
    */
-  public static class StringFieldBuilder {
+  public static class KeywordFieldBuilder {
     private final NewIndexType indexType;
     private final String fieldName;
     private boolean disableSearch = false;
@@ -202,7 +203,7 @@ public class NewIndex {
     private boolean termVectorWithPositionOffsets = false;
     private SortedMap<String, Object> subFields = Maps.newTreeMap();
 
-    private StringFieldBuilder(NewIndexType indexType, String fieldName) {
+    private KeywordFieldBuilder(NewIndexType indexType, String fieldName) {
       this.indexType = indexType;
       this.fieldName = fieldName;
     }
@@ -211,7 +212,7 @@ public class NewIndex {
      * Add a sub-field. A {@code SortedMap} is required for consistency of the index settings hash.
      * @see IndexDefinitionHash
      */
-    private StringFieldBuilder addSubField(String fieldName, SortedMap<String, String> fieldDefinition) {
+    private KeywordFieldBuilder addSubField(String fieldName, SortedMap<String, String> fieldDefinition) {
       subFields.put(fieldName, fieldDefinition);
       return this;
     }
@@ -219,9 +220,9 @@ public class NewIndex {
     /**
      * Add subfields, one for each analyzer.
      */
-    public StringFieldBuilder addSubFields(DefaultIndexSettingsElement... analyzers) {
+    public KeywordFieldBuilder addSubFields(DefaultIndexSettingsElement... analyzers) {
       Arrays.stream(analyzers)
-        .forEach(analyzer -> addSubField(analyzer.getSubFieldSuffix(), analyzer.fieldMapping()));
+          .forEach(analyzer -> addSubField(analyzer.getSubFieldSuffix(), analyzer.fieldMapping()));
       return this;
     }
 
@@ -231,7 +232,7 @@ public class NewIndex {
      * https://www.elastic.co/guide/en/elasticsearch/reference/2.3/norms.html
      * https://www.elastic.co/guide/en/elasticsearch/guide/current/scoring-theory.html#field-norm
      */
-    public StringFieldBuilder disableNorms() {
+    public KeywordFieldBuilder disableNorms() {
       this.disableNorms = true;
       return this;
     }
@@ -239,7 +240,7 @@ public class NewIndex {
     /**
      * Position offset term vectors are required for the fast_vector_highlighter (fvh).
      */
-    public StringFieldBuilder termVectorWithPositionOffsets() {
+    public KeywordFieldBuilder termVectorWithPositionOffsets() {
       this.termVectorWithPositionOffsets = true;
       return this;
     }
@@ -249,7 +250,7 @@ public class NewIndex {
      * By default field is "not_analyzed": it is searchable, but index the value exactly
      * as specified.
      */
-    public StringFieldBuilder disableSearch() {
+    public KeywordFieldBuilder disableSearch() {
       this.disableSearch = true;
       return this;
     }
@@ -258,9 +259,9 @@ public class NewIndex {
       Map<String, Object> hash = new TreeMap<>();
       if (subFields.isEmpty()) {
         hash.putAll(ImmutableMap.of(
-          "type", "string",
-          "index", disableSearch ? "no" : "not_analyzed",
-          "norms", ImmutableMap.of("enabled", String.valueOf(!disableNorms))));
+            "type", FIELD_TYPE_KEYWORD,
+            "index", disableSearch ? "no" : "not_analyzed", // ES 5: change to false and true
+            "norms", ImmutableMap.of("enabled", String.valueOf(!disableNorms))));
       } else {
         hash.put("type", "multi_field");
 
@@ -271,18 +272,18 @@ public class NewIndex {
             Object subFieldMapping = entry.getValue();
             if (subFieldMapping instanceof Map) {
               entry.setValue(
-                addFieldToMapping(
-                  (Map<String, String>) subFieldMapping,
-                  "term_vector", "with_positions_offsets"));
+                  addFieldToMapping(
+                      (Map<String, String>) subFieldMapping,
+                      "term_vector", "with_positions_offsets"));
             }
           });
         }
 
         multiFields.put(fieldName, ImmutableMap.of(
-          "type", "string",
-          "index", "not_analyzed",
-          "term_vector", termVectorWithPositionOffsets ? "with_positions_offsets" : "no",
-          "norms", ImmutableMap.of("enabled", "false")));
+            "type", FIELD_TYPE_KEYWORD,
+            "index", "not_analyzed", // ES 5: change to true
+            "term_vector", termVectorWithPositionOffsets ? "with_positions_offsets" : "no",
+            "norms", ImmutableMap.of("enabled", "false")));
 
         hash.put("fields", multiFields);
       }
@@ -313,9 +314,9 @@ public class NewIndex {
       return this;
     }
 
-    public NestedFieldBuilder addStringField(String fieldName) {
+    public NestedFieldBuilder addKeywordField(String fieldName) {
       return setProperty(fieldName, ImmutableMap.of(
-        "type", "string",
+        "type", FIELD_TYPE_KEYWORD,
         "index", "not_analyzed"));
     }
 
index 469f16afe39818b37256d94325fef4f744995db3..bdffcf6b5eb881c8f71d64ed48f570799927b85a 100644 (file)
@@ -44,6 +44,6 @@ public class MetadataIndexDefinition {
 
     NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_METADATA.getType());
 
-    mapping.stringFieldBuilder(FIELD_VALUE).disableSearch().build();
+    mapping.keywordFieldBuilder(FIELD_VALUE).disableSearch().build();
   }
 }
index 1732c5bc331b2722d84654ae84eba9d716553f63..908767016614f4e24243257f59891be8eb09e464 100644 (file)
@@ -98,28 +98,28 @@ public class IssueIndexDefinition implements IndexDefinition {
     type.requireProjectAuthorization();
     type.setEnableSource(enableSource);
 
-    type.stringFieldBuilder(FIELD_ISSUE_ASSIGNEE).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
-    type.stringFieldBuilder(FIELD_ISSUE_AUTHOR_LOGIN).disableNorms().build();
-    type.stringFieldBuilder(FIELD_ISSUE_COMPONENT_UUID).disableNorms().build();
+    type.keywordFieldBuilder(FIELD_ISSUE_ASSIGNEE).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
+    type.keywordFieldBuilder(FIELD_ISSUE_AUTHOR_LOGIN).disableNorms().build();
+    type.keywordFieldBuilder(FIELD_ISSUE_COMPONENT_UUID).disableNorms().build();
     type.createLongField(FIELD_ISSUE_EFFORT);
-    type.stringFieldBuilder(FIELD_ISSUE_FILE_PATH).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
+    type.keywordFieldBuilder(FIELD_ISSUE_FILE_PATH).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
     type.createDateTimeField(FIELD_ISSUE_FUNC_CREATED_AT);
     type.createDateTimeField(FIELD_ISSUE_FUNC_UPDATED_AT);
     type.createDateTimeField(FIELD_ISSUE_FUNC_CLOSED_AT);
-    type.stringFieldBuilder(FIELD_ISSUE_KEY).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
-    type.stringFieldBuilder(FIELD_ISSUE_LANGUAGE).disableNorms().build();
+    type.keywordFieldBuilder(FIELD_ISSUE_KEY).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
+    type.keywordFieldBuilder(FIELD_ISSUE_LANGUAGE).disableNorms().build();
     type.createIntegerField(FIELD_ISSUE_LINE);
-    type.stringFieldBuilder(FIELD_ISSUE_MODULE_UUID).disableNorms().build();
+    type.keywordFieldBuilder(FIELD_ISSUE_MODULE_UUID).disableNorms().build();
     type.createUuidPathField(FIELD_ISSUE_MODULE_PATH);
-    type.stringFieldBuilder(FIELD_ISSUE_ORGANIZATION_UUID).disableNorms().build();
-    type.stringFieldBuilder(FIELD_ISSUE_PROJECT_UUID).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
-    type.stringFieldBuilder(FIELD_ISSUE_DIRECTORY_PATH).disableNorms().build();
-    type.stringFieldBuilder(FIELD_ISSUE_RESOLUTION).disableNorms().build();
-    type.stringFieldBuilder(FIELD_ISSUE_RULE_KEY).disableNorms().build();
-    type.stringFieldBuilder(FIELD_ISSUE_SEVERITY).disableNorms().build();
+    type.keywordFieldBuilder(FIELD_ISSUE_ORGANIZATION_UUID).disableNorms().build();
+    type.keywordFieldBuilder(FIELD_ISSUE_PROJECT_UUID).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
+    type.keywordFieldBuilder(FIELD_ISSUE_DIRECTORY_PATH).disableNorms().build();
+    type.keywordFieldBuilder(FIELD_ISSUE_RESOLUTION).disableNorms().build();
+    type.keywordFieldBuilder(FIELD_ISSUE_RULE_KEY).disableNorms().build();
+    type.keywordFieldBuilder(FIELD_ISSUE_SEVERITY).disableNorms().build();
     type.createByteField(FIELD_ISSUE_SEVERITY_VALUE);
-    type.stringFieldBuilder(FIELD_ISSUE_STATUS).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
-    type.stringFieldBuilder(FIELD_ISSUE_TAGS).disableNorms().build();
-    type.stringFieldBuilder(FIELD_ISSUE_TYPE).disableNorms().build();
+    type.keywordFieldBuilder(FIELD_ISSUE_STATUS).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
+    type.keywordFieldBuilder(FIELD_ISSUE_TAGS).disableNorms().build();
+    type.keywordFieldBuilder(FIELD_ISSUE_TYPE).disableNorms().build();
   }
 }
index 76e4394774324bfd94294247d9420d15e7397d9a..9e7881ebd68e00b2ade00b82712f448f3c527d82 100644 (file)
@@ -56,14 +56,14 @@ public class ProjectMeasuresIndexDefinition implements IndexDefinition {
     NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_PROJECT_MEASURES.getType())
       .requireProjectAuthorization();
 
-    mapping.stringFieldBuilder(FIELD_ORGANIZATION_UUID).build();
-    mapping.stringFieldBuilder(FIELD_KEY).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
-    mapping.stringFieldBuilder(FIELD_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_GRAMS_ANALYZER).build();
-    mapping.stringFieldBuilder(FIELD_QUALITY_GATE_STATUS).build();
-    mapping.stringFieldBuilder(FIELD_TAGS).build();
-    mapping.stringFieldBuilder(FIELD_LANGUAGES).build();
+    mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUID).build();
+    mapping.keywordFieldBuilder(FIELD_KEY).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
+    mapping.keywordFieldBuilder(FIELD_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_GRAMS_ANALYZER).build();
+    mapping.keywordFieldBuilder(FIELD_QUALITY_GATE_STATUS).build();
+    mapping.keywordFieldBuilder(FIELD_TAGS).build();
+    mapping.keywordFieldBuilder(FIELD_LANGUAGES).build();
     mapping.nestedFieldBuilder(FIELD_MEASURES)
-      .addStringField(FIELD_MEASURES_KEY)
+      .addKeywordField(FIELD_MEASURES_KEY)
       .addDoubleField(FIELD_MEASURES_VALUE)
       .build();
     mapping.createDateTimeField(FIELD_ANALYSED_AT);
index 2abf0d654c032a7f1775617fce4d24c48f53851a..eff0896ad567b508832bcbe8a5c12667d2457bbe 100644 (file)
@@ -114,44 +114,44 @@ public class RuleIndexDefinition implements IndexDefinition {
     activeRuleMapping.setEnableSource(enableSource);
     activeRuleMapping.setAttribute("_parent", ImmutableMap.of("type", INDEX_TYPE_RULE.getType()));
 
-    activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
-    activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_REPOSITORY).build();
-    activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_PROFILE_UUID).disableNorms().build();
-    activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_INHERITANCE).disableNorms().build();
-    activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_SEVERITY).disableNorms().build();
+    activeRuleMapping.keywordFieldBuilder(FIELD_ACTIVE_RULE_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
+    activeRuleMapping.keywordFieldBuilder(FIELD_ACTIVE_RULE_REPOSITORY).build();
+    activeRuleMapping.keywordFieldBuilder(FIELD_ACTIVE_RULE_PROFILE_UUID).disableNorms().build();
+    activeRuleMapping.keywordFieldBuilder(FIELD_ACTIVE_RULE_INHERITANCE).disableNorms().build();
+    activeRuleMapping.keywordFieldBuilder(FIELD_ACTIVE_RULE_SEVERITY).disableNorms().build();
 
     // Rule extension type
     NewIndex.NewIndexType ruleExtensionType = index.createType(INDEX_TYPE_RULE_EXTENSION.getType());
     ruleExtensionType.setEnableSource(enableSource);
     ruleExtensionType.setAttribute("_parent", ImmutableMap.of("type", INDEX_TYPE_RULE.getType()));
 
-    ruleExtensionType.stringFieldBuilder(FIELD_RULE_EXTENSION_SCOPE).disableNorms().build();
-    ruleExtensionType.stringFieldBuilder(FIELD_RULE_EXTENSION_RULE_KEY).disableNorms().build();
-    ruleExtensionType.stringFieldBuilder(FIELD_RULE_EXTENSION_TAGS).build();
+    ruleExtensionType.keywordFieldBuilder(FIELD_RULE_EXTENSION_SCOPE).disableNorms().build();
+    ruleExtensionType.keywordFieldBuilder(FIELD_RULE_EXTENSION_RULE_KEY).disableNorms().build();
+    ruleExtensionType.keywordFieldBuilder(FIELD_RULE_EXTENSION_TAGS).build();
 
     // Rule type
     NewIndex.NewIndexType ruleMapping = index.createType(INDEX_TYPE_RULE.getType());
     ruleMapping.setEnableSource(enableSource);
 
-    ruleMapping.stringFieldBuilder(FIELD_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
-    ruleMapping.stringFieldBuilder(FIELD_RULE_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
-    ruleMapping.stringFieldBuilder(FIELD_RULE_REPOSITORY).build();
-    ruleMapping.stringFieldBuilder(FIELD_RULE_INTERNAL_KEY).disableNorms().disableSearch().build();
+    ruleMapping.keywordFieldBuilder(FIELD_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
+    ruleMapping.keywordFieldBuilder(FIELD_RULE_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
+    ruleMapping.keywordFieldBuilder(FIELD_RULE_REPOSITORY).build();
+    ruleMapping.keywordFieldBuilder(FIELD_RULE_INTERNAL_KEY).disableNorms().disableSearch().build();
 
-    ruleMapping.stringFieldBuilder(FIELD_RULE_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_WORDS_ANALYZER).build();
+    ruleMapping.keywordFieldBuilder(FIELD_RULE_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_WORDS_ANALYZER).build();
     ruleMapping.setProperty(FIELD_RULE_HTML_DESCRIPTION, ImmutableSortedMap.of(
-      DefaultIndexSettings.TYPE, DefaultIndexSettings.STRING,
+      DefaultIndexSettings.TYPE, DefaultIndexSettings.FIELD_TYPE_TEXT,
       DefaultIndexSettings.INDEX, DefaultIndexSettings.ANALYZED,
       DefaultIndexSettings.ANALYZER, ENGLISH_HTML_ANALYZER.getName(),
       DefaultIndexSettings.SEARCH_ANALYZER, ENGLISH_HTML_ANALYZER.getName()));
-    ruleMapping.stringFieldBuilder(FIELD_RULE_SEVERITY).disableNorms().build();
-    ruleMapping.stringFieldBuilder(FIELD_RULE_STATUS).disableNorms().build();
-    ruleMapping.stringFieldBuilder(FIELD_RULE_LANGUAGE).disableNorms().build();
+    ruleMapping.keywordFieldBuilder(FIELD_RULE_SEVERITY).disableNorms().build();
+    ruleMapping.keywordFieldBuilder(FIELD_RULE_STATUS).disableNorms().build();
+    ruleMapping.keywordFieldBuilder(FIELD_RULE_LANGUAGE).disableNorms().build();
 
     ruleMapping.createBooleanField(FIELD_RULE_IS_TEMPLATE);
-    ruleMapping.stringFieldBuilder(FIELD_RULE_TEMPLATE_KEY).disableNorms().build();
+    ruleMapping.keywordFieldBuilder(FIELD_RULE_TEMPLATE_KEY).disableNorms().build();
 
-    ruleMapping.stringFieldBuilder(FIELD_RULE_TYPE).disableNorms().build();
+    ruleMapping.keywordFieldBuilder(FIELD_RULE_TYPE).disableNorms().build();
 
     ruleMapping.createLongField(FIELD_RULE_CREATED_AT);
     ruleMapping.createLongField(FIELD_RULE_UPDATED_AT);
index 7d78f076394281ed4dd76fceb6ad4f85c611e8ff..ea415ff30263b97a5cc497093658a0eb32f08797 100644 (file)
@@ -25,6 +25,8 @@ import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.IndexType;
 import org.sonar.server.es.NewIndex;
 
+import static org.sonar.server.es.DefaultIndexSettings.FIELD_TYPE_KEYWORD;
+
 public class TestIndexDefinition implements IndexDefinition {
 
   public static final IndexType INDEX_TYPE_TEST = new IndexType("tests", "test");
@@ -56,16 +58,16 @@ public class TestIndexDefinition implements IndexDefinition {
 
     NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_TEST.getType());
     mapping.setAttribute("_routing", ImmutableMap.of("required", true));
-    mapping.stringFieldBuilder(FIELD_PROJECT_UUID).disableNorms().build();
-    mapping.stringFieldBuilder(FIELD_FILE_UUID).disableNorms().build();
-    mapping.stringFieldBuilder(FIELD_TEST_UUID).disableNorms().build();
-    mapping.stringFieldBuilder(FIELD_NAME).disableNorms().disableSearch().build();
-    mapping.stringFieldBuilder(FIELD_STATUS).disableNorms().disableSearch().build();
+    mapping.keywordFieldBuilder(FIELD_PROJECT_UUID).disableNorms().build();
+    mapping.keywordFieldBuilder(FIELD_FILE_UUID).disableNorms().build();
+    mapping.keywordFieldBuilder(FIELD_TEST_UUID).disableNorms().build();
+    mapping.keywordFieldBuilder(FIELD_NAME).disableNorms().disableSearch().build();
+    mapping.keywordFieldBuilder(FIELD_STATUS).disableNorms().disableSearch().build();
     mapping.createLongField(FIELD_DURATION_IN_MS);
-    mapping.stringFieldBuilder(FIELD_MESSAGE).disableNorms().disableSearch().build();
-    mapping.stringFieldBuilder(FIELD_STACKTRACE).disableNorms().disableSearch().build();
+    mapping.keywordFieldBuilder(FIELD_MESSAGE).disableNorms().disableSearch().build();
+    mapping.keywordFieldBuilder(FIELD_STACKTRACE).disableNorms().disableSearch().build();
     mapping.setProperty(FIELD_COVERED_FILES, ImmutableMap.of("type", "nested", "properties", ImmutableMap.of(
-      FIELD_COVERED_FILE_UUID, ImmutableMap.of("type", "string", "index", "not_analyzed"),
+      FIELD_COVERED_FILE_UUID, ImmutableMap.of("type", FIELD_TYPE_KEYWORD, "index", "not_analyzed"),
       FIELD_COVERED_FILE_LINES, ImmutableMap.of("type", "integer"))));
     mapping.createDateTimeField(FIELD_UPDATED_AT);
   }
index 4178d607ead9756e0db8378ab7832e62dc135ae6..13830f63ba8eb6bd796f5cc6bf929324fc131bc2 100644 (file)
@@ -54,11 +54,11 @@ public class UserIndexDefinition implements IndexDefinition {
 
     // type "user"
     NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_USER.getType());
-    mapping.stringFieldBuilder(FIELD_LOGIN).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build();
-    mapping.stringFieldBuilder(FIELD_NAME).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build();
-    mapping.stringFieldBuilder(FIELD_EMAIL).addSubFields(USER_SEARCH_GRAMS_ANALYZER, SORTABLE_ANALYZER).build();
+    mapping.keywordFieldBuilder(FIELD_LOGIN).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build();
+    mapping.keywordFieldBuilder(FIELD_NAME).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build();
+    mapping.keywordFieldBuilder(FIELD_EMAIL).addSubFields(USER_SEARCH_GRAMS_ANALYZER, SORTABLE_ANALYZER).build();
     mapping.createBooleanField(FIELD_ACTIVE);
-    mapping.stringFieldBuilder(FIELD_SCM_ACCOUNTS).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
-    mapping.stringFieldBuilder(FIELD_ORGANIZATION_UUIDS).disableNorms().build();
+    mapping.keywordFieldBuilder(FIELD_SCM_ACCOUNTS).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
+    mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUIDS).disableNorms().build();
   }
 }
index d49ef6df2db31bf563b70e68d3d6779d77628994..79523f94a804ae406bbbc380f02bb538695b122f 100644 (file)
@@ -47,7 +47,7 @@ public class ViewIndexDefinition implements IndexDefinition {
 
     // type "view"
     NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_VIEW.getType());
-    mapping.stringFieldBuilder(FIELD_UUID).disableNorms().build();
-    mapping.stringFieldBuilder(FIELD_PROJECTS).disableNorms().build();
+    mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build();
+    mapping.keywordFieldBuilder(FIELD_PROJECTS).disableNorms().build();
   }
 }
index 6cd13fcef3fde56977f85f877cf05e971aaf2058..d7b1e669cdbec3965d85401c190555a0bd174ab3 100644 (file)
@@ -160,7 +160,7 @@ public class IndexCreatorTest {
     public void define(IndexDefinitionContext context) {
       NewIndex index = context.create("fakes");
       NewIndex.NewIndexType mapping = index.createType("fake");
-      mapping.stringFieldBuilder("key").build();
+      mapping.keywordFieldBuilder("key").build();
       mapping.createDateTimeField("updatedAt");
     }
   }
@@ -170,7 +170,7 @@ public class IndexCreatorTest {
     public void define(IndexDefinitionContext context) {
       NewIndex index = context.create("fakes");
       NewIndex.NewIndexType mapping = index.createType("fake");
-      mapping.stringFieldBuilder("key").build();
+      mapping.keywordFieldBuilder("key").build();
       mapping.createDateTimeField("updatedAt");
       mapping.createIntegerField("newField");
     }
index 06d8bb1fdb12534bf7f15f924ce42b29d40dcf67..1c3c30d710e7b6af9a368336879ce762059986b6 100644 (file)
@@ -45,7 +45,7 @@ public class IndexDefinitionHashTest {
     NewIndex newIndex = new NewIndex("fakes");
     NewIndex.NewIndexType mapping = newIndex.createType("fake");
     mapping.setAttribute("list_attr", Arrays.asList("foo", "bar"));
-    mapping.stringFieldBuilder("key").build();
+    mapping.keywordFieldBuilder("key").build();
     mapping.createDateTimeField("updatedAt");
     return newIndex;
   }
index f9e119a1b122aea897222464427722fca0cb0100..ceabf6cb2bc92c9f6de8af02b39f956bae7ae317 100644 (file)
@@ -63,7 +63,7 @@ public class NewIndexTest {
     NewIndex index = new NewIndex("issues");
     NewIndex.NewIndexType mapping = index.createType("issue");
     mapping.setAttribute("dynamic", "true");
-    mapping.setProperty("foo_field", ImmutableMap.of("type", "string"));
+    mapping.setProperty("foo_field", ImmutableMap.of("type", "string"));// ES 5: change to keyword
     mapping.createBooleanField("boolean_field");
     mapping.createByteField("byte_field");
     mapping.createDateTimeField("dt_field");
@@ -77,7 +77,7 @@ public class NewIndexTest {
     assertThat(mapping).isNotNull();
     assertThat(mapping.getAttributes().get("dynamic")).isEqualTo("true");
     assertThat(mapping.getProperty("foo_field")).isInstanceOf(Map.class);
-    assertThat((Map) mapping.getProperty("foo_field")).containsEntry("type", "string");
+    assertThat((Map) mapping.getProperty("foo_field")).containsEntry("type", "string");// ES 5: change to keyword
     assertThat((Map) mapping.getProperty("byte_field")).isNotEmpty();
     assertThat((Map) mapping.getProperty("double_field")).isNotEmpty();
     assertThat((Map) mapping.getProperty("dt_field")).isNotEmpty();
@@ -92,9 +92,9 @@ public class NewIndexTest {
   public void define_string_field() {
     NewIndex index = new NewIndex("issues");
     NewIndex.NewIndexType mapping = index.createType("issue");
-    mapping.stringFieldBuilder("basic_field").build();
-    mapping.stringFieldBuilder("not_searchable_field").disableSearch().build();
-    mapping.stringFieldBuilder("all_capabilities_field")
+    mapping.keywordFieldBuilder("basic_field").build();
+    mapping.keywordFieldBuilder("not_searchable_field").disableSearch().build();
+    mapping.keywordFieldBuilder("all_capabilities_field")
       .addSubFields(
         DefaultIndexSettingsElement.SEARCH_GRAMS_ANALYZER,
         DefaultIndexSettingsElement.SEARCH_WORDS_ANALYZER,
@@ -102,12 +102,12 @@ public class NewIndexTest {
       .build();
 
     Map<String, Object> props = (Map) mapping.getProperty("basic_field");
-    assertThat(props.get("type")).isEqualTo("string");
+    assertThat(props.get("type")).isEqualTo("string");// ES 5: change to keyword
     assertThat(props.get("index")).isEqualTo("not_analyzed");
     assertThat(props.get("fields")).isNull();
 
     props = (Map) mapping.getProperty("not_searchable_field");
-    assertThat(props.get("type")).isEqualTo("string");
+    assertThat(props.get("type")).isEqualTo("string");// ES 5: change to keyword
     assertThat(props.get("index")).isEqualTo("no");
     assertThat(props.get("fields")).isNull();
 
@@ -123,14 +123,14 @@ public class NewIndexTest {
     NewIndex.NewIndexType mapping = index.createType("projectmeasures");
 
     mapping.nestedFieldBuilder("measures")
-      .addStringField("key")
+      .addKeywordField("key")
       .addDoubleField("value")
       .build();
     Map<String, Object> result = (Map) mapping.getProperty("measures");
 
     assertThat(result.get("type")).isEqualTo("nested");
     Map<String, Map<String, Object>> subProperties = (Map) result.get("properties");
-    assertThat(subProperties.get("key").get("type")).isEqualTo("string");
+    assertThat(subProperties.get("key").get("type")).isEqualTo("string"); // ES 5: change to "keyword
     assertThat(subProperties.get("value").get("type")).isEqualTo("double");
   }
 
@@ -149,10 +149,10 @@ public class NewIndexTest {
   public void use_default_doc_values() {
     NewIndex index = new NewIndex("issues");
     NewIndex.NewIndexType mapping = index.createType("issue");
-    mapping.stringFieldBuilder("the_doc_value").build();
+    mapping.keywordFieldBuilder("the_doc_value").build();
 
     Map<String, Object> props = (Map) mapping.getProperty("the_doc_value");
-    assertThat(props.get("type")).isEqualTo("string");
+    assertThat(props.get("type")).isEqualTo("string");// ES 5: change to keyword
     assertThat(props.get("doc_values")).isNull();
   }
 
index 03caece09092b3355a28cc8d03e622dc3c1afac9..8d416609aec780344a24639b7b51a08c8565d965 100644 (file)
@@ -39,7 +39,7 @@ public class FooIndexDefinition implements IndexDefinition {
     NewIndex.NewIndexType type = index.createType(FOO_TYPE)
       .requireProjectAuthorization();
 
-    type.stringFieldBuilder(FIELD_NAME).build();
-    type.stringFieldBuilder(FIELD_PROJECT_UUID).build();
+    type.keywordFieldBuilder(FIELD_NAME).build();
+    type.keywordFieldBuilder(FIELD_PROJECT_UUID).build();
   }
 }