From fc39be58b09d3c98a8a04f71b0244916f1358ab3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Mon, 11 Mar 2019 15:09:25 +0100 Subject: [PATCH] SONAR-11792 drop usage of "_all" field --- .../java/org/sonar/server/es/newindex/NewIndex.java | 1 - .../org/sonar/server/es/newindex/NewIndexTest.java | 13 +++++++++++-- .../org/sonar/server/es/MigrationEsClientImpl.java | 9 +++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/newindex/NewIndex.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/newindex/NewIndex.java index 43ce95471de..84c50d63487 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/es/newindex/NewIndex.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/newindex/NewIndex.java @@ -69,7 +69,6 @@ public abstract class NewIndex> { private void configureDefaultAttributes() { attributes.put("dynamic", valueOf(false)); - attributes.put("_all", ImmutableSortedMap.of(ENABLED, false)); attributes.put("_source", ImmutableSortedMap.of(ENABLED, true)); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java index 4f50be5e81c..4db0c2b9be4 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java @@ -61,6 +61,15 @@ public class NewIndexTest { assertThat(newIndex.getRelations()).isEmpty(); } + @Test + @UseDataProvider("indexWithAndWithoutRelations") + public void does_not_enable_all_field(Index index) { + SimplestNewIndex newIndex = new SimplestNewIndex(IndexType.main(index, "foo"), defaultSettingsConfiguration); + + // _all field is deprecated in 6.X and will be removed in 7.x and should not be used + assertThat(newIndex.getAttributes().get("_all")).isNull(); + } + @Test @UseDataProvider("indexWithAndWithoutRelations") public void verify_default_index_settings_in_standalone(Index index) { @@ -83,9 +92,9 @@ public class NewIndexTest { settings.setProperty(CLUSTER_ENABLED.getKey(), "true"); Settings underTest = new SimplestNewIndex(IndexType.main(index, "foo"), defaultSettingsConfiguration).getSettings().build(); + // _all field is deprecated in ES 6.X and will be removed in 7.X + assertThat(underTest.get("_all")).isNull(); assertThat(underTest.get("index.number_of_shards")).isNotEmpty(); - // index.mapper.dynamic is deprecated and should not be set anymore - assertThat(underTest.get("index.mapper.dynamic")).isNull(); assertThat(underTest.get("index.refresh_interval")).isEqualTo("30s"); // setting "mapping.single_type" has been dropped in 6.X because multi type indices are not supported anymore assertThat(underTest.get("mapping.single_type")).isNull(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/MigrationEsClientImpl.java b/server/sonar-server/src/main/java/org/sonar/server/es/MigrationEsClientImpl.java index 25619a0b015..fb9c425a2cd 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/MigrationEsClientImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/MigrationEsClientImpl.java @@ -19,12 +19,13 @@ */ package org.sonar.server.es; -import com.google.common.collect.Sets; import java.util.Arrays; +import java.util.Map; import java.util.Set; import java.util.stream.Stream; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; +import org.elasticsearch.action.admin.indices.stats.IndexStats; import org.sonar.api.utils.log.Loggers; +import org.sonar.core.util.stream.MoreCollectors; import org.sonar.server.platform.db.migration.es.MigrationEsClient; public class MigrationEsClientImpl implements MigrationEsClient { @@ -36,8 +37,8 @@ public class MigrationEsClientImpl implements MigrationEsClient { @Override public void deleteIndexes(String name, String... otherNames) { - GetMappingsResponse mappings = client.nativeClient().admin().indices().prepareGetMappings("_all").get(); - Set existingIndices = Sets.newHashSet(mappings.mappings().keysIt()); + Map indices = client.nativeClient().admin().indices().prepareStats().get().getIndices(); + Set existingIndices = indices.values().stream().map(IndexStats::getIndex).collect(MoreCollectors.toSet()); Stream.concat(Stream.of(name), Arrays.stream(otherNames)) .distinct() .filter(existingIndices::contains) -- 2.39.5