]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11792 drop usage of "_all" field
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 11 Mar 2019 14:09:25 +0000 (15:09 +0100)
committerSonarTech <sonartech@sonarsource.com>
Tue, 19 Mar 2019 19:21:25 +0000 (20:21 +0100)
server/sonar-server-common/src/main/java/org/sonar/server/es/newindex/NewIndex.java
server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java
server/sonar-server/src/main/java/org/sonar/server/es/MigrationEsClientImpl.java

index 43ce95471dee300340941b20a791890860852193..84c50d634878c8a4a72c974da86877e1ac1fc54f 100644 (file)
@@ -69,7 +69,6 @@ public abstract class NewIndex<T extends NewIndex<T>> {
 
   private void configureDefaultAttributes() {
     attributes.put("dynamic", valueOf(false));
-    attributes.put("_all", ImmutableSortedMap.of(ENABLED, false));
     attributes.put("_source", ImmutableSortedMap.of(ENABLED, true));
   }
 
index 4f50be5e81cf111264e5f6bec90b9be7f50db8ef..4db0c2b9be45f43285a97e9f4f3b8b91df2b31ad 100644 (file)
@@ -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();
index 25619a0b0158077c749fe3eb93a8595338292a12..fb9c425a2cdd2f8b37ff92a7e9c06acd0baa0aaa 100644 (file)
  */
 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<String> existingIndices = Sets.newHashSet(mappings.mappings().keysIt());
+    Map<String, IndexStats> indices = client.nativeClient().admin().indices().prepareStats().get().getIndices();
+    Set<String> existingIndices = indices.values().stream().map(IndexStats::getIndex).collect(MoreCollectors.toSet());
     Stream.concat(Stream.of(name), Arrays.stream(otherNames))
       .distinct()
       .filter(existingIndices::contains)