Skip to content

Commit d7ef161

Browse files
authored
[ES body removal] @elastic/fleet (#204867)
## Summary Attempt to remove the deprecated `body` in the ES client.
1 parent a0ebb1d commit d7ef161

File tree

24 files changed

+98
-110
lines changed

24 files changed

+98
-110
lines changed

x-pack/plugins/fleet/common/types/models/agent_policy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import type { SecurityRoleDescriptor } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
8+
import type { SecurityRoleDescriptor } from '@elastic/elasticsearch/lib/api/types';
99

1010
import type { agentPolicyStatuses } from '../../constants';
1111
import type { MonitoringType, PolicySecretReference, ValueOf } from '..';

x-pack/plugins/fleet/common/types/models/epm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
8+
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
99

1010
import type {
1111
ASSETS_SAVED_OBJECT_TYPE,

x-pack/plugins/fleet/server/routes/data_streams/handlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { Dictionary } from 'lodash';
88
import { keyBy, keys, merge } from 'lodash';
99
import type { RequestHandler } from '@kbn/core/server';
1010
import pMap from 'p-map';
11-
import type { IndicesDataStreamsStatsDataStreamsStatsItem } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
11+
import type { IndicesDataStreamsStatsDataStreamsStatsItem } from '@elastic/elasticsearch/lib/api/types';
1212
import { ByteSizeValue } from '@kbn/config-schema';
1313

1414
import type { DataStream } from '../../types';

x-pack/plugins/fleet/server/services/agent_policies/package_policies_to_agent_permissions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import type {
99
SecurityIndicesPrivileges,
1010
SecurityRoleDescriptor,
11-
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
11+
} from '@elastic/elasticsearch/lib/api/types';
1212

1313
import {
1414
FLEET_APM_PACKAGE,

x-pack/plugins/fleet/server/services/agent_policy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type {
2222
} from '@kbn/core/server';
2323
import { SavedObjectsUtils } from '@kbn/core/server';
2424

25-
import type { BulkResponseItem } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
25+
import type { BulkResponseItem } from '@elastic/elasticsearch/lib/api/types';
2626

2727
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common/constants';
2828

x-pack/plugins/fleet/server/services/agents/action.mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export function createClientMock() {
152152

153153
esClientMock.mget.mockResponseImplementation((params) => {
154154
// @ts-expect-error
155-
const docs = params?.body.docs.map(({ _id }) => {
155+
const docs = params?.docs.map(({ _id }) => {
156156
let result;
157157
switch (_id) {
158158
case agentInHostedDoc._id:

x-pack/plugins/fleet/server/services/agents/actions.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('Agent actions', () => {
135135

136136
expect(esClient.create).toBeCalledWith(
137137
expect.objectContaining({
138-
body: expect.objectContaining({
138+
document: expect.objectContaining({
139139
signed: {
140140
data: expect.any(String),
141141
signature: expect.any(String),
@@ -180,7 +180,7 @@ describe('Agent actions', () => {
180180

181181
expect(esClient.create).toBeCalledWith(
182182
expect.objectContaining({
183-
body: expect.not.objectContaining({
183+
document: expect.not.objectContaining({
184184
signed: expect.any(Object),
185185
}),
186186
})
@@ -235,7 +235,7 @@ describe('Agent actions', () => {
235235
await bulkCreateAgentActions(esClient, newActions);
236236
expect(esClient.bulk).toHaveBeenCalledWith(
237237
expect.objectContaining({
238-
body: expect.arrayContaining([
238+
operations: expect.arrayContaining([
239239
expect.arrayContaining([
240240
expect.objectContaining({
241241
signed: {
@@ -274,7 +274,7 @@ describe('Agent actions', () => {
274274
await bulkCreateAgentActions(esClient, newActions);
275275
expect(esClient.bulk).toHaveBeenCalledWith(
276276
expect.objectContaining({
277-
body: expect.arrayContaining([
277+
operations: expect.arrayContaining([
278278
expect.arrayContaining([
279279
expect.not.objectContaining({
280280
signed: {
@@ -350,7 +350,7 @@ describe('Agent actions', () => {
350350
expect(esClient.create).toBeCalledTimes(2);
351351
expect(esClient.create).toBeCalledWith(
352352
expect.objectContaining({
353-
body: expect.objectContaining({
353+
document: expect.objectContaining({
354354
type: 'CANCEL',
355355
data: { target_id: 'action1' },
356356
agents: ['agent1', 'agent2'],
@@ -359,7 +359,7 @@ describe('Agent actions', () => {
359359
);
360360
expect(esClient.create).toBeCalledWith(
361361
expect.objectContaining({
362-
body: expect.objectContaining({
362+
document: expect.objectContaining({
363363
type: 'CANCEL',
364364
data: { target_id: 'action1' },
365365
agents: ['agent3', 'agent4'],

x-pack/plugins/fleet/server/services/agents/actions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export async function createAgentAction(
8181
await esClient.create({
8282
index: AGENT_ACTIONS_INDEX,
8383
id: uuidv4(),
84-
body,
84+
document: body,
8585
refresh: 'wait_for',
8686
});
8787

@@ -153,7 +153,7 @@ export async function bulkCreateAgentActions(
153153

154154
await esClient.bulk({
155155
index: AGENT_ACTIONS_INDEX,
156-
body: fleetServerAgentActions,
156+
operations: fleetServerAgentActions,
157157
});
158158

159159
for (const action of actions) {
@@ -231,7 +231,7 @@ export async function bulkCreateAgentActionResults(
231231

232232
await esClient.bulk({
233233
index: AGENT_ACTIONS_RESULTS_INDEX,
234-
body: bulkBody,
234+
operations: bulkBody,
235235
refresh: 'wait_for',
236236
});
237237
}

x-pack/plugins/fleet/server/services/agents/agent_service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import type {
1313
SavedObjectsClientContract,
1414
} from '@kbn/core/server';
1515

16-
import type { AggregationsAggregationContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
16+
import type { AggregationsAggregationContainer } from '@elastic/elasticsearch/lib/api/types';
1717

18-
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
18+
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
1919

2020
import type { SortResults } from '@elastic/elasticsearch/lib/api/types';
2121

x-pack/plugins/fleet/server/services/agents/crud.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ describe('Agents CRUD test', () => {
107107
expect(searchMock).toHaveBeenCalledWith(
108108
expect.objectContaining({
109109
aggs: { tags: { terms: { field: 'tags', size: 10000 } } },
110-
body: {
111-
query: expect.any(Object),
112-
},
110+
query: expect.any(Object),
113111
index: '.fleet-agents',
114112
size: 0,
115113
fields: ['status'],
@@ -164,7 +162,7 @@ describe('Agents CRUD test', () => {
164162
})
165163
);
166164

167-
expect(searchMock.mock.calls.at(-1)[0].body.query).toEqual(
165+
expect(searchMock.mock.calls.at(-1)[0].query).toEqual(
168166
toElasticsearchQuery(
169167
_joinFilters(['fleet-agents.policy_id: 123', 'NOT status:unenrolled'])!
170168
)

0 commit comments

Comments
 (0)