Skip to content

Commit f7e9b4c

Browse files
authored
[ES 9.0] Remove body workaround (@elastic/response-ops) (#217216)
1 parent 2231ba6 commit f7e9b4c

File tree

7 files changed

+61
-70
lines changed

7 files changed

+61
-70
lines changed

x-pack/platform/plugins/shared/alerting/server/alerts_service/alerts_service.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -473,14 +473,12 @@ describe('Alerts Service', () => {
473473
expect(clusterClient.indices.putIndexTemplate).toHaveBeenCalledTimes(1);
474474
expect(clusterClient.indices.putIndexTemplate).toHaveBeenCalledWith({
475475
name: existingIndexTemplate.name,
476-
body: {
477-
...existingIndexTemplate.index_template,
478-
template: {
479-
...existingIndexTemplate.index_template.template,
480-
settings: {
481-
...existingIndexTemplate.index_template.template?.settings,
482-
'index.mapping.total_fields.limit': 2500,
483-
},
476+
...existingIndexTemplate.index_template,
477+
template: {
478+
...existingIndexTemplate.index_template.template,
479+
settings: {
480+
...existingIndexTemplate.index_template.template?.settings,
481+
'index.mapping.total_fields.limit': 2500,
484482
},
485483
},
486484
});

x-pack/platform/plugins/shared/alerting/server/alerts_service/lib/create_concrete_write_index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ const updateUnderlyingMapping = async ({
9090

9191
try {
9292
await retryTransientEsErrors(
93-
// @ts-expect-error [email protected] https://github.com/elastic/elasticsearch-js/issues/2584
94-
() => esClient.indices.putMapping({ index, body: simulatedMapping }),
93+
() => esClient.indices.putMapping({ index, ...simulatedMapping }),
9594
{ logger }
9695
);
9796

x-pack/platform/plugins/shared/alerting/server/alerts_service/lib/create_or_update_component_template.test.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,12 @@ describe('createOrUpdateComponentTemplate', () => {
177177
expect(clusterClient.indices.putIndexTemplate).toHaveBeenCalledTimes(1);
178178
expect(clusterClient.indices.putIndexTemplate).toHaveBeenCalledWith({
179179
name: existingIndexTemplate.name,
180-
body: {
181-
...existingIndexTemplate.index_template,
182-
template: {
183-
...existingIndexTemplate.index_template.template,
184-
settings: {
185-
...existingIndexTemplate.index_template.template?.settings,
186-
'index.mapping.total_fields.limit': 2500,
187-
},
180+
...existingIndexTemplate.index_template,
181+
template: {
182+
...existingIndexTemplate.index_template.template,
183+
settings: {
184+
...existingIndexTemplate.index_template.template?.settings,
185+
'index.mapping.total_fields.limit': 2500,
188186
},
189187
},
190188
});
@@ -283,14 +281,12 @@ describe('createOrUpdateComponentTemplate', () => {
283281
expect(clusterClient.indices.putIndexTemplate).toHaveBeenCalledTimes(1);
284282
expect(clusterClient.indices.putIndexTemplate).toHaveBeenCalledWith({
285283
name: existingIndexTemplate.name,
286-
body: {
287-
...existingIndexTemplate.index_template,
288-
template: {
289-
...existingIndexTemplate.index_template.template,
290-
settings: {
291-
...existingIndexTemplate.index_template.template?.settings,
292-
'index.mapping.total_fields.limit': 2500,
293-
},
284+
...existingIndexTemplate.index_template,
285+
template: {
286+
...existingIndexTemplate.index_template.template,
287+
settings: {
288+
...existingIndexTemplate.index_template.template?.settings,
289+
'index.mapping.total_fields.limit': 2500,
294290
},
295291
},
296292
});

x-pack/platform/plugins/shared/alerting/server/alerts_service/lib/create_or_update_component_template.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,19 @@ const getIndexTemplatesUsingComponentTemplate = async (
5050
() =>
5151
esClient.indices.putIndexTemplate({
5252
name: template.name,
53-
body: {
54-
...template.index_template,
55-
// @ts-expect-error [email protected] https://github.com/elastic/elasticsearch-js/issues/2584
56-
template: {
57-
...template.index_template.template,
58-
settings: {
59-
...template.index_template.template?.settings,
60-
'index.mapping.total_fields.limit': totalFieldsLimit,
61-
},
53+
...template.index_template,
54+
template: {
55+
...template.index_template.template,
56+
settings: {
57+
...template.index_template.template?.settings,
58+
'index.mapping.total_fields.limit': totalFieldsLimit,
6259
},
6360
},
61+
// GET brings string | string[] | undefined but this PUT expects string[]
62+
ignore_missing_component_templates: template.index_template
63+
.ignore_missing_component_templates
64+
? [template.index_template.ignore_missing_component_templates].flat()
65+
: undefined,
6466
}),
6567
{ logger }
6668
);

x-pack/platform/plugins/shared/event_log/server/es/cluster_client_adapter.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,11 @@ describe('setLegacyIndexTemplateToHidden', () => {
379379
await clusterClientAdapter.setLegacyIndexTemplateToHidden('foo-bar-template', currentTemplate);
380380
expect(clusterClient.indices.putTemplate).toHaveBeenCalledWith({
381381
name: 'foo-bar-template',
382-
body: {
383-
order: 0,
384-
index_patterns: ['foo-bar-*'],
385-
settings: { index: { number_of_shards: '1' }, 'index.hidden': true },
386-
mappings: { dynamic: false, properties: {} },
387-
aliases: {},
388-
},
382+
order: 0,
383+
index_patterns: ['foo-bar-*'],
384+
settings: { index: { number_of_shards: '1' }, 'index.hidden': true },
385+
mappings: { dynamic: false, properties: {} },
386+
aliases: {},
389387
});
390388
});
391389

@@ -659,7 +657,8 @@ describe('updateConcreteIndices', () => {
659657
});
660658
expect(clusterClient.indices.putMapping).toHaveBeenCalledWith({
661659
index: 'foo',
662-
body: { dynamic: false, properties: { '@timestamp': { type: 'date' } } },
660+
dynamic: false,
661+
properties: { '@timestamp': { type: 'date' } },
663662
});
664663
});
665664

@@ -720,7 +719,8 @@ describe('updateConcreteIndices', () => {
720719

721720
expect(clusterClient.indices.putMapping).toHaveBeenCalledWith({
722721
index: 'foo',
723-
body: { dynamic: false, properties: { '@timestamp': { type: 'date' } } },
722+
dynamic: false,
723+
properties: { '@timestamp': { type: 'date' } },
724724
});
725725
expect(logger.error).toHaveBeenCalledWith(
726726
`Error updating index mappings for foo: failed to put mappings`

x-pack/platform/plugins/shared/event_log/server/es/cluster_client_adapter.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,10 @@ export class ClusterClientAdapter<
339339
const esClient = await this.elasticsearchClientPromise;
340340
await esClient.indices.putTemplate({
341341
name: indexTemplateName,
342-
body: {
343-
...currentIndexTemplate,
344-
// @ts-expect-error [email protected] https://github.com/elastic/elasticsearch-js/issues/2584
345-
settings: {
346-
...currentIndexTemplate.settings,
347-
'index.hidden': true,
348-
},
342+
...currentIndexTemplate,
343+
settings: {
344+
...currentIndexTemplate.settings,
345+
'index.hidden': true,
349346
},
350347
});
351348
} catch (err) {
@@ -461,8 +458,7 @@ export class ClusterClientAdapter<
461458
const simulatedMapping = get(simulatedIndexMapping, ['template', 'mappings']);
462459

463460
if (simulatedMapping != null) {
464-
// @ts-expect-error [email protected] https://github.com/elastic/elasticsearch-js/issues/2584
465-
await esClient.indices.putMapping({ index: name, body: simulatedMapping });
461+
await esClient.indices.putMapping({ index: name, ...simulatedMapping });
466462
this.logger.debug(`Successfully updated concrete index mappings for ${name}`);
467463
}
468464
} catch (err) {

x-pack/platform/plugins/shared/task_manager/server/task_store.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -902,24 +902,24 @@ export class TaskStore {
902902
{ max_docs: max_docs }: UpdateByQueryOpts = {}
903903
): Promise<UpdateByQueryResult> {
904904
const { query } = ensureQueryOnlyReturnsTaskObjects(opts);
905+
const { sort, ...rest } = opts;
905906
try {
906-
const // @ts-expect-error [email protected] https://github.com/elastic/elasticsearch-js/issues/2584 types complain because the body should not be there.
907-
// However, we can't use this API without the body because it fails to claim the tasks.
908-
// eslint-disable-next-line @typescript-eslint/naming-convention
909-
{ total, updated, version_conflicts } = await this.esClientWithoutRetries.updateByQuery(
910-
{
911-
index: this.index,
912-
ignore_unavailable: true,
913-
refresh: true,
914-
conflicts: 'proceed',
915-
body: {
916-
...opts,
917-
max_docs,
918-
query,
919-
},
920-
},
921-
{ requestTimeout: this.requestTimeouts.update_by_query }
922-
);
907+
// eslint-disable-next-line @typescript-eslint/naming-convention
908+
const { total, updated, version_conflicts } = await this.esClientWithoutRetries.updateByQuery(
909+
{
910+
index: this.index,
911+
ignore_unavailable: true,
912+
refresh: true,
913+
conflicts: 'proceed',
914+
...rest,
915+
max_docs,
916+
query,
917+
// @ts-expect-error According to the docs, sort should be a comma-separated list of fields and goes in the querystring.
918+
// However, this one is using a "body" format?
919+
body: { sort },
920+
},
921+
{ requestTimeout: this.requestTimeouts.update_by_query }
922+
);
923923

924924
const conflictsCorrectedForContinuation = correctVersionConflictsForContinuation(
925925
updated,

0 commit comments

Comments
 (0)