Skip to content

Commit

Permalink
SONAR-9796 map with predictive order must be used for index definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
sns-seb committed Sep 11, 2017
1 parent b9a406a commit d050cbd
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions server/sonar-server/src/main/java/org/sonar/server/es/NewIndex.java
Expand Up @@ -232,7 +232,10 @@ public NewIndexType createByteField(String fieldName) {
} }


public NewIndexType createDateTimeField(String fieldName) { public NewIndexType createDateTimeField(String fieldName) {
return setProperty(fieldName, ImmutableMap.of("type", "date", "format", "date_time||epoch_second")); Map<String, String> hash = new TreeMap<>();
hash.put("type", "date");
hash.put("format", "date_time||epoch_second");
return setProperty(fieldName, hash);
} }


public NewIndexType createDoubleField(String fieldName) { public NewIndexType createDoubleField(String fieldName) {
Expand Down Expand Up @@ -351,18 +354,18 @@ public NewIndexType build() {
} }


private NewIndexType buildWithoutSubfields() { private NewIndexType buildWithoutSubfields() {
ImmutableMap.Builder<String, String> hash = ImmutableMap.builder(); Map<String, Object> hash = new TreeMap<>();
hash.put("type", getFieldType()) hash.put("type", getFieldType());
.put(INDEX, disableSearch ? INDEX_NOT_SEARCHABLE : INDEX_SEARCHABLE) hash.put(INDEX, disableSearch ? INDEX_NOT_SEARCHABLE : INDEX_SEARCHABLE);
.put("norms", valueOf(!disableNorms)) hash.put("norms", valueOf(!disableNorms));
.put("store", valueOf(store)); hash.put("store", valueOf(store));
if (FIELD_TYPE_KEYWORD.equals(getFieldType())) { if (FIELD_TYPE_KEYWORD.equals(getFieldType())) {
hash.put("doc_values", valueOf(!disabledDocValues)); hash.put("doc_values", valueOf(!disabledDocValues));
} }
if (getFieldData()) { if (getFieldData()) {
hash.put(FIELD_FIELDDATA, FIELDDATA_ENABLED); hash.put(FIELD_FIELDDATA, FIELDDATA_ENABLED);
} }
return indexType.setProperty(fieldName, hash.build()); return indexType.setProperty(fieldName, hash);
} }


private NewIndexType buildWithSubfields() { private NewIndexType buildWithSubfields() {
Expand Down Expand Up @@ -396,15 +399,15 @@ private NewIndexType buildWithSubfields() {
hash.put(FIELD_FIELDDATA, FIELDDATA_ENABLED); hash.put(FIELD_FIELDDATA, FIELDDATA_ENABLED);
} }


ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); Map<String, String> subHash = new TreeMap<>();
builder.put("type", getFieldType()) subHash.put("type", getFieldType());
.put(INDEX, INDEX_SEARCHABLE) subHash.put(INDEX, INDEX_SEARCHABLE);
.put("norms", "false") subHash.put("norms", "false");
.put("store", valueOf(store)); subHash.put("store", valueOf(store));
if (FIELD_TYPE_KEYWORD.equals(getFieldType())) { if (FIELD_TYPE_KEYWORD.equals(getFieldType())) {
builder.put("doc_values", valueOf(!disabledDocValues)); subHash.put("doc_values", valueOf(!disabledDocValues));
} }
multiFields.put(fieldName, builder.build()); multiFields.put(fieldName, subHash);
hash.put("fields", multiFields); hash.put("fields", multiFields);


return indexType.setProperty(fieldName, hash); return indexType.setProperty(fieldName, hash);
Expand Down Expand Up @@ -492,7 +495,7 @@ private NestedFieldBuilder setProperty(String fieldName, Object value) {
} }


public NestedFieldBuilder addKeywordField(String fieldName) { public NestedFieldBuilder addKeywordField(String fieldName) {
return setProperty(fieldName, ImmutableMap.of( return setProperty(fieldName, ImmutableSortedMap.of(
"type", FIELD_TYPE_KEYWORD, "type", FIELD_TYPE_KEYWORD,
INDEX, INDEX_SEARCHABLE)); INDEX, INDEX_SEARCHABLE));
} }
Expand All @@ -507,11 +510,10 @@ public NestedFieldBuilder addIntegerField(String fieldName) {


public NewIndexType build() { public NewIndexType build() {
checkArgument(!properties.isEmpty(), "At least one sub-field must be declared in nested property '%s'", fieldName); checkArgument(!properties.isEmpty(), "At least one sub-field must be declared in nested property '%s'", fieldName);
Map<String, Object> hash = new TreeMap<>();
hash.put("type", "nested");
hash.put("properties", properties);


return indexType.setProperty(fieldName, hash); return indexType.setProperty(fieldName, ImmutableSortedMap.of(
"type", "nested",
"properties", properties));
} }
} }


Expand Down

0 comments on commit d050cbd

Please sign in to comment.