diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistry.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistry.java index fdb863e9e65..7f4467b6ade 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistry.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistry.java @@ -290,7 +290,9 @@ public class MachineLearningTemplateRegistry extends AbstractComponent implemen // pick up default mappings and be used in queries .put(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey(), true) // set the default all search field - .put(IndexSettings.DEFAULT_FIELD_SETTING.getKey(), ElasticsearchMappings.ALL_FIELD_VALUES); + .put(IndexSettings.DEFAULT_FIELD_SETTING.getKey(), ElasticsearchMappings.ALL_FIELD_VALUES) + // TODO: fix the template to use a single type + .put("index.mapping.single_type", false); } /** @@ -321,7 +323,9 @@ public class MachineLearningTemplateRegistry extends AbstractComponent implemen // Sacrifice durability for performance: in the event of power // failure we can lose the last 5 seconds of changes, but it's // much faster - .put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), ASYNC); + .put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), ASYNC) + // TODO: do not create multiple types + .put("index.mapping.single_type", false); } public static boolean allTemplatesInstalled(MetaData metaData) { diff --git a/plugin/src/main/resources/monitoring-alerts.json b/plugin/src/main/resources/monitoring-alerts.json index 87313c3fbad..c06f2bf6e27 100644 --- a/plugin/src/main/resources/monitoring-alerts.json +++ b/plugin/src/main/resources/monitoring-alerts.json @@ -4,7 +4,8 @@ "index": { "number_of_shards": 1, "number_of_replicas": 1, - "codec": "best_compression" + "codec": "best_compression", + "mapping.single_type": false } }, "mappings": { diff --git a/plugin/src/main/resources/monitoring-beats.json b/plugin/src/main/resources/monitoring-beats.json index e3843e0f970..9750f25e4ca 100644 --- a/plugin/src/main/resources/monitoring-beats.json +++ b/plugin/src/main/resources/monitoring-beats.json @@ -3,7 +3,8 @@ "settings": { "index.number_of_shards": 1, "index.number_of_replicas": 1, - "index.codec": "best_compression" + "index.codec": "best_compression", + "index.mapping.single_type": false }, "mappings": { "beats_stats": { diff --git a/plugin/src/main/resources/monitoring-data.json b/plugin/src/main/resources/monitoring-data.json index 413e5cd8a83..91662d0a8c7 100644 --- a/plugin/src/main/resources/monitoring-data.json +++ b/plugin/src/main/resources/monitoring-data.json @@ -3,7 +3,8 @@ "settings": { "index.number_of_shards": 1, "index.number_of_replicas": 1, - "index.codec": "best_compression" + "index.codec": "best_compression", + "index.mapping.single_type": false }, "mappings": { "_default_": { diff --git a/plugin/src/main/resources/monitoring-es.json b/plugin/src/main/resources/monitoring-es.json index 94646f5f235..bfad9040643 100644 --- a/plugin/src/main/resources/monitoring-es.json +++ b/plugin/src/main/resources/monitoring-es.json @@ -4,7 +4,8 @@ "index.number_of_shards": 1, "index.number_of_replicas": 1, "index.codec": "best_compression", - "index.mapper.dynamic": false + "index.mapper.dynamic": false, + "index.mapping.single_type": false }, "mappings": { "_default_": { diff --git a/plugin/src/main/resources/monitoring-kibana.json b/plugin/src/main/resources/monitoring-kibana.json index 018090c5e28..8c5bbe25328 100644 --- a/plugin/src/main/resources/monitoring-kibana.json +++ b/plugin/src/main/resources/monitoring-kibana.json @@ -3,7 +3,8 @@ "settings": { "index.number_of_shards": 1, "index.number_of_replicas": 1, - "index.codec": "best_compression" + "index.codec": "best_compression", + "index.mapping.single_type": false }, "mappings": { "_default_": { diff --git a/plugin/src/main/resources/monitoring-logstash.json b/plugin/src/main/resources/monitoring-logstash.json index c48348bded1..2d262b3f010 100644 --- a/plugin/src/main/resources/monitoring-logstash.json +++ b/plugin/src/main/resources/monitoring-logstash.json @@ -3,7 +3,8 @@ "settings": { "index.number_of_shards": 1, "index.number_of_replicas": 1, - "index.codec": "best_compression" + "index.codec": "best_compression", + "index.mapping.single_type": false }, "mappings": { "_default_": { diff --git a/plugin/src/main/resources/security-index-template.json b/plugin/src/main/resources/security-index-template.json index f581e814140..d29b5ffd6a5 100644 --- a/plugin/src/main/resources/security-index-template.json +++ b/plugin/src/main/resources/security-index-template.json @@ -2,6 +2,7 @@ "index_patterns" : ".security", "order" : 1000, "settings" : { + "mapping.single_type": false, "number_of_shards" : 1, "number_of_replicas" : 0, "auto_expand_replicas" : "0-all", diff --git a/plugin/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java b/plugin/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java index 2035d77c012..38798741290 100644 --- a/plugin/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java +++ b/plugin/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java @@ -563,6 +563,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase { public void testChildrenAggregation() throws Exception { assertAcked(client().admin().indices().prepareCreate("test") + .setSettings("mapping.single_type", false) .addMapping("type1", "field1", "type=text", "field2", "type=text") .addMapping("type2", "_parent", "type=type1", "field3", "type=text,fielddata=true") ); @@ -619,6 +620,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase { public void testParentChild() { assertAcked(prepareCreate("test") + .setSettings("mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent", "field1", "type=text", "field2", "type=text", "field3", "type=text")); ensureGreen(); diff --git a/plugin/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java b/plugin/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java index a2d052b8da6..7a6273718e6 100644 --- a/plugin/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java +++ b/plugin/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java @@ -1280,6 +1280,7 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase { public void testParentChild() { assertAcked(prepareCreate("test") + .setSettings("mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistryTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistryTests.java index f8309f70a5d..44e3c4cbcf7 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistryTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistryTests.java @@ -156,12 +156,13 @@ public class MachineLearningTemplateRegistryTests extends ESTestCase { new MachineLearningTemplateRegistry(createSettings(), clusterService, client, threadPool); Settings settings = templateRegistry.mlResultsIndexSettings().build(); - assertEquals(4, settings.size()); + assertEquals(5, settings.size()); assertThat(settings.get("index.number_of_shards"), is(nullValue())); assertEquals("async", settings.get("index.translog.durability")); assertEquals("true", settings.get("index.mapper.dynamic")); assertEquals("all_field_values", settings.get("index.query.default_field")); assertEquals("2s", settings.get("index.unassigned.node_left.delayed_timeout")); + assertEquals("false", settings.get("index.mapping.single_type")); } public void testMlAuditIndexSettings() { @@ -180,10 +181,11 @@ public class MachineLearningTemplateRegistryTests extends ESTestCase { new MachineLearningTemplateRegistry(createSettings(), clusterService, client, threadPool); Settings settings = templateRegistry.mlStateIndexSettings().build(); - assertEquals(2, settings.size()); + assertEquals(3, settings.size()); assertThat(settings.get("index.number_of_shards"), is(nullValue())); assertEquals("async", settings.get("index.translog.durability")); assertEquals("2s", settings.get("index.unassigned.node_left.delayed_timeout")); + assertEquals("false", settings.get("index.mapping.single_type")); } public void testPutNotificationIndexTemplate() { diff --git a/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTemplateTests.java b/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTemplateTests.java index d6faac59a8c..6fbc1780c73 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTemplateTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTemplateTests.java @@ -187,6 +187,7 @@ public class LocalExporterTemplateTests extends MonitoringIntegTestCase { .startObject("settings") .field("index.number_of_shards", 1) .field("index.number_of_replicas", 1) + .field("index.mapping.single_type", false) .endObject() .startObject("mappings") .startObject("_default_") diff --git a/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTests.java b/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTests.java index 0a5c27c9a52..4220bde2a22 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterTests.java @@ -51,6 +51,7 @@ import org.junit.AfterClass; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -186,31 +187,6 @@ public class LocalExporterTests extends MonitoringIntegTestCase { assertAcked(client().admin().cluster().prepareUpdateSettings() .setTransientSettings(exporterSettings)); - if (randomBoolean()) { - // export some documents now, before starting the monitoring service - final int nbDocs = randomIntBetween(1, 20); - List monitoringDocs = new ArrayList<>(nbDocs); - for (int i = 0; i < nbDocs; i++) { - monitoringDocs.add(createMonitoringBulkDoc(String.valueOf(i))); - } - - assertBusy(() -> { - MonitoringBulkRequestBuilder bulk = monitoringClient().prepareMonitoringBulk(); - monitoringDocs.forEach(bulk::add); - assertEquals(RestStatus.OK, bulk.get().status()); - refresh(); - - SearchResponse response = client().prepareSearch(".monitoring-*").get(); - assertEquals(nbDocs, response.getHits().getTotalHits()); - }); - - checkMonitoringTemplates(); - checkMonitoringPipeline(); - checkMonitoringAliases(); - checkMonitoringMappings(); - checkMonitoringDocs(); - } - // monitoring service is started exporterSettings = Settings.builder() .put(MonitoringSettings.INTERVAL.getKey(), 3L, TimeUnit.SECONDS); @@ -396,7 +372,7 @@ public class LocalExporterTests extends MonitoringIntegTestCase { expectedIndex.add(".monitoring-data-2"); } } - assertTrue(expectedIndex.contains(hit.getIndex())); + assertTrue("Expected " + expectedIndex + " but got " + hit.getIndex(), expectedIndex.contains(hit.getIndex())); @SuppressWarnings("unchecked") Map sourceNode = (Map) source.get("source_node"); @@ -425,11 +401,7 @@ public class LocalExporterTests extends MonitoringIntegTestCase { source = builder.bytes(); } - // Aligns the type with the monitoring index and monitored system so that we can later - // check if the document is indexed in the correct index. - String type = index.name().toLowerCase(Locale.ROOT) + "_" + monitoringId; - - return new MonitoringBulkDoc(monitoringId, monitoringVersion, index, type, id, source, + return new MonitoringBulkDoc(monitoringId, monitoringVersion, index, monitoringId, id, source, xContentType); } } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchAckTests.java b/plugin/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchAckTests.java index 91039490b1c..d262f0c6de0 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchAckTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchAckTests.java @@ -79,8 +79,8 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase { .input(searchInput(templateRequest(searchSource(), "events"))) .condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L)) .transform(searchTransform(templateRequest(searchSource(), "events"))) - .addAction("_a1", indexAction("actions", "action1")) - .addAction("_a2", indexAction("actions", "action2")) + .addAction("_a1", indexAction("actions1", "doc")) + .addAction("_a2", indexAction("actions2", "doc")) .defaultThrottlePeriod(new TimeValue(0, TimeUnit.SECONDS))) .get(); @@ -93,8 +93,8 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase { assertThat(ackResponse.getStatus().actionStatus("_a2").ackStatus().state(), is(ActionStatus.AckStatus.State.ACKABLE)); refresh(); - long a1CountAfterAck = docCount("actions", "action1", matchAllQuery()); - long a2CountAfterAck = docCount("actions", "action2", matchAllQuery()); + long a1CountAfterAck = docCount("actions1", "doc", matchAllQuery()); + long a2CountAfterAck = docCount("actions2", "doc", matchAllQuery()); assertThat(a1CountAfterAck, greaterThan(0L)); assertThat(a2CountAfterAck, greaterThan(0L)); @@ -103,11 +103,11 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase { refresh(); // There shouldn't be more a1 actions in the index after we ack the watch, even though the watch was triggered - long a1CountAfterPostAckFires = docCount("actions", "action1", matchAllQuery()); + long a1CountAfterPostAckFires = docCount("actions1", "doc", matchAllQuery()); assertThat(a1CountAfterPostAckFires, equalTo(a1CountAfterAck)); // There should be more a2 actions in the index after we ack the watch - long a2CountAfterPostAckFires = docCount("actions", "action2", matchAllQuery()); + long a2CountAfterPostAckFires = docCount("actions2", "doc", matchAllQuery()); assertThat(a2CountAfterPostAckFires, greaterThan(a2CountAfterAck)); // Now delete the event and the ack states should change to AWAITS_EXECUTION @@ -139,8 +139,8 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase { .input(searchInput(templateRequest(searchSource(), "events"))) .condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L)) .transform(searchTransform(templateRequest(searchSource(), "events"))) - .addAction("_a1", indexAction("actions", "action1")) - .addAction("_a2", indexAction("actions", "action2")) + .addAction("_a1", indexAction("actions1", "doc")) + .addAction("_a2", indexAction("actions2", "doc")) .defaultThrottlePeriod(new TimeValue(0, TimeUnit.SECONDS))) .get(); @@ -161,8 +161,8 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase { assertThat(ackResponse.getStatus().actionStatus("_a2").ackStatus().state(), is(ActionStatus.AckStatus.State.ACKED)); refresh(); - long a1CountAfterAck = docCount("actions", "action1", matchAllQuery()); - long a2CountAfterAck = docCount("actions", "action2", matchAllQuery()); + long a1CountAfterAck = docCount("actions1", "doc", matchAllQuery()); + long a2CountAfterAck = docCount("actions2", "doc", matchAllQuery()); assertThat(a1CountAfterAck, greaterThanOrEqualTo((long) 1)); assertThat(a2CountAfterAck, greaterThanOrEqualTo((long) 1)); @@ -171,11 +171,11 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase { refresh(); // There shouldn't be more a1 actions in the index after we ack the watch, even though the watch was triggered - long a1CountAfterPostAckFires = docCount("actions", "action1", matchAllQuery()); + long a1CountAfterPostAckFires = docCount("actions1", "doc", matchAllQuery()); assertThat(a1CountAfterPostAckFires, equalTo(a1CountAfterAck)); // There shouldn't be more a2 actions in the index after we ack the watch, even though the watch was triggered - long a2CountAfterPostAckFires = docCount("actions", "action2", matchAllQuery()); + long a2CountAfterPostAckFires = docCount("actions2", "doc", matchAllQuery()); assertThat(a2CountAfterPostAckFires, equalTo(a2CountAfterAck)); // Now delete the event and the ack states should change to AWAITS_EXECUTION