diff options
author | Daniel Schwarz <daniel.schwarz@sonarsource.com> | 2017-10-12 10:09:24 +0200 |
---|---|---|
committer | Daniel Schwarz <bartfastiel@users.noreply.github.com> | 2017-10-13 10:15:55 +0200 |
commit | 4c1a2f226b279b9b173c65695a07182717a9ffe3 (patch) | |
tree | 0d6ba6551b853ae7de46c22602a39fdaa6506355 | |
parent | d1eef867e02c7402a4516fa2dd4d193a03eb2b7b (diff) | |
download | sonarqube-4c1a2f226b279b9b173c65695a07182717a9ffe3.tar.gz sonarqube-4c1a2f226b279b9b173c65695a07182717a9ffe3.zip |
SONAR-9965 avoid obsolete subfields in Elasticsearch keyword fields
Each field with subfields used to have one obsolete additional subfield with the same name as the name itself. This one is now removed. Those obsolete subfields also sometimes caused issues with long text values (like rule descriptions or test messages).
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java | 66 |
1 files changed, 29 insertions, 37 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java b/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java index 263fa0d9b46..13701a250e4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java @@ -372,57 +372,49 @@ public class NewIndex { private NewIndexType buildWithSubfields() { Map<String, Object> hash = new TreeMap<>(); hash.put("type", getFieldType()); - - Map<String, Object> multiFields = new TreeMap<>(subFields); - - if (termVectorWithPositionOffsets) { - multiFields.entrySet().forEach(entry -> { - Object subFieldMapping = entry.getValue(); - if (subFieldMapping instanceof Map) { - entry.setValue( - addFieldToMapping( - (Map<String, String>) subFieldMapping, - FIELD_TERM_VECTOR, "with_positions_offsets")); - } - }); - hash.put(FIELD_TERM_VECTOR, "with_positions_offsets"); + hash.put(INDEX, disableSearch ? INDEX_NOT_SEARCHABLE : INDEX_SEARCHABLE); + hash.put("norms", "false"); + hash.put("store", valueOf(store)); + if (FIELD_TYPE_KEYWORD.equals(getFieldType())) { + hash.put("doc_values", valueOf(!disabledDocValues)); } if (getFieldData()) { - multiFields.entrySet().forEach(entry -> { - Object subFieldMapping = entry.getValue(); - if (subFieldMapping instanceof Map) { - entry.setValue( - addFieldToMapping( - (Map<String, String>) subFieldMapping, - FIELD_FIELDDATA, FIELDDATA_ENABLED)); - } - }); hash.put(FIELD_FIELDDATA, FIELDDATA_ENABLED); } + if (termVectorWithPositionOffsets) { + hash.put(FIELD_TERM_VECTOR, "with_positions_offsets"); + } + hash.put("fields", configureSubFields()); + return indexType.setProperty(fieldName, hash); + } + + private Map<String, Object> configureSubFields() { + Map<String, Object> multiFields = new TreeMap<>(subFields); + + // apply this fields configuration to all subfields + multiFields.entrySet().forEach(entry -> { + Object subFieldMapping = entry.getValue(); + if (subFieldMapping instanceof Map) { + entry.setValue(configureSubField((Map<String, String>) subFieldMapping)); + } + }); + return multiFields; + } - Map<String, String> subHash = new TreeMap<>(); - subHash.put("type", getFieldType()); + private Map<String, String> configureSubField(Map<String, String> subFieldMapping) { + Map<String, String> subHash = new TreeMap<>(subFieldMapping); subHash.put(INDEX, INDEX_SEARCHABLE); subHash.put("norms", "false"); subHash.put("store", valueOf(store)); - if (FIELD_TYPE_KEYWORD.equals(getFieldType())) { - subHash.put("doc_values", valueOf(!disabledDocValues)); + if (termVectorWithPositionOffsets) { + subHash.put(FIELD_TERM_VECTOR, "with_positions_offsets"); } - multiFields.put(fieldName, subHash); - hash.put("fields", multiFields); - - return indexType.setProperty(fieldName, hash); + return subHash; } protected abstract boolean getFieldData(); protected abstract String getFieldType(); - - private static SortedMap<String, String> addFieldToMapping(Map<String, String> source, String key, String value) { - SortedMap<String, String> mutable = new TreeMap<>(source); - mutable.put(key, value); - return ImmutableSortedMap.copyOf(mutable); - } } public static class KeywordFieldBuilder extends StringFieldBuilder<KeywordFieldBuilder> { |