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

Update elasticsearch client version #97360

Closed
wants to merge 2 commits into from
Closed
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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"@elastic/apm-rum-react": "^1.2.5",
"@elastic/charts": "28.0.1",
"@elastic/datemath": "link:bazel-bin/packages/elastic-datemath/npm_module",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@^8.0.0-canary.4",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@^8.0.0-canary.6",
"@elastic/ems-client": "7.12.0",
"@elastic/eui": "32.0.4",
"@elastic/filesaver": "1.1.2",
Expand Down
1 change: 1 addition & 0 deletions src/core/server/elasticsearch/client/configure_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const configureClient = (
): Client => {
const clientOptions = parseClientOptions(config, scoped);

// @ts-expect-error @elastic/elasticsearch Client should be class
const client = new Client(clientOptions);
addLogging(client, logger.get('query', type));

Expand Down
1 change: 1 addition & 0 deletions src/core/server/elasticsearch/client/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const createInternalClientMock = (
res?: MockedTransportRequestPromise<unknown>
): DeeplyMockedKeys<Client> => {
// we mimic 'reflection' on a concrete instance of the client to generate the mocked functions.
// @ts-expect-error @elastic/elasticsearch Client should be class
const client = new Client({
node: 'http://localhost',
}) as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('ElasticIndex', () => {
return elasticsearchClientMock.createSuccessTransportRequestPromise({
[index]: {
aliases: { foo: index },
mappings: { dynamic: 'strict', properties: { a: 'b' } },
mappings: { dynamic: 'strict', properties: { a: 'b' } as any },
Copy link
Member

Choose a reason for hiding this comment

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

should we fix the mocked result instead of casting it as any? { a: 'b' } doesn't seem to fit any mapping definition.

settings: {},
},
} as estypes.GetIndexResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export async function createIndex(
mappings?: IndexMapping
) {
await client.indices.create({
body: { mappings, settings },
body: { mappings: mappings as estypes.TypeMapping, settings },
index,
});
}
Expand All @@ -283,7 +283,7 @@ export async function convertToAlias(
script?: string
) {
await client.indices.create({
body: { mappings: info.mappings, settings },
body: { mappings: info.mappings as estypes.TypeMapping, settings },
index: info.indexName,
});

Expand Down Expand Up @@ -406,7 +406,6 @@ async function reindex(
task_id: String(task),
});

// @ts-expect-error @elastic/elasticsearch GetTaskResponse doesn't contain `error` property
const e = body.error;
if (e) {
throw new Error(`Re-index failed [${e.type}] ${e.reason} :: ${JSON.stringify(e)}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,11 @@ const mockV2MigrationOptions = () => {
)
);
options.client.indices.addBlock.mockReturnValue(
elasticsearchClientMock.createSuccessTransportRequestPromise({ acknowledged: true })
elasticsearchClientMock.createSuccessTransportRequestPromise({
acknowledged: true,
shards_acknowledged: true,
indices: [],
})
);
options.client.reindex.mockReturnValue(
elasticsearchClientMock.createSuccessTransportRequestPromise({
Expand Down
9 changes: 4 additions & 5 deletions src/core/server/saved_objects/migrationsv2/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const fetchIndices = (

export interface IndexNotFound {
type: 'index_not_found_exception';
index: string;
index?: string;
}
/**
* Sets a write block in place for the given index. If the response includes
Expand Down Expand Up @@ -305,7 +305,7 @@ export const cloneIndex = (
};

interface WaitForTaskResponse {
error: Option.Option<{ type: string; reason: string; index: string }>;
error: Option.Option<{ type: string; reason: string; index?: string }>;
completed: boolean;
failures: Option.Option<any[]>;
description?: string;
Expand Down Expand Up @@ -367,7 +367,6 @@ const waitForTask = (
const failures = body.response?.failures ?? [];
return Either.right({
completed: body.completed,
// @ts-expect-error @elastic/elasticsearch GetTaskResponse doesn't declare `error` property
error: Option.fromNullable(body.error),
failures: failures.length > 0 ? Option.some(failures) : Option.none,
description: body.task.description,
Expand Down Expand Up @@ -720,7 +719,7 @@ export const createIndex = (
// started
timeout: DEFAULT_TIMEOUT,
body: {
mappings,
mappings: mappings as estypes.TypeMapping,
aliases: aliasesObject,
settings: {
index: {
Expand Down Expand Up @@ -813,7 +812,7 @@ export const updateAndPickupMappings = (
.putMapping({
index,
timeout: DEFAULT_TIMEOUT,
body: mappings,
body: mappings as estypes.TypeMapping,
Copy link
Member

Choose a reason for hiding this comment

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

should we @elastic/elasticsearch? The reason it's failing is that GenericProperty expects all properties to be mandatory.

})
.then((res) => {
// Ignore `acknowledged: false`. When the coordinating node accepts
Expand Down
12 changes: 3 additions & 9 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,6 @@ export class SavedObjectsRepository {
}

const deleteDocNotFound = body.result === 'not_found';
// @ts-expect-error 'error' does not exist on type 'DeleteResponse'
const deleteIndexNotFound = body.error && body.error.type === 'index_not_found_exception';
if (deleteDocNotFound || deleteIndexNotFound) {
// see "404s from missing index" above
Expand Down Expand Up @@ -1372,7 +1371,6 @@ export class SavedObjectsRepository {
}

const deleteDocNotFound = body.result === 'not_found';
// @ts-expect-error
const deleteIndexNotFound = body.error && body.error.type === 'index_not_found_exception';
if (deleteDocNotFound || deleteIndexNotFound) {
// see "404s from missing index" above
Expand Down Expand Up @@ -1906,13 +1904,9 @@ export class SavedObjectsRepository {
const {
body,
statusCode,
} = await this.client.openPointInTime<SavedObjectsOpenPointInTimeResponse>(
// @ts-expect-error @elastic/elasticsearch OpenPointInTimeRequest.index expected to accept string[]
esOptions,
{
ignore: [404],
}
);
} = await this.client.openPointInTime<SavedObjectsOpenPointInTimeResponse>(esOptions, {
ignore: [404],
});
if (statusCode === 404) {
throw SavedObjectsErrorHelpers.createGenericNotFoundError();
}
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/data/server/search/routes/call_msearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import type { estypes } from '@elastic/elasticsearch';
import { IUiSettingsClient, IScopedClusterClient, SharedGlobalConfig } from 'src/core/server';

import type { MsearchRequestBody, MsearchResponse } from '../../../common/search/search_source';
Expand Down Expand Up @@ -78,7 +79,9 @@ export function getCallMsearch(dependencies: CallMsearchDependencies) {
body: {
...response,
body: {
responses: response.body.responses?.map((r) => shimHitsTotal(r)),
responses: response.body.responses?.map((r) =>
shimHitsTotal(r as estypes.MultiSearchResult)
),
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ export const eqlSearchStrategyProvider = (
};
const promise = id
? client.get({ ...params, id }, request.options)
: client.search(params as EqlSearchStrategyRequest['params'], request.options);
: // @ts-expect-error undefined in not assignable to the search request
client.search(params as EqlSearchStrategyRequest['params'], request.options);
const response = await shimAbortSignal(promise, options.abortSignal);
// @ts-expect-error _shards is optional in @elastic/elasticsearch EqlGetResponse
return toEqlKibanaSearchResponse(response as ApiResponse<EqlSearchResponse>);
};

Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/lens/server/routes/existing_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ async function fetchIndexPatternStats({
_source: false,
runtime_mappings: runtimeFields.reduce((acc, field) => {
if (!field.runtimeField) return acc;
// @ts-expect-error @elastic/elasticsearch StoredScript.language is required
acc[field.name] = field.runtimeField;
return acc;
}, {} as Record<string, estypes.RuntimeField>),
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/lens/server/routes/field_stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export async function initFieldsRoute(setup: CoreSetup<PluginStartContract>) {
body: {
query,
aggs,
// @ts-expect-error @elastic/elasticsearch StoredScript.language is required
runtime_mappings: field.runtimeField ? { [fieldName]: field.runtimeField } : {},
},
size: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export function definePutRolesRoutes({
const body = transformPutPayloadToElasticsearchRole(
request.body,
authz.applicationName,
// @ts-expect-error @elastic/elasticsearch `XPackRole` type doesn't define `applications`.
rawRoles[name] ? rawRoles[name].applications : []
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export class SessionIndex {
try {
await this.options.elasticsearchClient.indices.putTemplate({
name: sessionIndexTemplateName,
// @ts-expect-error @elastic/elasticsearch Property incompatible
body: getSessionIndexTemplate(this.indexName),
});
this.options.logger.debug('Successfully created session index template.');
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/snapshot_restore/server/routes/api/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ export function registerPolicyRoutes({
name: '*',
expand_wildcards: 'all',
});
// @ts-expect-error @elastic/elasticsearch ResolveIndexAliasItem doesn't declare attributes
// https://github.com/elastic/elasticsearch/pull/57626
const resolvedIndicesResponse = response.body as ResolveIndexResponseFromES;

const body: PolicyIndicesResponse = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export function registerRepositoriesRoutes({
snapshot: '_all',
});

// @ts-expect-error @elastic/elasticsearch remove this "as unknown" workaround when the types for this endpoint are correct. Track progress at https://github.com/elastic/elastic-client-generator/issues/250.
const { responses: snapshotResponses } = response.body;

if (repositoryByName[name]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export function registerSnapshotsRoutes({
ignore_unavailable: true, // Allow request to succeed even if some snapshots are unavailable.
});

// @ts-expect-error @elastic/elasticsearch remove this "as unknown" workaround when the types for this endpoint are correct. Track progress at https://github.com/elastic/elastic-client-generator/issues/250.
const { responses: fetchedResponses } = response.body;

// Decorate each snapshot with the repository with which it's associated.
Expand Down Expand Up @@ -135,7 +134,6 @@ export function registerSnapshotsRoutes({
ignore_unavailable: true,
});

// @ts-expect-error @elastic/elasticsearch remove this "as unknown" workaround when the types for this endpoint are correct. Track progress at https://github.com/elastic/elastic-client-generator/issues/250.
const { responses: snapshotsResponse } = response.body;

const snapshotsList =
Expand All @@ -144,7 +142,6 @@ export function registerSnapshotsRoutes({
return res.notFound({ body: 'Snapshot not found' });
}
const selectedSnapshot = snapshotsList.find(
// @ts-expect-error @elastic/elasticsearch related to above incorrect type from client
({ snapshot: snapshotName }) => snapshot === snapshotName
) as SnapshotDetailsEs;

Expand All @@ -154,9 +151,7 @@ export function registerSnapshotsRoutes({
}

const successfulSnapshots = snapshotsList
// @ts-expect-error @elastic/elasticsearch related to above incorrect type from client
.filter(({ state }) => state === 'SUCCESS')
// @ts-expect-error @elastic/elasticsearch related to above incorrect type from client
.sort((a, b) => {
return +new Date(b.end_time!) - +new Date(a.end_time!);
}) as SnapshotDetailsEs[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export interface WorkloadAggregation {

// The type of a bucket in the scheduleDensity range aggregation
type ScheduleDensityResult = AggregationResultOf<
// @ts-expect-error AggregationRange reqires from: number
WorkloadAggregation['aggs']['idleTasks']['aggs']['scheduleDensity'],
{}
>['buckets'][0];
Expand Down Expand Up @@ -137,9 +136,7 @@ export function createWorkloadAggregator(
field: 'task.runAt',
ranges: [
{
// @ts-expect-error @elastic/elasticsearch The `AggregationRange` type only supports `double` for `from` and `to` but it can be a string too for time based ranges
from: `now`,
// @ts-expect-error @elastic/elasticsearch The `AggregationRange` type only supports `double` for `from` and `to` but it can be a string too for time based ranges
to: `now+${asInterval(scheduleDensityBuckets * pollInterval)}`,
},
],
Expand All @@ -151,7 +148,7 @@ export function createWorkloadAggregator(
field: 'task.runAt',
fixed_interval: asInterval(pollInterval),
},
// break down each bucket in the historgram by schedule
// break down each bucket in the histogram by schedule
aggs: {
interval: {
terms: { field: 'task.schedule.interval' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ describe('getUpgradeAssistantStatus', () => {
asApiResponse(deprecationsResponse)
);

esClient.asCurrentUser.indices.resolveIndex.mockResolvedValue(asApiResponse(resolvedIndices));
esClient.asCurrentUser.indices.resolveIndex.mockResolvedValue(
// @ts-expect-error not full interface
asApiResponse(resolvedIndices)
);

it('calls /_migration/deprecations', async () => {
await getUpgradeAssistantStatus(esClient, false);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1389,10 +1389,10 @@
version "0.0.0"
uid ""

"@elastic/elasticsearch@npm:@elastic/elasticsearch-canary@^8.0.0-canary.4":
version "8.0.0-canary.4"
resolved "https://registry.yarnpkg.com/@elastic/elasticsearch-canary/-/elasticsearch-canary-8.0.0-canary.4.tgz#6f1a592974941baae347eb8c66a2006848349717"
integrity sha512-UexFloloyvGOhvMc1ePRHCy89sjQL6rPTTZkXAB/GcC8rCvA3mgSnIY2+Ylvctdv9o4l+M4Bkw8azICulyhwMg==
"@elastic/elasticsearch@npm:@elastic/elasticsearch-canary@^8.0.0-canary.6":
version "8.0.0-canary.6"
resolved "https://registry.yarnpkg.com/@elastic/elasticsearch-canary/-/elasticsearch-canary-8.0.0-canary.6.tgz#8406f3a35fbebb1a8990ab5a045f44f122314444"
integrity sha512-IYij5MMTya3eAa37iHuGL7ZIZbKhDNiMNvzKr9iB8g91otprAWsF8m7n1+Nb4++6Z6sv7X06+wM+REfvFBrC3Q==
dependencies:
debug "^4.3.1"
hpagent "^0.1.1"
Expand Down