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

Change includeTypeName to include_type_name #5

12 changes: 8 additions & 4 deletions packages/kbn-es/src/integration_tests/cluster.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,14 @@ describe('#installSnapshot()', () => {
const cluster = new Cluster(log);
await cluster.installSnapshot({ foo: 'bar' });
expect(installSnapshot).toHaveBeenCalledTimes(1);
expect(installSnapshot).toHaveBeenCalledWith({
log,
foo: 'bar',
});
expect(installSnapshot).toHaveBeenCalledWith(
// In es6.7, this is the literal object. In 7.0, it also
// contains "version": "7.0.0"
expect.objectContaining({
log,
foo: 'bar',
})
);
});

it('rejects if installSnapshot() rejects', async () => {
Expand Down
10 changes: 7 additions & 3 deletions src/es_archiver/lib/indices/create_index_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,20 @@ export function createCreateIndexStream({ client, stats, skipExisting, log, kiba
await client.indices.create({
method: 'PUT',
index,
include_type_name: true,
body: { settings, mappings },
});

if (index.startsWith('.kibana') && await isSpacesEnabled({ kibanaUrl })) {
if (index.startsWith('.kibana') && (await isSpacesEnabled({ kibanaUrl }))) {
await createDefaultSpace({ index, client });
}

stats.createdIndex(index, { settings });
} catch (err) {
if (get(err, 'body.error.type') !== 'resource_already_exists_exception' || attemptNumber >= 3) {
if (
get(err, 'body.error.type') !== 'resource_already_exists_exception' ||
attemptNumber >= 3
) {
throw err;
}

Expand Down Expand Up @@ -104,6 +108,6 @@ export function createCreateIndexStream({ client, stats, skipExisting, log, kiba
} catch (err) {
callback(err);
}
}
},
});
}
2 changes: 1 addition & 1 deletion src/server/sample_data/routes/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const createInstallRoute = () => ({
}
}
},
includeTypeName: true
include_type_name: true
};
await callWithRequest(request, 'indices.create', createIndexParams);
} catch (err) {
Expand Down
2 changes: 2 additions & 0 deletions src/server/saved_objects/migrations/core/call_cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ export interface PutTemplateOpts {

export interface IndexOpts {
index: string;
include_type_name?: boolean;
}

export interface IndexCreationOpts {
index: string;
include_type_name?: boolean;
body?: {
mappings?: IndexMapping;
settings?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ describe('ElasticIndex', () => {

expect(hasMigrations).toBeFalsy();
expect(callCluster.args).toEqual([
['indices.get', { ignore: [404], index: '.myalias', includeTypeName: true }],
['indices.get', { ignore: [404], index: '.myalias', include_type_name: true }],
]);
});

Expand Down
10 changes: 7 additions & 3 deletions src/server/saved_objects/migrations/core/elastic_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export interface FullIndexInfo {
* index mappings are somewhat what we expect.
*/
export async function fetchInfo(callCluster: CallCluster, index: string): Promise<FullIndexInfo> {
const result = await callCluster('indices.get', { ignore: [404], index, includeTypeName: true });
const result = await callCluster('indices.get', {
ignore: [404],
index,
include_type_name: true,
});

if ((result as NotFound).status === 404) {
return {
Expand Down Expand Up @@ -229,7 +233,7 @@ export async function createIndex(
await callCluster('indices.create', {
body: { mappings, settings },
index,
includeTypeName: true,
include_type_name: true,
});
}

Expand All @@ -255,7 +259,7 @@ export async function convertToAlias(
await callCluster('indices.create', {
body: { mappings: info.mappings, settings },
index: info.indexName,
includeTypeName: true,
include_type_name: true,
});

await reindex(callCluster, alias, info.indexName, batchSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('IndexMigrator', () => {
settings: { number_of_shards: 1, auto_expand_replicas: '0-1' },
},
index: '.kibana_1',
includeTypeName: true,
include_type_name: true,
});
});

Expand Down Expand Up @@ -181,7 +181,7 @@ describe('IndexMigrator', () => {
await new IndexMigrator(opts).migrate();

sinon.assert.calledWith(callCluster, 'indices.create', {
includeTypeName: true,
include_type_name: true,
body: {
mappings: {
doc: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function createSavedObjectsService(server, schema, serializer, migrator)
const index = server.config().get('kibana.index');
await adminCluster.callWithInternalUser('indices.putTemplate', {
name: `kibana_index_template:${index}`,
includeTypeName: true,
include_type_name: true,
body: {
template: index,
settings: {
Expand Down
61 changes: 29 additions & 32 deletions src/ui/ui_settings/routes/__tests__/index_missing.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
import expect from 'expect.js';
import sinon from 'sinon';

import {
getServices,
chance,
assertSinonMatch,
} from './lib';
import { getServices, chance, assertSinonMatch } from './lib';

export function indexMissingSuite() {
async function setup() {
Expand All @@ -41,17 +37,18 @@ export function indexMissingSuite() {
// but automatically by writing to es when index didn't exist
async assertValidKibanaIndex() {
const resp = await callCluster('indices.get', {
index: indexName
index: indexName,
include_type_name: true,
});

expect(resp[indexName].mappings).to.have.property('doc');
expect(resp[indexName].mappings.doc.properties).to.have.keys(
const mappings = resp[indexName].mappings.doc;
expect(mappings.properties).to.have.keys(
'index-pattern',
'visualization',
'search',
'dashboard'
);
}
},
};
}

Expand All @@ -61,7 +58,7 @@ export function indexMissingSuite() {

const { statusCode, result } = await kbnServer.inject({
method: 'GET',
url: '/api/kibana/settings'
url: '/api/kibana/settings',
});

expect(statusCode).to.be(200);
Expand All @@ -72,9 +69,9 @@ export function indexMissingSuite() {
},
foo: {
userValue: 'bar',
isOverridden: true
}
}
isOverridden: true,
},
},
});
});
});
Expand All @@ -88,24 +85,24 @@ export function indexMissingSuite() {
method: 'POST',
url: '/api/kibana/settings/defaultIndex',
payload: {
value: defaultIndex
}
value: defaultIndex,
},
});

expect(statusCode).to.be(200);
assertSinonMatch(result, {
settings: {
buildNum: {
userValue: sinon.match.number
userValue: sinon.match.number,
},
defaultIndex: {
userValue: defaultIndex
userValue: defaultIndex,
},
foo: {
userValue: 'bar',
isOverridden: true
}
}
isOverridden: true,
},
},
});

await assertValidKibanaIndex();
Expand All @@ -121,24 +118,24 @@ export function indexMissingSuite() {
method: 'POST',
url: '/api/kibana/settings',
payload: {
changes: { defaultIndex }
}
changes: { defaultIndex },
},
});

expect(statusCode).to.be(200);
assertSinonMatch(result, {
settings: {
buildNum: {
userValue: sinon.match.number
userValue: sinon.match.number,
},
defaultIndex: {
userValue: defaultIndex
userValue: defaultIndex,
},
foo: {
userValue: 'bar',
isOverridden: true
}
}
isOverridden: true,
},
},
});

await assertValidKibanaIndex();
Expand All @@ -151,20 +148,20 @@ export function indexMissingSuite() {

const { statusCode, result } = await kbnServer.inject({
method: 'DELETE',
url: '/api/kibana/settings/defaultIndex'
url: '/api/kibana/settings/defaultIndex',
});

expect(statusCode).to.be(200);
assertSinonMatch(result, {
settings: {
buildNum: {
userValue: sinon.match.number
userValue: sinon.match.number,
},
foo: {
userValue: 'bar',
isOverridden: true
}
}
isOverridden: true,
},
},
});

await assertValidKibanaIndex();
Expand Down
2 changes: 1 addition & 1 deletion test/api_integration/apis/saved_objects/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async function createIndex({ callCluster, index }) {
};
await callCluster('indices.create', {
index,
includeTypeName: true,
include_type_name: true,
body: { mappings: { doc: { dynamic: 'strict', properties } } },
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class KibanaDatabaseAdapter implements DatabaseAdapter {
const result = await this.callWithUser({ kind: 'internal' }, 'indices.putTemplate', {
name,
body: template,
includeTypeName: true,
include_type_name: true,
});

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_facto
async function bootstrap(callWithRequest, payload) {
await callWithRequest('indices.create', {
index: payload.indexName,
include_type_name: true,
body: {
aliases: {
[payload.aliasName]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { licensePreRoutingFactory } from'../../../lib/license_pre_routing_factor
import { merge } from 'lodash';

async function getIndexTemplate(callWithRequest, templateName) {
const response = await callWithRequest('indices.getTemplate', { name: templateName });
const response = await callWithRequest('indices.getTemplate', { name: templateName, include_type_name: true });
return response[templateName];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function formatHit(hit, indexName) {
async function fetchMapping(callWithRequest, indexName) {
const params = {
expand_wildcards: 'none',
includeTypeName: true,
include_type_name: true,
index: indexName,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async function executeUpgrade(callWithRequest) {
return callWithRequest('indices.putMapping', {
index: INDEX_NAMES.PIPELINES,
type: TYPE_NAMES.PIPELINES,
include_type_name: true,
body: {
properties: {
pipeline_settings: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function importDataProvider(callWithRequest) {
body.settings = settings;
}

await callWithRequest('indices.create', { index, body, includeTypeName: true });
await callWithRequest('indices.create', { index, body, include_type_name: true });
}

async function indexData(index, pipelineId, data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function createIndex(client, indexName,
return client.indices.create({
index: indexName,
body: body,
includeTypeName: true,
include_type_name: true,
})
.then(() => true)
.catch(err => {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/task_manager/task_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('TaskStore', () => {
},
},
name: 'tasky',
include_type_name: true,
});
});

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/task_manager/task_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class TaskStore {
// check if template exists
const templateCheck = await this.callCluster('indices.getTemplate', {
name: templateName,
include_type_name: true,
filter_path: '*.version',
});
// extract the existing version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export const reindexActionsFactory = (
async getBooleanFieldPaths(indexName: string) {
const results = await callCluster('indices.getMapping', {
index: indexName,
includeTypeName: true,
include_type_name: true,
});
const mapping = getSingleMappingType(results[indexName].mappings);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const initElasticsearchIndicesHelpers = (es) => {

const createIndex = (index = getRandomString()) => {
indicesCreated.push(index);
return es.indices.create({ index }).then(() => index);
return es.indices.create({ index, include_type_name: true }).then(() => index);
};

const deleteIndex = (index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function ({ getService }) {
let mappings;

before('load mappings', async () => {
const template = await es.indices.getTemplate({ name: indexTemplate });
const template = await es.indices.getTemplate({ name: indexTemplate, include_type_name: true });
mappings = get(template, [indexTemplate, 'mappings', 'doc', 'properties']);
});

Expand Down