Skip to content

Commit

Permalink
Upgrade ES client to 9.0.0-alpha.3 (elastic#208776)
Browse files Browse the repository at this point in the history
## Summary

Updating the ES client to 9.0. 

Resolves elastic#116102

## What changes?

**Breaking change**: `body` has been removed.

Most of the changes are about bringing all the content inside the body
as a root attribute to the API params:

```diff
const response = await client.search({
  index: 'test',
-  body: {
    query: {
      match_all: {}
    }
-  }
})
```

For this reason, enabling the "Hide whitespace changes" option when
reviewing is recommended.

Some exceptions to this rule:

* Bulk APIs replace the `body` array with `operations` array (direct
replacement)
* Index Put Settings API replace `body` array with `settings` (direct
replacement)
* Msearch replaces the `body` array with `searches` array (direct
replacement)
* Document Index API replaces `body` with `document` (direct
replacement)
* Create Repository replaces `body` with `repository` (direct
replacement)

Because of a known issue in the client
(elastic/elasticsearch-js#2584), there's still
an escape hatch to send data in the body in case the specific use case
requires it via `// @ts-expect-error [email protected]
https://github.com/elastic/elasticsearch-js/issues/2584`, but it
shouldn't be abused because we lose types. In this PR we've used it in
those scenarios where we reuse the response of a GET as the body of a
PUT/POST.

### Other changes

* `estypes` can be imported from the root of the library as `import type
{ estypes } from '@elastic/elasticsearch';`
* `estypesWithBody` have been removed
* `requestTimeout`'s 30s default has been removed in the client. This PR
explicitly adds the setting in all client usages.


### Identify risks

- [x] The client places unknown properties as querystring, risking body
params leaking there, and causing 400 errors from ES => Solved by
forcing `body` usage there via `// @ts-expect-error [email protected]
https://github.com/elastic/elasticsearch-js/issues/2584`. The next
version of the client will address this.
- [x] We need to run the MKI tests to make sure that we're not breaking
anything there =>
https://elastic.slack.com/archives/C04HT4P1YS3/p1739528112482629?thread_ts=1739480136.231439&cid=C04HT4P1YS3

---------

Co-authored-by: Gloria Hornero <[email protected]>
  • Loading branch information
afharo and MadameSheema authored Feb 25, 2025
1 parent 3492f12 commit 52ab19d
Show file tree
Hide file tree
Showing 1,907 changed files with 26,727 additions and 29,371 deletions.
2 changes: 1 addition & 1 deletion examples/eso_model_version_example/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export class EsoModelVersionExample
const objectsCreated = await Promise.all(
documentVersionConstants.map(async (obj) => {
const createdDoc: WriteResponseBase =
await elasticsearch.client.asInternalUser.create(obj);
await elasticsearch.client.asInternalUser.create<unknown>(obj);
const parts = createdDoc._id.split(':', 2);
return { type: parts[0], id: parts[1] };
})
Expand Down
12 changes: 7 additions & 5 deletions examples/search_examples/public/search/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,15 @@ export const SearchExamplesApp = ({
const aggs = [{ type: metricAggType, params: { field: selectedNumericField!.name } }];
const aggsDsl = data.search.aggs.createAggConfigs(dataView, aggs).toDsl();

const body = {
aggs: aggsDsl,
query,
};

const req = {
params: {
index: dataView.title,
body: {
aggs: aggsDsl,
query,
},
...body,
},
// Add a custom request parameter to be consumed by `MyStrategy`.
...(strategy ? { get_cool: getCool } : {}),
Expand All @@ -197,7 +199,7 @@ export const SearchExamplesApp = ({
setAbortController(abortController);

// Submit the search request using the `data.search` service.
setRequest(req.params.body);
setRequest(body);
setRawResponse({});
setWarningContents([]);
setIsLoading(true);
Expand Down
6 changes: 2 additions & 4 deletions examples/search_examples/public/search_sessions/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,8 @@ function doSearch(
const req = {
params: {
index: dataView.title,
body: {
aggs: aggsDsl,
query,
},
aggs: aggsDsl,
query,
},
};

Expand Down
10 changes: 4 additions & 6 deletions examples/search_examples/server/routes/server_search_route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ export function registerServerSearchRoute(router: IRouter<DataRequestHandlerCont
{
params: {
index,
body: {
aggs: {
'1': {
avg: {
field,
},
aggs: {
'1': {
avg: {
field,
},
},
},
Expand Down
6 changes: 2 additions & 4 deletions examples/unified_doc_viewer/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ function UnifiedDocViewerExamplesApp({ data }: { data: DataPublicPluginStart })
.search({
params: {
index: dataView?.getIndexPattern(),
body: {
fields: ['*'],
_source: false,
},
fields: ['*'],
_source: false,
},
})
.toPromise();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"@elastic/datemath": "5.0.3",
"@elastic/ebt": "^1.1.1",
"@elastic/ecs": "^8.11.5",
"@elastic/elasticsearch": "^8.17.0",
"@elastic/elasticsearch": "9.0.0-alpha.3",
"@elastic/ems-client": "8.6.3",
"@elastic/eui": "99.2.0-borealis.0",
"@elastic/eui-theme-borealis": "0.0.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export async function reportFailuresToEs(log: ToolingLog, failures: TestFailure[
password: process.env.TEST_FAILURES_ES_PASSWORD,
},
Connection: HttpConnection,
requestTimeout: 30_000,
});

const body = failures.flatMap((failure) => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { Client } from '@elastic/elasticsearch';
import { Client, HttpConnection } from '@elastic/elasticsearch';
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { SearchRequest, MsearchRequestItem } from '@elastic/elasticsearch/lib/api/types';
import { ToolingLog } from '@kbn/tooling-log';
Expand Down Expand Up @@ -109,6 +109,8 @@ export class ESClient {
username: options.username,
password: options.password,
},
Connection: HttpConnection,
requestTimeout: 30_000,
});
this.log = log;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class ElasticsearchService

this.esNodesCompatibility$ = esNodesCompatibility$;

this.clusterInfo$ = getClusterInfo$(this.client.asInternalUser);
this.clusterInfo$ = getClusterInfo$(this.client.asInternalUser).pipe(takeUntil(this.stop$));
registerAnalyticsContextProvider(deps.analytics, this.clusterInfo$);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { isRetryableEsClientErrorMock } from './is_scripting_enabled.test.mocks';
import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { isInlineScriptingEnabled } from './is_scripting_enabled';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '../repository.test.mock';

import type { Payload } from '@hapi/boom';
import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';

import type {
SavedObjectsBulkDeleteObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getSavedObjectFromSourceMock,
rawDocExistsInNamespaceMock,
} from './bulk_get.isolated.test.mocks';
import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import { SavedObject, CheckAuthorizationResult } from '@kbn/core-saved-objects-server';
import { apiContextMock, ApiExecutionContextMock } from '../../mocks';
import { performBulkGet } from './bulk_get';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import type { ISavedObjectsSecurityExtension } from '@kbn/core-saved-objects-server';

import type { Payload } from '@hapi/boom';
import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';

import type { SavedObjectsBulkGetObject } from '@kbn/core-saved-objects-api-server';
import { type SavedObjectsRawDocSource, type SavedObject } from '@kbn/core-saved-objects-server';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '../repository.test.mock';

import type { Payload } from '@hapi/boom';
import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';

import type {
SavedObjectsBulkUpdateObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
mockGetSearchDsl,
} from '../repository.test.mock';

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';

import { ALL_NAMESPACES_STRING } from '@kbn/core-saved-objects-utils-server';
import { SavedObjectsRepository } from '../repository';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
mockGetSearchDsl,
} from '../repository.test.mock';

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';

import type { SavedObjectsCreateOptions } from '@kbn/core-saved-objects-api-server';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
mockGetSearchDsl,
} from '../repository.test.mock';

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';

import type { SavedObjectsDeleteOptions } from '@kbn/core-saved-objects-api-server';
import { ALL_NAMESPACES_STRING } from '@kbn/core-saved-objects-utils-server';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { isSupportedEsServerMock } from './find.isolated.test.mocks';
import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import { SavedObject, AuthorizationTypeMap } from '@kbn/core-saved-objects-server';
import { apiContextMock, ApiExecutionContextMock } from '../../mocks';
import { performFind } from './find';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import Boom from '@hapi/boom';
import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import { isSupportedEsServer } from '@kbn/core-elasticsearch-server-internal';
import {
SavedObjectsErrorHelpers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
mockGetSearchDsl,
} from '../repository.test.mock';

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';

import type { SavedObjectsBaseOptions } from '@kbn/core-saved-objects-api-server';
import { ALL_NAMESPACES_STRING } from '@kbn/core-saved-objects-utils-server';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
mockGetSearchDsl,
} from '../repository.test.mock';

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';

import type {
SavedObjectsIncrementCounterField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ describe('preflightCheckForCreate', () => {
docs: results.map(({ found, disabled }, i) => {
return found
? {
// @ts-expect-error
_id: params!.docs![i]._id, // needed for mockRawDocExistsInNamespaces mock implementation and existingDocument assertions
_index: 'doesnt-matter',
_source: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal';
import {
type ISavedObjectTypeRegistry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import pMap from 'p-map';
import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import intersection from 'lodash/intersection';

import type { Logger } from '@kbn/logging';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
mockGetSearchDsl,
} from '../repository.test.mock';

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';

import { SavedObjectsRepository } from '../repository';
import { loggerMock } from '@kbn/logging-mocks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import { mockGetCurrentTime, mockPreflightCheckForCreate } from '../repository.test.mock';

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import {
type SavedObjectUnsanitizedDoc,
type SavedObjectReference,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';

/**
* Type and type guard function for converting a possibly not existent doc to an existent doc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import type { Payload } from '@hapi/boom';
import {
SavedObjectsErrorHelpers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import type { Logger } from '@kbn/logging';
import type {
SavedObjectsFindOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
mockGetSearchDsl,
} from './repository.test.mock';

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';

import { SavedObjectsRepository } from './repository';
import { loggerMock } from '@kbn/logging-mocks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {

import { SavedObjectsRepository } from './repository';
import { loggerMock } from '@kbn/logging-mocks';
import { estypes } from '@elastic/elasticsearch';
import type { estypes } from '@elastic/elasticsearch';
import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { SavedObjectsBulkUpdateObject } from '@kbn/core-saved-objects-api-server';
import { SavedObjectsSerializer } from '@kbn/core-saved-objects-base-server-internal';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
mockDeleteLegacyUrlAliases,
} from './repository.test.mock';

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';

import { SavedObjectsRepository } from './repository';
import { loggerMock } from '@kbn/logging-mocks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import { validateAndConvertAggregations } from './validation';

type AggsMap = Record<string, estypes.AggregationsAggregationContainer>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import { ObjectType } from '@kbn/config-schema';
import { isPlainObject, isArray } from 'lodash';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import Boom from '@hapi/boom';

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import type { SavedObjectsPitParams } from '@kbn/core-saved-objects-api-server';
import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server';
import type { IndexMapping } from '@kbn/core-saved-objects-base-server-internal';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import { schema } from '@kbn/config-schema';
import { loggerMock } from '@kbn/logging-mocks';
import type { Payload } from 'elastic-apm-node';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import { errors as esErrors } from '@elastic/elasticsearch';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export const closePit =
({ client, pitId }: ClosePitParams): TaskEither.TaskEither<RetryableEsClientError, {}> =>
() => {
return client
.closePointInTime({
body: { id: pitId },
})
.closePointInTime({ id: pitId })
.then((response) => {
if (!response.succeeded) {
throw new Error(`Failed to close PointInTime with id: ${pitId}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
import { pipe } from 'fp-ts/lib/function';
import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { estypes } from '@elastic/elasticsearch';
import type {
ElasticsearchClient,
ElasticsearchCapabilities,
Expand Down
Loading

0 comments on commit 52ab19d

Please sign in to comment.