Skip to content
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
2 changes: 2 additions & 0 deletions x-pack/plugins/enterprise_search/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,5 @@ export const DEFAULT_PRODUCT_FEATURES: ProductFeatures = {
hasNativeConnectors: true,
hasWebCrawler: true,
};

export const CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX = '.search-acl-filter-';
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {

import { i18n } from '@kbn/i18n';

import { CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX } from '../../../../../common/constants';

import { KibanaLogic } from '../../../shared/kibana';

import {
Expand All @@ -44,7 +46,7 @@ export const SearchIndexDocuments: React.FC = () => {
const indexToShow =
selectedIndexType === 'content-index'
? indexName
: indexName.replace('search-', '.search-acl-filter-');
: indexName.replace('search-', CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX);

const shouldShowAccessControlSwitcher =
hasDocumentLevelSecurityFeature && productFeatures.hasDocumentLevelSecurityEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';

import { CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX } from '../../../../../common/constants';

import { docLinks } from '../../../shared/doc_links';

import { KibanaLogic } from '../../../shared/kibana';
Expand All @@ -51,7 +53,7 @@ export const SearchIndexIndexMappings: React.FC = () => {
const indexToShow =
selectedIndexType === 'content-index'
? indexName
: indexName.replace('search-', '.search-acl-filter-');
: indexName.replace('search-', CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX);

const shouldShowAccessControlSwitch =
hasDocumentLevelSecurityFeature && productFeatures.hasDocumentLevelSecurityEnabled;
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/enterprise_search/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ export const CURRENT_CONNECTORS_INDEX = '.elastic-connectors-v1';
export const CONNECTORS_JOBS_INDEX = '.elastic-connectors-sync-jobs';
export const CONNECTORS_VERSION = 1;
export const CRAWLERS_INDEX = '.ent-search-actastic-crawler2_configurations_v2';
export const CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX = '.search-acl-filter-';
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

import { IScopedClusterClient } from '@kbn/core/server';

import {
CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX,
CONNECTORS_INDEX,
CONNECTORS_JOBS_INDEX,
} from '../..';
import { CONNECTORS_INDEX, CONNECTORS_JOBS_INDEX } from '../..';
import { CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX } from '../../../common/constants';

import { SyncJobType, SyncStatus, TriggerMethod } from '../../../common/types/connectors';

import { ErrorCode } from '../../../common/types/error_codes';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@

import { IScopedClusterClient } from '@kbn/core/server';

import {
CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX,
CONNECTORS_INDEX,
CONNECTORS_JOBS_INDEX,
} from '../..';
import { CONNECTORS_INDEX, CONNECTORS_JOBS_INDEX } from '../..';
import { isConfigEntry } from '../../../common/connectors/is_category_entry';

import { ENTERPRISE_SEARCH_CONNECTOR_CRAWLER_SERVICE_TYPE } from '../../../common/constants';
import {
CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX,
ENTERPRISE_SEARCH_CONNECTOR_CRAWLER_SERVICE_TYPE,
} from '../../../common/constants';

import {
ConnectorConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { isIndexNotFoundException } from '@kbn/core-saved-objects-migration-server-internal';
import { IScopedClusterClient } from '@kbn/core/server';

import { CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX } from '../..';
import { CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX } from '../../../common/constants';

export const deleteAccessControlIndex = async (client: IScopedClusterClient, index: string) => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@

import { schema } from '@kbn/config-schema';

import { ErrorCode } from '../../../common/types/error_codes';

import { fetchMapping } from '../../lib/fetch_mapping';
import { RouteDependencies } from '../../plugin';
import { createError } from '../../utils/create_error';
import { elasticsearchErrorHandler } from '../../utils/elasticsearch_error_handler';
import { isIndexNotFoundException } from '../../utils/identify_exceptions';

export function registerMappingRoute({ router, log }: RouteDependencies) {
router.get(
Expand All @@ -24,12 +28,24 @@ export function registerMappingRoute({ router, log }: RouteDependencies) {
elasticsearchErrorHandler(log, async (context, request, response) => {
const { client } = (await context.core).elasticsearch;

const mapping = await fetchMapping(client, request.params.index_name);
try {
const mapping = await fetchMapping(client, request.params.index_name);

return response.ok({
body: mapping,
headers: { 'content-type': 'application/json' },
});
return response.ok({
body: mapping,
headers: { 'content-type': 'application/json' },
});
} catch (error) {
if (isIndexNotFoundException(error)) {
return createError({
errorCode: ErrorCode.INDEX_NOT_FOUND,
message: 'Could not found index',
response,
statusCode: 404,
});
}
throw error;
}
})
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import { SearchResponseBody } from '@elastic/elasticsearch/lib/api/types';
import { schema } from '@kbn/config-schema';

import { ENTERPRISE_SEARCH_DOCUMENTS_DEFAULT_DOC_COUNT } from '../../../common/constants';
import { ErrorCode } from '../../../common/types/error_codes';

import { fetchSearchResults } from '../../lib/fetch_search_results';
import { RouteDependencies } from '../../plugin';
import { createError } from '../../utils/create_error';
import { elasticsearchErrorHandler } from '../../utils/elasticsearch_error_handler';
import { isIndexNotFoundException } from '../../utils/identify_exceptions';

const calculateMeta = (searchResults: SearchResponseBody, page: number, size: number) => {
let totalResults = 0;
Expand Down Expand Up @@ -64,21 +67,33 @@ export function registerSearchRoute({ router, log }: RouteDependencies) {
const { client } = (await context.core).elasticsearch;
const { page = 0, size = ENTERPRISE_SEARCH_DOCUMENTS_DEFAULT_DOC_COUNT } = request.query;
const from = page * size;
const searchResults: SearchResponseBody = await fetchSearchResults(
client,
indexName,
searchQuery,
from,
size
);
try {
const searchResults: SearchResponseBody = await fetchSearchResults(
client,
indexName,
searchQuery,
from,
size
);

return response.ok({
body: {
meta: calculateMeta(searchResults, page, size),
results: searchResults,
},
headers: { 'content-type': 'application/json' },
});
return response.ok({
body: {
meta: calculateMeta(searchResults, page, size),
results: searchResults,
},
headers: { 'content-type': 'application/json' },
});
} catch (error) {
if (isIndexNotFoundException(error)) {
return createError({
errorCode: ErrorCode.INDEX_NOT_FOUND,
message: 'Could not found index',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whilst its not everywhere, we typically localise the error message here, especially if presented to the user. Also message could be better: "Index does not exist".

response,
statusCode: 404,
});
}
throw error;
}
})
);
}