Skip to content

Commit

Permalink
[Enterprise Search] Add language analyzer to connector index creation (
Browse files Browse the repository at this point in the history
  • Loading branch information
sphilipse committed Jul 27, 2022
1 parent 37d5dd6 commit 58f7eaf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ErrorCode } from '../../../common/types/error_codes';
import { setupConnectorsIndices } from '../../index_management/setup_indices';

import { fetchCrawlerByIndexName } from '../crawler/fetch_crawlers';
import { textAnalysisSettings } from '../indices/text_analysis';

import { addConnector } from './add_connector';
import { fetchConnectorByIndexName } from './fetch_connectors';
Expand Down Expand Up @@ -52,15 +53,15 @@ describe('addConnector lib function', () => {
await expect(
addConnector(mockClient as unknown as IScopedClusterClient, {
index_name: 'index_name',
language: 'en',
language: 'fr',
})
).resolves.toEqual({ id: 'fakeId', index_name: 'index_name' });
expect(mockClient.asCurrentUser.index).toHaveBeenCalledWith({
document: {
api_key_id: null,
configuration: {},
index_name: 'index_name',
language: 'en',
language: 'fr',
last_seen: null,
last_sync_error: null,
last_sync_status: null,
Expand All @@ -73,7 +74,10 @@ describe('addConnector lib function', () => {
},
index: CONNECTORS_INDEX,
});
expect(mockClient.asCurrentUser.indices.create).toHaveBeenCalledWith({ index: 'index_name' });
expect(mockClient.asCurrentUser.indices.create).toHaveBeenCalledWith({
index: 'index_name',
settings: textAnalysisSettings('fr'),
});
});

it('should reject if index already exists', async () => {
Expand Down Expand Up @@ -156,7 +160,10 @@ describe('addConnector lib function', () => {
},
index: CONNECTORS_INDEX,
});
expect(mockClient.asCurrentUser.indices.create).toHaveBeenCalledWith({ index: 'index_name' });
expect(mockClient.asCurrentUser.indices.create).toHaveBeenCalledWith({
index: 'index_name',
settings: textAnalysisSettings(undefined),
});
});

it('should create index if no connectors index exists', async () => {
Expand Down Expand Up @@ -196,6 +203,7 @@ describe('addConnector lib function', () => {
});
expect(mockClient.asCurrentUser.indices.create).toHaveBeenCalledWith({
index: 'search-index_name',
settings: textAnalysisSettings('en'),
});
});
it('should not create index if status code is not 404', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { setupConnectorsIndices } from '../../index_management/setup_indices';
import { isIndexNotFoundException } from '../../utils/identify_exceptions';

import { fetchCrawlerByIndexName } from '../crawler/fetch_crawlers';
import { textAnalysisSettings } from '../indices/text_analysis';

import { deleteConnectorById } from './delete_connector';

Expand Down Expand Up @@ -51,7 +52,10 @@ const createConnector = async (
document,
index: CONNECTORS_INDEX,
});
await client.asCurrentUser.indices.create({ index });
await client.asCurrentUser.indices.create({
index,
settings: textAnalysisSettings(language ?? undefined),
});
await client.asCurrentUser.indices.refresh({ index: CONNECTORS_INDEX });

return { id: result._id, index_name: document.index_name };
Expand Down

0 comments on commit 58f7eaf

Please sign in to comment.