mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
parent
d38268e9ee
commit
9f6e55543e
4 changed files with 80 additions and 10 deletions
|
@ -27,10 +27,6 @@ export const register = ({ router, getLicenseStatus, log }: RouteDependencies) =
|
|||
});
|
||||
}
|
||||
|
||||
const {
|
||||
core: { elasticsearch },
|
||||
} = ctx;
|
||||
|
||||
const {
|
||||
body: { query, index },
|
||||
} = request;
|
||||
|
@ -46,21 +42,25 @@ export const register = ({ router, getLicenseStatus, log }: RouteDependencies) =
|
|||
body: JSON.stringify(parsed, null, 2),
|
||||
};
|
||||
try {
|
||||
const resp = await elasticsearch.legacy.client.callAsCurrentUser('search', body);
|
||||
const client = ctx.core.elasticsearch.client.asCurrentUser;
|
||||
const resp = await client.search(body);
|
||||
|
||||
return response.ok({
|
||||
body: {
|
||||
ok: true,
|
||||
resp,
|
||||
resp: resp.body,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
log.error(err);
|
||||
const { statusCode, body: errorBody } = err;
|
||||
|
||||
return response.customError({
|
||||
statusCode: err.status || 500,
|
||||
body: err.body
|
||||
statusCode: statusCode || 500,
|
||||
body: errorBody
|
||||
? {
|
||||
message: err.message,
|
||||
attributes: err.body,
|
||||
message: errorBody.error?.reason,
|
||||
attributes: errorBody,
|
||||
}
|
||||
: err,
|
||||
});
|
||||
|
|
|
@ -33,5 +33,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
|
|||
loadTestFile(require.resolve('./transform'));
|
||||
loadTestFile(require.resolve('./lists'));
|
||||
loadTestFile(require.resolve('./upgrade_assistant'));
|
||||
loadTestFile(require.resolve('./searchprofiler'));
|
||||
});
|
||||
}
|
||||
|
|
13
x-pack/test/api_integration/apis/searchprofiler/index.ts
Normal file
13
x-pack/test/api_integration/apis/searchprofiler/index.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
|
||||
export default function ({ loadTestFile }: FtrProviderContext) {
|
||||
describe('Search Profiler', () => {
|
||||
loadTestFile(require.resolve('./searchprofiler'));
|
||||
});
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
|
||||
const API_BASE_PATH = '/api/searchprofiler';
|
||||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
const supertest = getService('supertest');
|
||||
|
||||
describe('Profile', () => {
|
||||
it('should return profile results for a valid index', async () => {
|
||||
const payload = {
|
||||
index: '_all',
|
||||
query: {
|
||||
query: {
|
||||
match_all: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const { body } = await supertest
|
||||
.post(`${API_BASE_PATH}/profile`)
|
||||
.set('kbn-xsrf', 'xxx')
|
||||
.set('Content-Type', 'application/json;charset=UTF-8')
|
||||
.send(payload)
|
||||
.expect(200);
|
||||
|
||||
expect(body.ok).to.eql(true);
|
||||
});
|
||||
|
||||
it('should return error for invalid index', async () => {
|
||||
const payloadWithInvalidIndex = {
|
||||
index: 'index_does_not_exist',
|
||||
query: {
|
||||
query: {
|
||||
match_all: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const { body } = await supertest
|
||||
.post(`${API_BASE_PATH}/execute`)
|
||||
.set('kbn-xsrf', 'xxx')
|
||||
.set('Content-Type', 'application/json;charset=UTF-8')
|
||||
.send(payloadWithInvalidIndex)
|
||||
.expect(404);
|
||||
|
||||
expect(body.error).to.eql('Not Found');
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue