Skip to content

Commit 52ab19d

Browse files
afharoMadameSheema
andauthored
Upgrade ES client to 9.0.0-alpha.3 (#208776)
## Summary Updating the ES client to 9.0. Resolves #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]>
1 parent 3492f12 commit 52ab19d

File tree

1,907 files changed

+26727
-29371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,907 files changed

+26727
-29371
lines changed

examples/eso_model_version_example/server/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export class EsoModelVersionExample
330330
const objectsCreated = await Promise.all(
331331
documentVersionConstants.map(async (obj) => {
332332
const createdDoc: WriteResponseBase =
333-
await elasticsearch.client.asInternalUser.create(obj);
333+
await elasticsearch.client.asInternalUser.create<unknown>(obj);
334334
const parts = createdDoc._id.split(':', 2);
335335
return { type: parts[0], id: parts[1] };
336336
})

examples/search_examples/public/search/app.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,15 @@ export const SearchExamplesApp = ({
181181
const aggs = [{ type: metricAggType, params: { field: selectedNumericField!.name } }];
182182
const aggsDsl = data.search.aggs.createAggConfigs(dataView, aggs).toDsl();
183183

184+
const body = {
185+
aggs: aggsDsl,
186+
query,
187+
};
188+
184189
const req = {
185190
params: {
186191
index: dataView.title,
187-
body: {
188-
aggs: aggsDsl,
189-
query,
190-
},
192+
...body,
191193
},
192194
// Add a custom request parameter to be consumed by `MyStrategy`.
193195
...(strategy ? { get_cool: getCool } : {}),
@@ -197,7 +199,7 @@ export const SearchExamplesApp = ({
197199
setAbortController(abortController);
198200

199201
// Submit the search request using the `data.search` service.
200-
setRequest(req.params.body);
202+
setRequest(body);
201203
setRawResponse({});
202204
setWarningContents([]);
203205
setIsLoading(true);

examples/search_examples/public/search_sessions/app.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,8 @@ function doSearch(
707707
const req = {
708708
params: {
709709
index: dataView.title,
710-
body: {
711-
aggs: aggsDsl,
712-
query,
713-
},
710+
aggs: aggsDsl,
711+
query,
714712
},
715713
};
716714

examples/search_examples/server/routes/server_search_route.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ export function registerServerSearchRoute(router: IRouter<DataRequestHandlerCont
3939
{
4040
params: {
4141
index,
42-
body: {
43-
aggs: {
44-
'1': {
45-
avg: {
46-
field,
47-
},
42+
aggs: {
43+
'1': {
44+
avg: {
45+
field,
4846
},
4947
},
5048
},

examples/unified_doc_viewer/public/application.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ function UnifiedDocViewerExamplesApp({ data }: { data: DataPublicPluginStart })
4444
.search({
4545
params: {
4646
index: dataView?.getIndexPattern(),
47-
body: {
48-
fields: ['*'],
49-
_source: false,
50-
},
47+
fields: ['*'],
48+
_source: false,
5149
},
5250
})
5351
.toPromise();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
"@elastic/datemath": "5.0.3",
116116
"@elastic/ebt": "^1.1.1",
117117
"@elastic/ecs": "^8.11.5",
118-
"@elastic/elasticsearch": "^8.17.0",
118+
"@elastic/elasticsearch": "9.0.0-alpha.3",
119119
"@elastic/ems-client": "8.6.3",
120120
"@elastic/eui": "99.2.0-borealis.0",
121121
"@elastic/eui-theme-borealis": "0.0.10",

packages/kbn-failed-test-reporter-cli/failed_tests_reporter/report_failures_to_es.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export async function reportFailuresToEs(log: ToolingLog, failures: TestFailure[
3737
password: process.env.TEST_FAILURES_ES_PASSWORD,
3838
},
3939
Connection: HttpConnection,
40+
requestTimeout: 30_000,
4041
});
4142

4243
const body = failures.flatMap((failure) => [

packages/kbn-performance-testing-dataset-extractor/src/es_client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
import { Client } from '@elastic/elasticsearch';
10+
import { Client, HttpConnection } from '@elastic/elasticsearch';
1111
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
1212
import { SearchRequest, MsearchRequestItem } from '@elastic/elasticsearch/lib/api/types';
1313
import { ToolingLog } from '@kbn/tooling-log';
@@ -109,6 +109,8 @@ export class ESClient {
109109
username: options.username,
110110
password: options.password,
111111
},
112+
Connection: HttpConnection,
113+
requestTimeout: 30_000,
112114
});
113115
this.log = log;
114116
}

src/core/packages/elasticsearch/server-internal/src/elasticsearch_service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class ElasticsearchService
116116

117117
this.esNodesCompatibility$ = esNodesCompatibility$;
118118

119-
this.clusterInfo$ = getClusterInfo$(this.client.asInternalUser);
119+
this.clusterInfo$ = getClusterInfo$(this.client.asInternalUser).pipe(takeUntil(this.stop$));
120120
registerAnalyticsContextProvider(deps.analytics, this.clusterInfo$);
121121

122122
return {

src/core/packages/elasticsearch/server-internal/src/is_scripting_enabled.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

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

0 commit comments

Comments
 (0)