diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index c9a8738e5776..3a7682cec178 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -45,6 +45,7 @@ https://github.com/elastic/beats/compare/v6.0.0-alpha2...master[Check the HEAD d - Don't stop with error loading the ES template if the ES output is not enabled. {pull}4436[4436] - Fix race condition in internal logging rotator. {pull}4519[4519] +- Fix issue with loading dashboards to ES 6.0 when .kibana index did not already exist. {issue}4659[4659] *Filebeat* diff --git a/libbeat/dashboards/dashboards.go b/libbeat/dashboards/dashboards.go index b72fb760642e..0794ed0a4e8c 100644 --- a/libbeat/dashboards/dashboards.go +++ b/libbeat/dashboards/dashboards.go @@ -102,6 +102,10 @@ func ImportDashboardsViaElasticsearch(config *common.Config, dashConfig *Dashboa return false, nil } + if err := esLoader.CreateKibanaIndex(); err != nil { + return false, fmt.Errorf("fail to create the kibana index: %v", err) + } + importer, err := NewImporter("5.x", dashConfig, *esLoader) if err != nil { return false, fmt.Errorf("fail to create an Elasticsearch importer for loading the dashboards: %v", err) diff --git a/libbeat/dashboards/es_loader.go b/libbeat/dashboards/es_loader.go index 8264bc1b091b..2c2319c23cd4 100644 --- a/libbeat/dashboards/es_loader.go +++ b/libbeat/dashboards/es_loader.go @@ -44,37 +44,20 @@ func NewElasticsearchLoader(cfg *common.Config, dashboardsConfig *DashboardsConf loader.statusMsg("Initialize the Elasticsearch %s loader", version) - // initialize the Kibana index - if err := loader.createKibanaIndex(); err != nil { - return nil, fmt.Errorf("fail to create the kibana index: %v", err) - } - return &loader, nil } // CreateKibanaIndex creates the kibana index if it doesn't exists and sets // some index properties which are needed as a workaround for: // https://github.com/elastic/beats-dashboards/issues/94 -func (loader ElasticsearchLoader) createKibanaIndex() error { +func (loader ElasticsearchLoader) CreateKibanaIndex() error { status, err := loader.client.IndexExists(loader.config.KibanaIndex) if err != nil { if status != 404 { return err } else { - var settings common.MapStr - // XXX: this can be removed when the dashboard loaded will no longer need to support 6.0, - // because the Kibana API is used instead - if strings.HasPrefix(loader.client.GetVersion(), "6.") { - settings = common.MapStr{ - "settings": common.MapStr{ - "index.mapping.single_type": false, - }, - } - } else { - settings = nil - } - _, _, err = loader.client.CreateIndex(loader.config.KibanaIndex, settings) + _, _, err = loader.client.CreateIndex(loader.config.KibanaIndex, nil) if err != nil { return fmt.Errorf("Failed to create index: %v", err) } diff --git a/libbeat/dashboards/es_loader_test.go b/libbeat/dashboards/es_loader_test.go index 867e1fae4c3b..f160482ef841 100644 --- a/libbeat/dashboards/es_loader_test.go +++ b/libbeat/dashboards/es_loader_test.go @@ -32,7 +32,7 @@ func TestImporter(t *testing.T) { config: &dashboardsConfig, } - err := loader.createKibanaIndex() + err := loader.CreateKibanaIndex() assert.NoError(t, err)