Skip to content

Commit

Permalink
Create Kibana index after checking ES version
Browse files Browse the repository at this point in the history
Only create the .kibana index after checking that the ES version is < 6.0 because on > 6.0 the Kibana API is used.

I also removed the code to set `index.mapping.single_type` because that setting is no longer accepted by 6.0.

Fixes elastic#4659
  • Loading branch information
andrewkroh committed Jul 12, 2017
1 parent 7a6a5dd commit 8b14edd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
4 changes: 4 additions & 0 deletions libbeat/dashboards/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 2 additions & 19 deletions libbeat/dashboards/es_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion libbeat/dashboards/es_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestImporter(t *testing.T) {
config: &dashboardsConfig,
}

err := loader.createKibanaIndex()
err := loader.CreateKibanaIndex()

assert.NoError(t, err)

Expand Down

0 comments on commit 8b14edd

Please sign in to comment.