Skip to content

Commit

Permalink
Merge pull request #23 from gwintzer/es-settings-in-conf
Browse files Browse the repository at this point in the history
Set up the number of shards and replicas when index is creating
  • Loading branch information
gwintzer authored Jun 5, 2019
2 parents db2f98d + 3d66504 commit f70761f
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 88 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@

![view comments](assets/view-comments.gif)

## configuration


Set the number of shards and replicas for new comment's indices
Edit your kibana.yml
```
kibana-comments-app-plugin.newIndexNumberOfShards: 1 # default to 1
kibana-comments-app-plugin.newIndexNumberOfReplicas: 1 # default to 1
```


## development

This plugin is bootstrapped from [template-kibana-plugin](https://github.com/elastic/template-kibana-plugin)
Expand Down
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export default function (kibana) {
app: {
title: 'Comments',
description: 'A plugin to add comments to your Kibana dashboards',
main: 'plugins/kibana-comments-app-plugin/app'
main: 'plugins/kibana-comments-app-plugin/app',
euiIconType: 'tag'
}

},
Expand All @@ -25,16 +26,18 @@ export default function (kibana) {

return Joi.object({
enabled: Joi.boolean().default(true),
newIndexNumberOfShards: Joi.number().integer().default(1),
newIndexNumberOfReplicas: Joi.number().integer().default(1)
}).default();
},

init(server, options) {

// Add server routes and initialize the plugin here
const dataCluster = server.plugins.elasticsearch.getCluster('data');
const dataCluster = server.plugins.elasticsearch.getCluster('data')

serverRouteEsComment(server, dataCluster);
serverRouteEsIndex(server, dataCluster);
serverRouteEsComment(server, dataCluster)
serverRouteEsIndex(server, dataCluster)
}


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "kibana-comments-app-plugin",
"version": "6.6.0-1",
"version": "6.6+-1",
"description": "An application plugin to add and manage comments to your Kibana dashboards",
"main": "index.js",
"kibana": {
"version": "6.6.0",
"version": "6.7.1",
"templateVersion": "7.2.0"
},
"scripts": {
Expand Down
21 changes: 12 additions & 9 deletions server/routes/esIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ export default function (server, dataCluster) {
//const mandatoryFields = ["date", "comment"];

const baseIndex = "comments";
const defaultType = "document";

const defaultNewIndexSettings = {
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 1
}
}

// Route GET : list indices
server.route({
Expand Down Expand Up @@ -41,15 +33,26 @@ export default function (server, dataCluster) {
path: '/api/kibana-comments-plugin/index/{name?}',
method: 'PUT',
handler: async(req, h) => {

try {
const config = req.server.config();
const pluginConfig = config.get('kibana-comments-app-plugin');

const newIndexSettings = {
"settings" : {
"number_of_shards" : pluginConfig.newIndexNumberOfShards || 1,
"number_of_replicas" : pluginConfig.newIndexNumberOfReplicas || 1
}
}

let indexName = baseIndex;

if (req.params.name)
indexName += '-' + encodeURIComponent(req.params.name);

var response = await dataCluster.callWithRequest(req, 'indices.create', {
index: indexName,
body: defaultNewIndexSettings,
body: newIndexSettings,
ignore: [400]
})

Expand Down
Loading

0 comments on commit f70761f

Please sign in to comment.