mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Revert "[Enterprise Search] Adds an endpoint to fetch an index mapping (#134870)"
This reverts commit fd10f3db1d
.
This commit is contained in:
parent
fd10f3db1d
commit
53e88cecf4
7 changed files with 5 additions and 227 deletions
|
@ -23,7 +23,6 @@ type PayloadType = 'params' | 'query' | 'body';
|
|||
interface IMockRouter {
|
||||
method: MethodType;
|
||||
path: string;
|
||||
context?: jest.Mocked<RequestHandlerContext>;
|
||||
}
|
||||
interface IMockRouterRequest {
|
||||
body?: object;
|
||||
|
@ -36,15 +35,13 @@ export class MockRouter {
|
|||
public router!: jest.Mocked<IRouter>;
|
||||
public method: MethodType;
|
||||
public path: string;
|
||||
public context: jest.Mocked<RequestHandlerContext>;
|
||||
public payload?: PayloadType;
|
||||
public response = httpServerMock.createResponseFactory();
|
||||
|
||||
constructor({ method, path, context = {} as jest.Mocked<RequestHandlerContext> }: IMockRouter) {
|
||||
constructor({ method, path }: IMockRouter) {
|
||||
this.createRouter();
|
||||
this.method = method;
|
||||
this.path = path;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public createRouter = () => {
|
||||
|
@ -54,7 +51,8 @@ export class MockRouter {
|
|||
public callRoute = async (request: MockRouterRequest) => {
|
||||
const route = this.findRouteRegistration();
|
||||
const [, handler] = route;
|
||||
await handler(this.context, httpServerMock.createKibanaRequest(request as any), this.response);
|
||||
const context = {} as jest.Mocked<RequestHandlerContext>;
|
||||
await handler(context, httpServerMock.createKibanaRequest(request as any), this.response);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { IScopedClusterClient } from '@kbn/core/server';
|
||||
|
||||
import { fetchMapping } from './fetch_mapping';
|
||||
|
||||
describe('fetchMapping lib function', () => {
|
||||
const mockClient = {
|
||||
asCurrentUser: {
|
||||
indices: {
|
||||
getMapping: jest.fn(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const indexName = 'search-regular-index';
|
||||
|
||||
const regularMappingResponse = {
|
||||
'search-regular-index': {
|
||||
mappings: {
|
||||
dynamic: true,
|
||||
dynamic_templates: [],
|
||||
properties: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const emptyMappingResponse = {
|
||||
'search-regular-index': {
|
||||
mappings: {},
|
||||
},
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should return regular mapping information', async () => {
|
||||
mockClient.asCurrentUser.indices.getMapping.mockImplementation(() => regularMappingResponse);
|
||||
|
||||
await expect(
|
||||
fetchMapping(mockClient as unknown as IScopedClusterClient, indexName)
|
||||
).resolves.toEqual({
|
||||
mappings: {
|
||||
dynamic: true,
|
||||
dynamic_templates: [],
|
||||
properties: {},
|
||||
},
|
||||
});
|
||||
|
||||
expect(mockClient.asCurrentUser.indices.getMapping).toHaveBeenCalledWith({
|
||||
index: indexName,
|
||||
expand_wildcards: ['open'],
|
||||
});
|
||||
});
|
||||
|
||||
it('should return empty object when no mapping is found', async () => {
|
||||
mockClient.asCurrentUser.indices.getMapping.mockImplementationOnce(() => emptyMappingResponse);
|
||||
|
||||
await expect(
|
||||
fetchMapping(mockClient as unknown as IScopedClusterClient, indexName)
|
||||
).resolves.toEqual({ mappings: {} });
|
||||
|
||||
expect(mockClient.asCurrentUser.indices.getMapping).toHaveBeenCalledWith({
|
||||
index: indexName,
|
||||
expand_wildcards: ['open'],
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { IndicesGetMappingIndexMappingRecord } from '@elastic/elasticsearch/lib/api/types';
|
||||
import { IScopedClusterClient } from '@kbn/core/server';
|
||||
|
||||
export const fetchMapping = async (
|
||||
client: IScopedClusterClient,
|
||||
indexName: string
|
||||
): Promise<IndicesGetMappingIndexMappingRecord> => {
|
||||
const mapping = await client.asCurrentUser.indices.getMapping({
|
||||
index: indexName,
|
||||
expand_wildcards: ['open'],
|
||||
});
|
||||
return mapping[indexName];
|
||||
};
|
|
@ -45,9 +45,9 @@ import {
|
|||
} from './lib/enterprise_search_request_handler';
|
||||
|
||||
import { registerAppSearchRoutes } from './routes/app_search';
|
||||
import { registerEnterpriseSearchRoutes } from './routes/enterprise_search';
|
||||
import { registerConfigDataRoute } from './routes/enterprise_search/config_data';
|
||||
import { registerConnectorRoutes } from './routes/enterprise_search/connectors';
|
||||
import { registerIndexRoutes } from './routes/enterprise_search/indices';
|
||||
import { registerTelemetryRoute } from './routes/enterprise_search/telemetry';
|
||||
import { registerWorkplaceSearchRoutes } from './routes/workplace_search';
|
||||
|
||||
|
@ -160,8 +160,8 @@ export class EnterpriseSearchPlugin implements Plugin {
|
|||
|
||||
registerConfigDataRoute(dependencies);
|
||||
registerAppSearchRoutes(dependencies);
|
||||
registerEnterpriseSearchRoutes(dependencies);
|
||||
registerWorkplaceSearchRoutes(dependencies);
|
||||
registerIndexRoutes(dependencies);
|
||||
registerConnectorRoutes(dependencies);
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
import { registerIndexRoutes } from './indices';
|
||||
import { registerMappingRoute } from './mapping';
|
||||
|
||||
export const registerEnterpriseSearchRoutes = (dependencies: RouteDependencies) => {
|
||||
registerIndexRoutes(dependencies);
|
||||
registerMappingRoute(dependencies);
|
||||
};
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { RequestHandlerContext } from '@kbn/core/server';
|
||||
|
||||
jest.mock('../../lib/fetch_mapping', () => ({
|
||||
fetchMapping: jest.fn(),
|
||||
}));
|
||||
import { fetchMapping } from '../../lib/fetch_mapping';
|
||||
|
||||
import { registerMappingRoute } from './mapping';
|
||||
|
||||
describe('Elasticsearch Index Mapping', () => {
|
||||
let mockRouter: MockRouter;
|
||||
const mockClient = {};
|
||||
|
||||
beforeEach(() => {
|
||||
const context = {
|
||||
core: Promise.resolve({ elasticsearch: { client: mockClient } }),
|
||||
} as jest.Mocked<RequestHandlerContext>;
|
||||
|
||||
mockRouter = new MockRouter({
|
||||
context,
|
||||
method: 'get',
|
||||
path: '/internal/enterprise_search/{index_name}/mapping',
|
||||
});
|
||||
|
||||
registerMappingRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/enterprise_search/{index_name}/mapping', () => {
|
||||
it('fails validation without index_name', () => {
|
||||
const request = { params: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('returns the mapping for an Elasticsearch index', async () => {
|
||||
const mockData = {
|
||||
mappings: {
|
||||
dynamic: true,
|
||||
dynamic_templates: [],
|
||||
properties: {},
|
||||
},
|
||||
};
|
||||
|
||||
(fetchMapping as jest.Mock).mockImplementationOnce(() => {
|
||||
return Promise.resolve(mockData);
|
||||
});
|
||||
|
||||
await mockRouter.callRoute({
|
||||
params: { index_name: 'search-index-name' },
|
||||
});
|
||||
|
||||
expect(fetchMapping).toHaveBeenCalledWith(mockClient, 'search-index-name');
|
||||
|
||||
expect(mockRouter.response.ok).toHaveBeenCalledWith({
|
||||
body: mockData,
|
||||
headers: { 'content-type': 'application/json' },
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { fetchMapping } from '../../lib/fetch_mapping';
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerMappingRoute({ router }: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/enterprise_search/{index_name}/mapping',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
index_name: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
async (context, request, response) => {
|
||||
const { client } = (await context.core).elasticsearch;
|
||||
try {
|
||||
const mapping = await fetchMapping(client, request.params.index_name);
|
||||
return response.ok({
|
||||
body: mapping,
|
||||
headers: { 'content-type': 'application/json' },
|
||||
});
|
||||
} catch (error) {
|
||||
return response.customError({
|
||||
statusCode: 502,
|
||||
body: 'Error fetching data from Enterprise Search',
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue