Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable dynamic/Implement static mappings #10638

Merged
merged 16 commits into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/core_plugins/elasticsearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import createProxy, { createPath } from './lib/create_proxy';

const DEFAULT_REQUEST_HEADERS = [ 'authorization' ];

module.exports = function ({ Plugin }) {
return new Plugin({
module.exports = function (kibana) {
return new kibana.Plugin({
require: ['kibana'],

config(Joi) {
const { array, boolean, number, object, string, ref } = Joi;

Expand Down Expand Up @@ -159,9 +158,9 @@ module.exports = function ({ Plugin }) {
pre: [ noDirectIndex, noBulkCheck ]
}
);

// Set up the health check service and start it.
const { start, waitUntilReady } = healthCheck(this, server);
const mappings = kibana.uiExports.mappings.getCombined();
const { start, waitUntilReady } = healthCheck(this, server, { mappings });
server.expose('waitUntilReady', waitUntilReady);
start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash';
import sinon from 'sinon';
import expect from 'expect.js';
import Promise from 'bluebird';

import mappings from './fixtures/mappings';
import createKibanaIndex from '../create_kibana_index';

describe('plugins/elasticsearch', function () {
Expand All @@ -22,13 +22,12 @@ describe('plugins/elasticsearch', function () {
get.withArgs('kibana.index').returns(config.kibana.index);
config = function () { return { get: get }; };

_.set(server, 'plugins.elasticsearch', {});
_.set(server, 'config', config);

callWithInternalUser = sinon.stub();
cluster = { callWithInternalUser: callWithInternalUser };

server.plugins.elasticsearch.getCluster = sinon.stub().withArgs('admin').returns(cluster);
_.set(server, 'plugins.elasticsearch.getCluster', sinon.stub().withArgs('admin').returns(cluster));
});

describe('successful requests', function () {
Expand All @@ -38,14 +37,14 @@ describe('plugins/elasticsearch', function () {
});

it('should check cluster.health upon successful index creation', function () {
const fn = createKibanaIndex(server);
const fn = createKibanaIndex(server, mappings);
return fn.then(function () {
sinon.assert.calledOnce(callWithInternalUser.withArgs('cluster.health', sinon.match.any));
});
});

it('should be created with mappings for config.buildNum', function () {
const fn = createKibanaIndex(server);
const fn = createKibanaIndex(server, mappings);
return fn.then(function () {
const params = callWithInternalUser.args[0][1];
expect(params)
Expand All @@ -64,7 +63,7 @@ describe('plugins/elasticsearch', function () {
});

it('should be created with 1 shard and default replica', function () {
const fn = createKibanaIndex(server);
const fn = createKibanaIndex(server, mappings);
return fn.then(function () {
const params = callWithInternalUser.args[0][1];
expect(params)
Expand All @@ -79,7 +78,7 @@ describe('plugins/elasticsearch', function () {
});

it('should be created with index name set in the config', function () {
const fn = createKibanaIndex(server);
const fn = createKibanaIndex(server, mappings);
return fn.then(function () {
const params = callWithInternalUser.args[0][1];
expect(params)
Expand Down
13 changes: 13 additions & 0 deletions src/core_plugins/elasticsearch/lib/__tests__/fixtures/mappings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'_default_': {
'dynamic': 'strict'
},
config: {
dynamic: true,
properties: {
buildNum: {
type: 'keyword'
}
}
}
};
3 changes: 2 additions & 1 deletion src/core_plugins/elasticsearch/lib/__tests__/health_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import url from 'url';

const NoConnections = require('elasticsearch').errors.NoConnections;

import mappings from './fixtures/mappings';
import healthCheck from '../health_check';
import kibanaVersion from '../kibana_version';
import serverConfig from '../../../../../test/server_config';
Expand Down Expand Up @@ -70,7 +71,7 @@ describe('plugins/elasticsearch', () => {
}
};

health = healthCheck(plugin, server);
health = healthCheck(plugin, server, { mappings });
});

afterEach(() => {
Expand Down
8 changes: 3 additions & 5 deletions src/core_plugins/elasticsearch/lib/create_kibana_index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { mappings } from './kibana_index_mappings';

module.exports = function (server) {
module.exports = function (server, mappings) {
const { callWithInternalUser } = server.plugins.elasticsearch.getCluster('admin');
const index = server.config().get('kibana.index');

return callWithInternalUser('indices.create', {
index: index,
body: {
settings: {
number_of_shards: 1
number_of_shards: 1,
'index.mapper.dynamic': false,
},
mappings
}
Expand Down
6 changes: 3 additions & 3 deletions src/core_plugins/elasticsearch/lib/health_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const NO_INDEX = 'no_index';
const INITIALIZING = 'initializing';
const READY = 'ready';

module.exports = function (plugin, server) {
module.exports = function (plugin, server, { mappings }) {
const config = server.config();
const callAdminAsKibanaUser = server.plugins.elasticsearch.getCluster('admin').callWithInternalUser;
const callDataAsKibanaUser = server.plugins.elasticsearch.getCluster('data').callWithInternalUser;
Expand Down Expand Up @@ -70,7 +70,7 @@ module.exports = function (plugin, server) {
.then(function (health) {
if (health === NO_INDEX) {
plugin.status.yellow('No existing Kibana index found');
return createKibanaIndex(server);
return createKibanaIndex(server, mappings);
}

if (health === INITIALIZING) {
Expand Down Expand Up @@ -98,7 +98,7 @@ module.exports = function (plugin, server) {
.then(() => ensureNotTribe(callAdminAsKibanaUser))
.then(() => ensureAllowExplicitIndex(callAdminAsKibanaUser, config))
.then(waitForShards)
.then(_.partial(migrateConfig, server))
.then(_.partial(migrateConfig, server, { mappings }))
.then(() => {
const tribeUrl = config.get('elasticsearch.tribe.url');
if (tribeUrl) {
Expand Down
16 changes: 0 additions & 16 deletions src/core_plugins/elasticsearch/lib/kibana_index_mappings.js

This file was deleted.

7 changes: 3 additions & 4 deletions src/core_plugins/elasticsearch/lib/migrate_config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { get } from 'lodash';
import upgrade from './upgrade_config';
import { mappings } from './kibana_index_mappings';

module.exports = function (server) {
module.exports = function (server, { mappings }) {
const config = server.config();
const { callWithInternalUser } = server.plugins.elasticsearch.getCluster('admin');

const options = {
index: config.get('kibana.index'),
type: 'config',
Expand All @@ -14,7 +13,7 @@ module.exports = function (server) {
{
buildNum: {
order: 'desc',
unmapped_type: mappings.config.properties.buildNum.type
unmapped_type: get(mappings, 'config.properties.buildNum.type') || 'keyword'
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions src/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import settings from './server/routes/api/settings';
import scripts from './server/routes/api/scripts';
import * as systemApi from './server/lib/system_api';
import handleEsError from './server/lib/handle_es_error';
import mappings from './mappings.json';

const mkdirp = Promise.promisify(mkdirpNode);

module.exports = function (kibana) {
const kbnBaseUrl = '/app/kibana';
return new kibana.Plugin({
id: 'kibana',

config: function (Joi) {
return Joi.object({
enabled: Joi.boolean().default(true),
Expand All @@ -43,7 +43,6 @@ module.exports = function (kibana) {
'devTools',
'docViews'
],

injectVars: function (server) {
const serverConfig = server.config();

Expand Down Expand Up @@ -122,7 +121,8 @@ module.exports = function (kibana) {

translations: [
resolve(__dirname, './translations/en.json')
]
],
mappings
},

preInit: async function (server) {
Expand Down
Loading