mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[ES body
removal] @elastic/kibana-core
(#204851)
This commit is contained in:
parent
5be981535b
commit
2cd882c50d
84 changed files with 472 additions and 534 deletions
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
import { isRetryableEsClientErrorMock } from './is_scripting_enabled.test.mocks';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
|
||||
import { isInlineScriptingEnabled } from './is_scripting_enabled';
|
||||
|
||||
|
|
|
@ -168,9 +168,9 @@ describe('#bulkCreate', () => {
|
|||
getId = () => expect.any(String),
|
||||
}: { method: string; _index?: string; getId?: (type: string, id?: string) => string }
|
||||
) => {
|
||||
const body = [];
|
||||
const operations = [];
|
||||
for (const { type, id, if_primary_term: ifPrimaryTerm, if_seq_no: ifSeqNo } of objects) {
|
||||
body.push({
|
||||
operations.push({
|
||||
[method]: {
|
||||
_index,
|
||||
_id: getId(type, id),
|
||||
|
@ -179,10 +179,10 @@ describe('#bulkCreate', () => {
|
|||
: {}),
|
||||
},
|
||||
});
|
||||
body.push(expect.any(Object));
|
||||
operations.push(expect.any(Object));
|
||||
}
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
};
|
||||
|
@ -290,9 +290,9 @@ describe('#bulkCreate', () => {
|
|||
|
||||
it(`formats the ES request`, async () => {
|
||||
await bulkCreateSuccess(client, repository, [obj1, obj2]);
|
||||
const body = [...expectObjArgs(obj1), ...expectObjArgs(obj2)];
|
||||
const operations = [...expectObjArgs(obj1), ...expectObjArgs(obj2)];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -301,9 +301,12 @@ describe('#bulkCreate', () => {
|
|||
const obj1WithManagedTrue = { ...obj1, managed: true };
|
||||
const obj2WithManagedTrue = { ...obj2, managed: true };
|
||||
await bulkCreateSuccess(client, repository, [obj1WithManagedTrue, obj2WithManagedTrue]);
|
||||
const body = [...expectObjArgs(obj1WithManagedTrue), ...expectObjArgs(obj2WithManagedTrue)];
|
||||
const operations = [
|
||||
...expectObjArgs(obj1WithManagedTrue),
|
||||
...expectObjArgs(obj2WithManagedTrue),
|
||||
];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -333,9 +336,9 @@ describe('#bulkCreate', () => {
|
|||
|
||||
await bulkCreateSuccess(client, repository, objects);
|
||||
const expected = expect.not.objectContaining({ originId: expect.anything() });
|
||||
const body = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
const operations = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -360,9 +363,9 @@ describe('#bulkCreate', () => {
|
|||
];
|
||||
await bulkCreateSuccess(client, repository, objects);
|
||||
const expected = expect.objectContaining({ originId: 'some-originId' });
|
||||
const body = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
const operations = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -375,9 +378,9 @@ describe('#bulkCreate', () => {
|
|||
];
|
||||
await bulkCreateSuccess(client, repository, objects);
|
||||
const expected = expect.not.objectContaining({ originId: expect.anything() });
|
||||
const body = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
const operations = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -389,9 +392,9 @@ describe('#bulkCreate', () => {
|
|||
];
|
||||
await bulkCreateSuccess(client, repository, objects);
|
||||
const expected = expect.objectContaining({ originId: 'existing-originId' });
|
||||
const body = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
const operations = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -401,9 +404,9 @@ describe('#bulkCreate', () => {
|
|||
it(`adds namespace to request body for any types that are single-namespace`, async () => {
|
||||
await bulkCreateSuccess(client, repository, [obj1, obj2], { namespace });
|
||||
const expected = expect.objectContaining({ namespace });
|
||||
const body = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
const operations = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -412,9 +415,9 @@ describe('#bulkCreate', () => {
|
|||
it(`adds managed=false to request body if declared for any types that are single-namespace`, async () => {
|
||||
await bulkCreateSuccess(client, repository, [obj1, obj2], { namespace, managed: false });
|
||||
const expected = expect.objectContaining({ namespace, managed: false });
|
||||
const body = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
const operations = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -422,9 +425,9 @@ describe('#bulkCreate', () => {
|
|||
it(`adds managed=true to request body if declared for any types that are single-namespace`, async () => {
|
||||
await bulkCreateSuccess(client, repository, [obj1, obj2], { namespace, managed: true });
|
||||
const expected = expect.objectContaining({ namespace, managed: true });
|
||||
const body = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
const operations = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -432,9 +435,9 @@ describe('#bulkCreate', () => {
|
|||
it(`normalizes options.namespace from 'default' to undefined`, async () => {
|
||||
await bulkCreateSuccess(client, repository, [obj1, obj2], { namespace: 'default' });
|
||||
const expected = expect.not.objectContaining({ namespace: 'default' });
|
||||
const body = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
const operations = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -446,9 +449,9 @@ describe('#bulkCreate', () => {
|
|||
];
|
||||
await bulkCreateSuccess(client, repository, objects, { namespace });
|
||||
const expected = expect.not.objectContaining({ namespace: expect.anything() });
|
||||
const body = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
const operations = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -468,9 +471,9 @@ describe('#bulkCreate', () => {
|
|||
await bulkCreateSuccess(client, repository, objects, { namespace, overwrite: true });
|
||||
const expected1 = expect.objectContaining({ namespaces: [namespace ?? 'default'] });
|
||||
const expected2 = expect.objectContaining({ namespaces: ['*'] });
|
||||
const body = [expect.any(Object), expected1, expect.any(Object), expected2];
|
||||
const operations = [expect.any(Object), expected1, expect.any(Object), expected2];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
client.bulk.mockClear();
|
||||
|
@ -503,7 +506,7 @@ describe('#bulkCreate', () => {
|
|||
},
|
||||
]);
|
||||
await bulkCreateSuccess(client, repository, objects, { namespace, overwrite: true });
|
||||
const body = [
|
||||
const operations = [
|
||||
{ index: expect.objectContaining({ _id: `${ns2}:dashboard:${o1.id}` }) },
|
||||
expect.objectContaining({ namespace: ns2 }),
|
||||
{
|
||||
|
@ -525,7 +528,7 @@ describe('#bulkCreate', () => {
|
|||
})
|
||||
);
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
client.bulk.mockClear();
|
||||
|
@ -539,12 +542,12 @@ describe('#bulkCreate', () => {
|
|||
const test = async (namespace?: string) => {
|
||||
const objects = [{ ...obj1, type: 'dashboard', initialNamespaces: ['default'] }];
|
||||
await bulkCreateSuccess(client, repository, objects, { namespace, overwrite: true });
|
||||
const body = [
|
||||
const operations = [
|
||||
{ index: expect.objectContaining({ _id: `dashboard:${obj1.id}` }) },
|
||||
expect.not.objectContaining({ namespace: 'default' }),
|
||||
];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
client.bulk.mockClear();
|
||||
|
@ -558,9 +561,9 @@ describe('#bulkCreate', () => {
|
|||
const objects = [obj1, { ...obj2, type: NAMESPACE_AGNOSTIC_TYPE }];
|
||||
await bulkCreateSuccess(client, repository, objects, { namespace, overwrite: true });
|
||||
const expected = expect.not.objectContaining({ namespaces: expect.anything() });
|
||||
const body = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
const operations = [expect.any(Object), expected, expect.any(Object), expected];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
client.bulk.mockClear();
|
||||
|
@ -652,9 +655,9 @@ describe('#bulkCreate', () => {
|
|||
const result = await repository.bulkCreate(objects);
|
||||
expect(client.bulk).toHaveBeenCalled();
|
||||
const objCall = isBulkError ? expectObjArgs(obj) : [];
|
||||
const body = [...expectObjArgs(obj1), ...objCall, ...expectObjArgs(obj2)];
|
||||
const operations = [...expectObjArgs(obj1), ...objCall, ...expectObjArgs(obj2)];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
expect(result).toEqual({
|
||||
|
@ -765,7 +768,7 @@ describe('#bulkCreate', () => {
|
|||
);
|
||||
expect(client.bulk).toHaveBeenCalled();
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body: [...expectObjArgs(o1), ...expectObjArgs(o5)] }),
|
||||
expect.objectContaining({ operations: [...expectObjArgs(o1), ...expectObjArgs(o5)] }),
|
||||
expect.anything()
|
||||
);
|
||||
expect(result).toEqual({
|
||||
|
|
|
@ -282,7 +282,7 @@ export const performBulkCreate = async <T>(
|
|||
? await client.bulk({
|
||||
refresh,
|
||||
require_alias: true,
|
||||
body: bulkCreateParams,
|
||||
operations: bulkCreateParams,
|
||||
})
|
||||
: undefined;
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ import {
|
|||
} from '../repository.test.mock';
|
||||
|
||||
import type { Payload } from '@hapi/boom';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import type {
|
||||
SavedObjectsBulkDeleteObject,
|
||||
|
@ -131,9 +131,9 @@ describe('#bulkDelete', () => {
|
|||
overrides?: Record<string, unknown>;
|
||||
}
|
||||
) => {
|
||||
const body = [];
|
||||
const operations = [];
|
||||
for (const { type, id } of objects) {
|
||||
body.push({
|
||||
operations.push({
|
||||
[method]: {
|
||||
_index,
|
||||
_id: getId(type, id),
|
||||
|
@ -143,7 +143,7 @@ describe('#bulkDelete', () => {
|
|||
}
|
||||
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
};
|
||||
|
@ -202,9 +202,9 @@ describe('#bulkDelete', () => {
|
|||
overrides?: Record<string, unknown>;
|
||||
}
|
||||
) => {
|
||||
const body = [];
|
||||
const operations = [];
|
||||
for (const { type, id } of objects) {
|
||||
body.push({
|
||||
operations.push({
|
||||
[method]: {
|
||||
_index,
|
||||
_id: getId(type, id),
|
||||
|
@ -213,7 +213,7 @@ describe('#bulkDelete', () => {
|
|||
});
|
||||
}
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
};
|
||||
|
@ -266,7 +266,7 @@ describe('#bulkDelete', () => {
|
|||
expect.objectContaining({ _id: `${MULTI_NAMESPACE_ISOLATED_TYPE}:${obj2.id}` }),
|
||||
];
|
||||
expect(client.mget).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body: { docs } }),
|
||||
expect.objectContaining({ docs }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
|
|
@ -141,7 +141,7 @@ export const performBulkDelete = async <T>(
|
|||
const bulkDeleteResponse = bulkDeleteParams.length
|
||||
? await client.bulk({
|
||||
refresh,
|
||||
body: bulkDeleteParams,
|
||||
operations: bulkDeleteParams,
|
||||
require_alias: true,
|
||||
})
|
||||
: undefined;
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
getSavedObjectFromSourceMock,
|
||||
rawDocExistsInNamespaceMock,
|
||||
} from './bulk_get.isolated.test.mocks';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { SavedObject, CheckAuthorizationResult } from '@kbn/core-saved-objects-server';
|
||||
import { apiContextMock, ApiExecutionContextMock } from '../../mocks';
|
||||
import { performBulkGet } from './bulk_get';
|
||||
|
|
|
@ -15,7 +15,7 @@ import {
|
|||
} from '../repository.test.mock';
|
||||
|
||||
import type { Payload } from '@hapi/boom';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import type { SavedObjectsBulkGetObject } from '@kbn/core-saved-objects-api-server';
|
||||
import { type SavedObjectsRawDocSource, type SavedObject } from '@kbn/core-saved-objects-server';
|
||||
|
@ -149,14 +149,12 @@ describe('#bulkGet', () => {
|
|||
) => {
|
||||
expect(client.mget).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: {
|
||||
docs: objects.map(({ type, id }) =>
|
||||
expect.objectContaining({
|
||||
_index,
|
||||
_id: getId(type, id),
|
||||
})
|
||||
),
|
||||
},
|
||||
docs: objects.map(({ type, id }) =>
|
||||
expect.objectContaining({
|
||||
_index,
|
||||
_id: getId(type, id),
|
||||
})
|
||||
),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
|
|
@ -134,11 +134,7 @@ export const performBulkGet = async <T>(
|
|||
}));
|
||||
const bulkGetResponse = bulkGetDocs.length
|
||||
? await client.mget<SavedObjectsRawDocSource>(
|
||||
{
|
||||
body: {
|
||||
docs: bulkGetDocs,
|
||||
},
|
||||
},
|
||||
{ docs: bulkGetDocs },
|
||||
{ ignore: [404], meta: true }
|
||||
)
|
||||
: undefined;
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
} from '../repository.test.mock';
|
||||
|
||||
import type { Payload } from '@hapi/boom';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import type {
|
||||
SavedObjectsBulkUpdateObject,
|
||||
|
@ -164,13 +164,13 @@ describe('#bulkUpdate', () => {
|
|||
overrides?: Record<string, unknown>;
|
||||
}
|
||||
) => {
|
||||
const body = [];
|
||||
const operations = [];
|
||||
for (const object of objects) {
|
||||
body.push(getBulkIndexEntry(method, object, _index, getId, overrides));
|
||||
body.push(expect.any(Object));
|
||||
operations.push(getBulkIndexEntry(method, object, _index, getId, overrides));
|
||||
operations.push(expect.any(Object));
|
||||
}
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
};
|
||||
|
@ -214,7 +214,7 @@ describe('#bulkUpdate', () => {
|
|||
expect.objectContaining({ _id: `${MULTI_NAMESPACE_ISOLATED_TYPE}:${obj2.id}` }),
|
||||
];
|
||||
expect(client.mget).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body: { docs } }),
|
||||
expect.objectContaining({ docs }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -239,7 +239,7 @@ describe('#bulkUpdate', () => {
|
|||
expect(client.bulk).toHaveBeenCalledTimes(1);
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: [
|
||||
operations: [
|
||||
getBulkIndexEntry('index', _obj1),
|
||||
expect.objectContaining({
|
||||
[obj1.type]: {
|
||||
|
@ -267,7 +267,7 @@ describe('#bulkUpdate', () => {
|
|||
expect(client.bulk).toHaveBeenCalledTimes(1);
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: [
|
||||
operations: [
|
||||
getBulkIndexEntry('index', _obj1),
|
||||
expect.objectContaining({
|
||||
[obj1.type]: {
|
||||
|
@ -288,12 +288,12 @@ describe('#bulkUpdate', () => {
|
|||
|
||||
it(`defaults to no references`, async () => {
|
||||
await bulkUpdateSuccess(client, repository, registry, [obj1, obj2]);
|
||||
const body = [
|
||||
const operations = [
|
||||
...expectObjArgs({ ...obj1, references: [] }),
|
||||
...expectObjArgs({ ...obj2, references: [] }),
|
||||
];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -302,12 +302,12 @@ describe('#bulkUpdate', () => {
|
|||
const test = async (references: SavedObjectReference[]) => {
|
||||
const objects = [obj1, obj2].map((obj) => ({ ...obj, references }));
|
||||
await bulkUpdateSuccess(client, repository, registry, objects);
|
||||
const body = [
|
||||
const operations = [
|
||||
...expectObjArgs({ ...obj1, references }),
|
||||
...expectObjArgs({ ...obj2, references }),
|
||||
];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
client.bulk.mockClear();
|
||||
|
@ -322,12 +322,12 @@ describe('#bulkUpdate', () => {
|
|||
const test = async (references: unknown) => {
|
||||
const objects = [obj1, obj2];
|
||||
await bulkUpdateSuccess(client, repository, registry, objects);
|
||||
const body = [
|
||||
const operations = [
|
||||
...expectObjArgs({ ...obj1, references: expect.not.arrayContaining([references]) }),
|
||||
...expectObjArgs({ ...obj2, references: expect.not.arrayContaining([references]) }),
|
||||
];
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ body }),
|
||||
expect.objectContaining({ operations }),
|
||||
expect.anything()
|
||||
);
|
||||
client.bulk.mockClear();
|
||||
|
|
|
@ -168,7 +168,7 @@ export const performBulkUpdate = async <T>(
|
|||
|
||||
const bulkGetResponse = bulkGetDocs.length
|
||||
? await client.mget<SavedObjectsRawDocSource>(
|
||||
{ body: { docs: bulkGetDocs } },
|
||||
{ docs: bulkGetDocs },
|
||||
{ ignore: [404], meta: true }
|
||||
)
|
||||
: undefined;
|
||||
|
@ -344,7 +344,7 @@ export const performBulkUpdate = async <T>(
|
|||
const bulkUpdateResponse = bulkUpdateParams.length
|
||||
? await client.bulk({
|
||||
refresh,
|
||||
body: bulkUpdateParams,
|
||||
operations: bulkUpdateParams,
|
||||
_source_includes: ['originId'],
|
||||
require_alias: true,
|
||||
})
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
mockGetSearchDsl,
|
||||
} from '../repository.test.mock';
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import { ALL_NAMESPACES_STRING } from '@kbn/core-saved-objects-utils-server';
|
||||
import { SavedObjectsRepository } from '../repository';
|
||||
|
@ -100,14 +100,12 @@ describe('#checkConflicts', () => {
|
|||
) => {
|
||||
expect(client.mget).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: {
|
||||
docs: objects.map(({ type, id }) =>
|
||||
expect.objectContaining({
|
||||
_index,
|
||||
_id: getId(type, id),
|
||||
})
|
||||
),
|
||||
},
|
||||
docs: objects.map(({ type, id }) =>
|
||||
expect.objectContaining({
|
||||
_index,
|
||||
_id: getId(type, id),
|
||||
})
|
||||
),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
|
|
@ -85,11 +85,7 @@ export const performCheckConflicts = async <T>(
|
|||
}));
|
||||
const bulkGetResponse = bulkGetDocs.length
|
||||
? await client.mget<SavedObjectsRawDocSource>(
|
||||
{
|
||||
body: {
|
||||
docs: bulkGetDocs,
|
||||
},
|
||||
},
|
||||
{ docs: bulkGetDocs },
|
||||
{ ignore: [404], meta: true }
|
||||
)
|
||||
: undefined;
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
mockGetSearchDsl,
|
||||
} from '../repository.test.mock';
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import type { SavedObjectsCreateOptions } from '@kbn/core-saved-objects-api-server';
|
||||
import {
|
||||
|
@ -234,8 +234,8 @@ describe('#create', () => {
|
|||
it(`defaults to empty references array`, async () => {
|
||||
await createSuccess(type, attributes, { id });
|
||||
expect(
|
||||
(client.create.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>).body!
|
||||
.references
|
||||
(client.create.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>)
|
||||
.document!.references
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
|
@ -244,7 +244,7 @@ describe('#create', () => {
|
|||
await createSuccess(type, attributes, { id, references });
|
||||
expect(
|
||||
(client.create.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>)
|
||||
.body!.references
|
||||
.document!.references
|
||||
).toEqual(references);
|
||||
client.create.mockClear();
|
||||
};
|
||||
|
@ -259,7 +259,7 @@ describe('#create', () => {
|
|||
await createSuccess(type, attributes, { id, references });
|
||||
expect(
|
||||
(client.create.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>)
|
||||
.body!.references
|
||||
.document!.references
|
||||
).not.toBeDefined();
|
||||
client.create.mockClear();
|
||||
};
|
||||
|
@ -286,9 +286,7 @@ describe('#create', () => {
|
|||
it(`${objType} defaults to no originId`, async () => {
|
||||
await createSuccess(objType, attributes, { id });
|
||||
expect(client.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.not.objectContaining({ originId: expect.anything() }),
|
||||
}),
|
||||
expect.not.objectContaining({ originId: expect.anything() }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -310,7 +308,7 @@ describe('#create', () => {
|
|||
await createSuccess(objType, attributes, { id, originId: 'some-originId' });
|
||||
expect(client.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({ originId: 'some-originId' }),
|
||||
document: expect.objectContaining({ originId: 'some-originId' }),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
@ -321,7 +319,7 @@ describe('#create', () => {
|
|||
await createSuccess(objType, attributes, { id, originId: undefined });
|
||||
expect(client.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.not.objectContaining({ originId: expect.anything() }),
|
||||
document: expect.not.objectContaining({ originId: expect.anything() }),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
@ -331,7 +329,7 @@ describe('#create', () => {
|
|||
await createSuccess(objType, attributes, { id });
|
||||
expect(client.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({ originId: 'existing-originId' }),
|
||||
document: expect.objectContaining({ originId: 'existing-originId' }),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
@ -388,7 +386,7 @@ describe('#create', () => {
|
|||
expect(client.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
id: `${namespace}:${type}:${id}`,
|
||||
body: expect.objectContaining({ namespace }),
|
||||
document: expect.objectContaining({ namespace }),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
@ -399,7 +397,7 @@ describe('#create', () => {
|
|||
expect(client.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
id: `${type}:${id}`,
|
||||
body: expect.not.objectContaining({ namespace: expect.anything() }),
|
||||
document: expect.not.objectContaining({ namespace: expect.anything() }),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
@ -410,7 +408,7 @@ describe('#create', () => {
|
|||
expect(client.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
id: `${type}:${id}`,
|
||||
body: expect.not.objectContaining({ namespace: expect.anything() }),
|
||||
document: expect.not.objectContaining({ namespace: expect.anything() }),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
@ -457,7 +455,7 @@ describe('#create', () => {
|
|||
expect(client.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
id: `${MULTI_NAMESPACE_TYPE}:${id}`,
|
||||
body: expect.objectContaining({ namespaces: [namespace] }),
|
||||
document: expect.objectContaining({ namespaces: [namespace] }),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
@ -465,7 +463,7 @@ describe('#create', () => {
|
|||
expect(client.index).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
id: `${MULTI_NAMESPACE_ISOLATED_TYPE}:${id}`,
|
||||
body: expect.objectContaining({ namespaces: ['*'] }),
|
||||
document: expect.objectContaining({ namespaces: ['*'] }),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
@ -524,7 +522,7 @@ describe('#create', () => {
|
|||
1,
|
||||
expect.objectContaining({
|
||||
id: `${ns2}:dashboard:${id}`,
|
||||
body: expect.objectContaining({ namespace: ns2 }),
|
||||
document: expect.objectContaining({ namespace: ns2 }),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
@ -532,7 +530,7 @@ describe('#create', () => {
|
|||
2,
|
||||
expect.objectContaining({
|
||||
id: `${MULTI_NAMESPACE_TYPE}:${id}`,
|
||||
body: expect.objectContaining({ namespaces: [ns2, ns3] }),
|
||||
document: expect.objectContaining({ namespaces: [ns2, ns3] }),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
@ -540,7 +538,7 @@ describe('#create', () => {
|
|||
expect(client.index).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
id: `${MULTI_NAMESPACE_ISOLATED_TYPE}:${id}`,
|
||||
body: expect.objectContaining({ namespaces: [ns2] }),
|
||||
document: expect.objectContaining({ namespaces: [ns2] }),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
@ -558,7 +556,7 @@ describe('#create', () => {
|
|||
1,
|
||||
expect.objectContaining({
|
||||
id: `dashboard:${id}`,
|
||||
body: expect.not.objectContaining({ namespace: 'default' }),
|
||||
document: expect.not.objectContaining({ namespace: 'default' }),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
@ -569,7 +567,7 @@ describe('#create', () => {
|
|||
expect(client.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
id: `${NAMESPACE_AGNOSTIC_TYPE}:${id}`,
|
||||
body: expect.not.objectContaining({
|
||||
document: expect.not.objectContaining({
|
||||
namespace: expect.anything(),
|
||||
namespaces: expect.anything(),
|
||||
}),
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
import { SavedObjectsUtils } from '@kbn/core-saved-objects-utils-server';
|
||||
import { decodeRequestVersion } from '@kbn/core-saved-objects-base-server-internal';
|
||||
import { SavedObjectsCreateOptions } from '@kbn/core-saved-objects-api-server';
|
||||
import { CreateRequest, type IndexRequest } from '@elastic/elasticsearch/lib/api/types';
|
||||
import { DEFAULT_REFRESH_SETTING } from '../constants';
|
||||
import type { PreflightCheckForCreateResult } from './internals/preflight_check_for_create';
|
||||
import { getSavedObjectNamespaces, getCurrentTime, normalizeNamespace, setManaged } from './utils';
|
||||
|
@ -152,19 +153,19 @@ export const performCreate = async <T>(
|
|||
|
||||
const raw = serializer.savedObjectToRaw(migrated as SavedObjectSanitizedDoc<T>);
|
||||
|
||||
const requestParams = {
|
||||
const requestParams: IndexRequest | CreateRequest = {
|
||||
id: raw._id,
|
||||
index: commonHelper.getIndexForType(type),
|
||||
refresh,
|
||||
body: raw._source,
|
||||
document: raw._source,
|
||||
...(overwrite && version ? decodeRequestVersion(version) : {}),
|
||||
require_alias: true,
|
||||
};
|
||||
|
||||
const { body, statusCode, headers } =
|
||||
id && overwrite
|
||||
? await client.index(requestParams, { meta: true })
|
||||
: await client.create(requestParams, { meta: true });
|
||||
? await client.index(requestParams as IndexRequest, { meta: true })
|
||||
: await client.create(requestParams as CreateRequest, { meta: true });
|
||||
|
||||
// throw if we can't verify a 404 response is from Elasticsearch
|
||||
if (isNotFoundFromUnsupportedServer({ statusCode, headers })) {
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
mockGetSearchDsl,
|
||||
} from '../repository.test.mock';
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import type { SavedObjectsDeleteOptions } from '@kbn/core-saved-objects-api-server';
|
||||
import { ALL_NAMESPACES_STRING } from '@kbn/core-saved-objects-utils-server';
|
||||
|
|
|
@ -49,28 +49,26 @@ export const performDeleteByNamespace = async <T>(
|
|||
{
|
||||
index: commonHelper.getIndicesForTypes(typesToUpdate),
|
||||
refresh: options.refresh,
|
||||
body: {
|
||||
script: {
|
||||
source: `
|
||||
if (!ctx._source.containsKey('namespaces')) {
|
||||
ctx.op = "delete";
|
||||
} else {
|
||||
ctx._source['namespaces'].removeAll(Collections.singleton(params['namespace']));
|
||||
if (ctx._source['namespaces'].empty) {
|
||||
ctx.op = "delete";
|
||||
}
|
||||
}
|
||||
`,
|
||||
lang: 'painless',
|
||||
params: { namespace },
|
||||
},
|
||||
conflicts: 'proceed',
|
||||
...getSearchDsl(mappings, registry, {
|
||||
namespaces: [namespace],
|
||||
type: typesToUpdate,
|
||||
kueryNode,
|
||||
}),
|
||||
script: {
|
||||
source: `
|
||||
if (!ctx._source.containsKey('namespaces')) {
|
||||
ctx.op = "delete";
|
||||
} else {
|
||||
ctx._source['namespaces'].removeAll(Collections.singleton(params['namespace']));
|
||||
if (ctx._source['namespaces'].empty) {
|
||||
ctx.op = "delete";
|
||||
}
|
||||
}
|
||||
`,
|
||||
lang: 'painless',
|
||||
params: { namespace },
|
||||
},
|
||||
conflicts: 'proceed',
|
||||
...(getSearchDsl(mappings, registry, {
|
||||
namespaces: [namespace],
|
||||
type: typesToUpdate,
|
||||
kueryNode,
|
||||
}) as Omit<ReturnType<typeof getSearchDsl>, 'sort'>), // Sort types don't match and we're not sorting anyways
|
||||
},
|
||||
{ ignore: [404], meta: true }
|
||||
);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
import { isSupportedEsServerMock } from './find.isolated.test.mocks';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { SavedObject, AuthorizationTypeMap } from '@kbn/core-saved-objects-server';
|
||||
import { apiContextMock, ApiExecutionContextMock } from '../../mocks';
|
||||
import { performFind } from './find';
|
||||
|
|
|
@ -106,9 +106,7 @@ describe('find', () => {
|
|||
await findSuccess(client, repository, { type });
|
||||
|
||||
expect(client.search).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({ ...query }),
|
||||
}),
|
||||
expect.objectContaining({ ...query }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -138,24 +136,22 @@ describe('find', () => {
|
|||
await findSuccess(client, repository, { type, fields: ['title'] });
|
||||
expect(client.search).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
_source: [
|
||||
`${type}.title`,
|
||||
'namespace',
|
||||
'namespaces',
|
||||
'type',
|
||||
'references',
|
||||
'migrationVersion',
|
||||
'coreMigrationVersion',
|
||||
'typeMigrationVersion',
|
||||
'managed',
|
||||
'updated_at',
|
||||
'updated_by',
|
||||
'created_at',
|
||||
'created_by',
|
||||
'originId',
|
||||
],
|
||||
}),
|
||||
_source: [
|
||||
`${type}.title`,
|
||||
'namespace',
|
||||
'namespaces',
|
||||
'type',
|
||||
'references',
|
||||
'migrationVersion',
|
||||
'coreMigrationVersion',
|
||||
'typeMigrationVersion',
|
||||
'managed',
|
||||
'updated_at',
|
||||
'updated_by',
|
||||
'created_at',
|
||||
'created_by',
|
||||
'originId',
|
||||
],
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
import Boom from '@hapi/boom';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { isSupportedEsServer } from '@kbn/core-elasticsearch-server-internal';
|
||||
import {
|
||||
SavedObjectsErrorHelpers,
|
||||
|
@ -191,31 +191,26 @@ export const performFind = async <T = unknown, A = unknown>(
|
|||
preference,
|
||||
rest_total_hits_as_int: true,
|
||||
size: perPage,
|
||||
body: {
|
||||
size: perPage,
|
||||
seq_no_primary_term: true,
|
||||
from: perPage * (page - 1),
|
||||
_source: includedFields(allowedTypes, fields),
|
||||
...(aggsObject ? { aggs: aggsObject } : {}),
|
||||
...getSearchDsl(mappings, registry, {
|
||||
search,
|
||||
defaultSearchOperator,
|
||||
searchFields,
|
||||
pit,
|
||||
rootSearchFields,
|
||||
type: allowedTypes,
|
||||
searchAfter,
|
||||
sortField,
|
||||
sortOrder,
|
||||
namespaces,
|
||||
typeToNamespacesMap, // If defined, this takes precedence over the `type` and `namespaces` fields
|
||||
hasReference,
|
||||
hasReferenceOperator,
|
||||
hasNoReference,
|
||||
hasNoReferenceOperator,
|
||||
kueryNode,
|
||||
}),
|
||||
},
|
||||
seq_no_primary_term: true,
|
||||
...(aggsObject ? { aggs: aggsObject } : {}),
|
||||
...getSearchDsl(mappings, registry, {
|
||||
search,
|
||||
defaultSearchOperator,
|
||||
searchFields,
|
||||
pit,
|
||||
rootSearchFields,
|
||||
type: allowedTypes,
|
||||
searchAfter,
|
||||
sortField,
|
||||
sortOrder,
|
||||
namespaces,
|
||||
typeToNamespacesMap, // If defined, this takes precedence over the `type` and `namespaces` fields
|
||||
hasReference,
|
||||
hasReferenceOperator,
|
||||
hasNoReference,
|
||||
hasNoReferenceOperator,
|
||||
kueryNode,
|
||||
}),
|
||||
};
|
||||
|
||||
const { body, statusCode, headers } = await client.search<SavedObjectsRawDocSource>(esOptions, {
|
||||
|
|
|
@ -15,7 +15,7 @@ import {
|
|||
mockGetSearchDsl,
|
||||
} from '../repository.test.mock';
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import type { SavedObjectsBaseOptions } from '@kbn/core-saved-objects-api-server';
|
||||
import { ALL_NAMESPACES_STRING } from '@kbn/core-saved-objects-utils-server';
|
||||
|
|
|
@ -88,10 +88,7 @@ export class PreflightCheckHelper {
|
|||
}));
|
||||
|
||||
const bulkGetMultiNamespaceDocsResponse = bulkGetMultiNamespaceDocs.length
|
||||
? await this.client.mget(
|
||||
{ body: { docs: bulkGetMultiNamespaceDocs } },
|
||||
{ ignore: [404], meta: true }
|
||||
)
|
||||
? await this.client.mget({ docs: bulkGetMultiNamespaceDocs }, { ignore: [404], meta: true })
|
||||
: undefined;
|
||||
// fail fast if we can't verify a 404 response is from Elasticsearch
|
||||
if (
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
mockGetSearchDsl,
|
||||
} from '../repository.test.mock';
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import type {
|
||||
SavedObjectsIncrementCounterField,
|
||||
|
@ -222,19 +222,17 @@ describe('#incrementCounter', () => {
|
|||
await incrementCounterSuccess(type, id, counterFields, { namespace, upsertAttributes });
|
||||
expect(client.update).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
upsert: expect.objectContaining({
|
||||
[type]: {
|
||||
foo: 'bar',
|
||||
hello: 'dolly',
|
||||
...counterFields.reduce((aggs, field) => {
|
||||
return {
|
||||
...aggs,
|
||||
[field]: 1,
|
||||
};
|
||||
}, {}),
|
||||
},
|
||||
}),
|
||||
upsert: expect.objectContaining({
|
||||
[type]: {
|
||||
foo: 'bar',
|
||||
hello: 'dolly',
|
||||
...counterFields.reduce((aggs, field) => {
|
||||
return {
|
||||
...aggs,
|
||||
[field]: 1,
|
||||
};
|
||||
}, {}),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
expect.anything()
|
||||
|
@ -495,12 +493,10 @@ describe('#incrementCounter', () => {
|
|||
expect(client.update).toBeCalledTimes(1);
|
||||
expect(client.update).toBeCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
script: expect.objectContaining({
|
||||
params: expect.objectContaining({
|
||||
counterFieldNames: [counterFields[0]],
|
||||
counts: [3],
|
||||
}),
|
||||
script: expect.objectContaining({
|
||||
params: expect.objectContaining({
|
||||
counterFieldNames: [counterFields[0]],
|
||||
counts: [3],
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
|
@ -514,12 +510,10 @@ describe('#incrementCounter', () => {
|
|||
expect(client.update).toBeCalledTimes(1);
|
||||
expect(client.update).toBeCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
script: expect.objectContaining({
|
||||
params: expect.objectContaining({
|
||||
counterFieldNames: [counterFields[0]],
|
||||
counts: [0],
|
||||
}),
|
||||
script: expect.objectContaining({
|
||||
params: expect.objectContaining({
|
||||
counterFieldNames: [counterFields[0]],
|
||||
counts: [0],
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
|
|
|
@ -134,7 +134,7 @@ describe('collectMultiNamespaceReferences', () => {
|
|||
...objects: SavedObjectsCollectMultiNamespaceReferencesObject[]
|
||||
) {
|
||||
const docs = objects.map(({ type, id }) => expect.objectContaining({ _id: `${type}:${id}` }));
|
||||
expect(client.mget).toHaveBeenNthCalledWith(n, { body: { docs } }, expect.anything());
|
||||
expect(client.mget).toHaveBeenNthCalledWith(n, { docs }, expect.anything());
|
||||
}
|
||||
|
||||
it('returns an empty array if no object args are passed in', async () => {
|
||||
|
|
|
@ -185,7 +185,7 @@ async function getObjectsAndReferences({
|
|||
);
|
||||
}
|
||||
const bulkGetResponse = await client.mget(
|
||||
{ body: { docs: makeBulkGetDocs(bulkGetObjects) } },
|
||||
{ docs: makeBulkGetDocs(bulkGetObjects) },
|
||||
{ ignore: [404], meta: true }
|
||||
);
|
||||
// exit early if we can't verify a 404 response is from Elasticsearch
|
||||
|
|
|
@ -86,14 +86,12 @@ describe('deleteLegacyUrlAliases', () => {
|
|||
expect(params.client.updateByQuery).toHaveBeenCalledTimes(1);
|
||||
expect(params.client.updateByQuery).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
script: expect.objectContaining({
|
||||
params: {
|
||||
namespaces,
|
||||
matchTargetNamespaceOp: 'delete',
|
||||
notMatchTargetNamespaceOp: 'noop',
|
||||
},
|
||||
}),
|
||||
script: expect.objectContaining({
|
||||
params: {
|
||||
namespaces,
|
||||
matchTargetNamespaceOp: 'delete',
|
||||
notMatchTargetNamespaceOp: 'noop',
|
||||
},
|
||||
}),
|
||||
}),
|
||||
expect.anything()
|
||||
|
@ -111,14 +109,12 @@ describe('deleteLegacyUrlAliases', () => {
|
|||
expect(params.client.updateByQuery).toHaveBeenCalledTimes(1);
|
||||
expect(params.client.updateByQuery).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
script: expect.objectContaining({
|
||||
params: {
|
||||
namespaces,
|
||||
matchTargetNamespaceOp: 'noop',
|
||||
notMatchTargetNamespaceOp: 'delete',
|
||||
},
|
||||
}),
|
||||
script: expect.objectContaining({
|
||||
params: {
|
||||
namespaces,
|
||||
matchTargetNamespaceOp: 'noop',
|
||||
notMatchTargetNamespaceOp: 'delete',
|
||||
},
|
||||
}),
|
||||
}),
|
||||
expect.anything()
|
||||
|
|
|
@ -69,29 +69,27 @@ export async function deleteLegacyUrlAliases(params: DeleteLegacyUrlAliasesParam
|
|||
{
|
||||
index: getIndexForType(LEGACY_URL_ALIAS_TYPE),
|
||||
refresh: false, // This could be called many times in succession, intentionally do not wait for a refresh
|
||||
body: {
|
||||
...getSearchDsl(mappings, registry, {
|
||||
type: LEGACY_URL_ALIAS_TYPE,
|
||||
kueryNode: createKueryNode(type, id),
|
||||
}),
|
||||
script: {
|
||||
// Intentionally use one script source with variable params to take advantage of ES script caching
|
||||
source: `
|
||||
...(getSearchDsl(mappings, registry, {
|
||||
type: LEGACY_URL_ALIAS_TYPE,
|
||||
kueryNode: createKueryNode(type, id),
|
||||
}) as Omit<ReturnType<typeof getSearchDsl>, 'sort'>), // Omitting sort in the types in this operation because types expect only string[] and we're not really sorting
|
||||
script: {
|
||||
// Intentionally use one script source with variable params to take advantage of ES script caching
|
||||
source: `
|
||||
if (params['namespaces'].indexOf(ctx._source['${LEGACY_URL_ALIAS_TYPE}']['targetNamespace']) > -1) {
|
||||
ctx.op = params['matchTargetNamespaceOp'];
|
||||
} else {
|
||||
ctx.op = params['notMatchTargetNamespaceOp'];
|
||||
}
|
||||
`,
|
||||
params: {
|
||||
namespaces,
|
||||
matchTargetNamespaceOp: deleteBehavior === 'inclusive' ? 'delete' : 'noop',
|
||||
notMatchTargetNamespaceOp: deleteBehavior === 'inclusive' ? 'noop' : 'delete',
|
||||
},
|
||||
lang: 'painless',
|
||||
params: {
|
||||
namespaces,
|
||||
matchTargetNamespaceOp: deleteBehavior === 'inclusive' ? 'delete' : 'noop',
|
||||
notMatchTargetNamespaceOp: deleteBehavior === 'inclusive' ? 'noop' : 'delete',
|
||||
},
|
||||
conflicts: 'proceed',
|
||||
lang: 'painless',
|
||||
},
|
||||
conflicts: 'proceed',
|
||||
},
|
||||
{ ignore: [404] }
|
||||
);
|
||||
|
|
|
@ -125,36 +125,34 @@ export const incrementCounterInternal = async <T>(
|
|||
refresh,
|
||||
require_alias: true,
|
||||
_source: true,
|
||||
body: {
|
||||
script: {
|
||||
source: `
|
||||
for (int i = 0; i < params.counterFieldNames.length; i++) {
|
||||
def counterFieldName = params.counterFieldNames[i];
|
||||
def count = params.counts[i];
|
||||
script: {
|
||||
source: `
|
||||
for (int i = 0; i < params.counterFieldNames.length; i++) {
|
||||
def counterFieldName = params.counterFieldNames[i];
|
||||
def count = params.counts[i];
|
||||
|
||||
if (ctx._source[params.type][counterFieldName] == null) {
|
||||
ctx._source[params.type][counterFieldName] = count;
|
||||
}
|
||||
else {
|
||||
ctx._source[params.type][counterFieldName] += count;
|
||||
}
|
||||
}
|
||||
ctx._source.updated_at = params.time;
|
||||
`,
|
||||
lang: 'painless',
|
||||
params: {
|
||||
counts: normalizedCounterFields.map(
|
||||
(normalizedCounterField) => normalizedCounterField.incrementBy
|
||||
),
|
||||
counterFieldNames: normalizedCounterFields.map(
|
||||
(normalizedCounterField) => normalizedCounterField.fieldName
|
||||
),
|
||||
time,
|
||||
type,
|
||||
},
|
||||
if (ctx._source[params.type][counterFieldName] == null) {
|
||||
ctx._source[params.type][counterFieldName] = count;
|
||||
}
|
||||
else {
|
||||
ctx._source[params.type][counterFieldName] += count;
|
||||
}
|
||||
}
|
||||
ctx._source.updated_at = params.time;
|
||||
`,
|
||||
lang: 'painless',
|
||||
params: {
|
||||
counts: normalizedCounterFields.map(
|
||||
(normalizedCounterField) => normalizedCounterField.incrementBy
|
||||
),
|
||||
counterFieldNames: normalizedCounterFields.map(
|
||||
(normalizedCounterField) => normalizedCounterField.fieldName
|
||||
),
|
||||
time,
|
||||
type,
|
||||
},
|
||||
upsert: raw._source,
|
||||
},
|
||||
upsert: raw._source,
|
||||
});
|
||||
|
||||
const { originId } = body.get?._source ?? {};
|
||||
|
|
|
@ -147,7 +147,7 @@ describe('internalBulkResolve', () => {
|
|||
expect(client.bulk).toHaveBeenCalledTimes(1);
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: aliasIds
|
||||
operations: aliasIds
|
||||
.map((id) => [
|
||||
{
|
||||
update: {
|
||||
|
@ -169,12 +169,10 @@ describe('internalBulkResolve', () => {
|
|||
expect(client.mget).toHaveBeenCalledTimes(1);
|
||||
expect(client.mget).toHaveBeenCalledWith(
|
||||
{
|
||||
body: {
|
||||
docs: objectIds.map((id) => ({
|
||||
_id: serializer.generateRawId(normalizedNamespace, OBJ_TYPE, id),
|
||||
_index: `index-for-${OBJ_TYPE}`,
|
||||
})),
|
||||
},
|
||||
docs: objectIds.map((id) => ({
|
||||
_id: serializer.generateRawId(normalizedNamespace, OBJ_TYPE, id),
|
||||
_index: `index-for-${OBJ_TYPE}`,
|
||||
})),
|
||||
},
|
||||
expect.anything()
|
||||
);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import type { MgetResponseItem } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { MgetResponseItem } from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal';
|
||||
import type {
|
||||
|
@ -141,7 +141,7 @@ export async function internalBulkResolve<T>(
|
|||
|
||||
const bulkGetResponse = docsToBulkGet.length
|
||||
? await client.mget<SavedObjectsRawDocSource>(
|
||||
{ body: { docs: docsToBulkGet } },
|
||||
{ docs: docsToBulkGet },
|
||||
{ ignore: [404], meta: true }
|
||||
)
|
||||
: undefined;
|
||||
|
@ -330,7 +330,7 @@ async function fetchAndUpdateAliases(
|
|||
const bulkUpdateResponse = await client.bulk({
|
||||
refresh: false,
|
||||
require_alias: true,
|
||||
body: bulkUpdateDocs,
|
||||
operations: bulkUpdateDocs,
|
||||
});
|
||||
return bulkUpdateResponse.items.map((item) => {
|
||||
// Map the bulk update response to the `_source` fields that were returned for each document
|
||||
|
|
|
@ -66,7 +66,7 @@ describe('preflightCheckForCreate', () => {
|
|||
return found
|
||||
? {
|
||||
// @ts-expect-error
|
||||
_id: params!.body!.docs![i]._id as string, // needed for mockRawDocExistsInNamespaces mock implementation and existingDocument assertions
|
||||
_id: params!.docs![i]._id, // needed for mockRawDocExistsInNamespaces mock implementation and existingDocument assertions
|
||||
_index: 'doesnt-matter',
|
||||
_source: {
|
||||
...(disabled !== undefined && { [LEGACY_URL_ALIAS_TYPE]: { disabled } }),
|
||||
|
@ -86,7 +86,7 @@ describe('preflightCheckForCreate', () => {
|
|||
/** Asserts that mget is called for the given raw object IDs */
|
||||
function expectMgetArgs(...rawObjectIds: string[]) {
|
||||
const docs = rawObjectIds.map((_id) => expect.objectContaining({ _id }));
|
||||
expect(client.mget).toHaveBeenCalledWith({ body: { docs } }, expect.anything());
|
||||
expect(client.mget).toHaveBeenCalledWith({ docs }, expect.anything());
|
||||
}
|
||||
|
||||
/** Asserts that findLegacyUrlAliases is called for the given objects */
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal';
|
||||
import {
|
||||
type ISavedObjectTypeRegistry,
|
||||
|
@ -278,7 +278,7 @@ async function bulkGetObjectsAndAliases(
|
|||
|
||||
const bulkGetResponse = docsToBulkGet.length
|
||||
? await client.mget<SavedObjectsRawDocSource>(
|
||||
{ body: { docs: docsToBulkGet } },
|
||||
{ docs: docsToBulkGet },
|
||||
{ ignore: [404], meta: true }
|
||||
)
|
||||
: undefined;
|
||||
|
|
|
@ -134,7 +134,7 @@ describe('#updateObjectsSpaces', () => {
|
|||
/** Asserts that mget is called for the given objects */
|
||||
function expectMgetArgs(...objects: SavedObjectsUpdateObjectsSpacesObject[]) {
|
||||
const docs = objects.map(({ type, id }) => expect.objectContaining({ _id: `${type}:${id}` }));
|
||||
expect(client.mget).toHaveBeenCalledWith({ body: { docs } }, expect.anything());
|
||||
expect(client.mget).toHaveBeenCalledWith({ docs }, expect.anything());
|
||||
}
|
||||
|
||||
/** Mocks the saved objects client so it returns the expected results */
|
||||
|
@ -153,14 +153,14 @@ describe('#updateObjectsSpaces', () => {
|
|||
});
|
||||
}
|
||||
|
||||
/** Asserts that mget is called for the given objects */
|
||||
/** Asserts that bulk is called for the given objects */
|
||||
function expectBulkArgs(
|
||||
...objectActions: Array<{
|
||||
object: { type: string; id: string; namespaces?: string[] };
|
||||
action: 'update' | 'delete';
|
||||
}>
|
||||
) {
|
||||
const body = objectActions.flatMap(
|
||||
const operations = objectActions.flatMap(
|
||||
({ object: { type, id, namespaces = expect.any(Array) }, action }) => {
|
||||
const operation = {
|
||||
[action]: {
|
||||
|
@ -174,7 +174,7 @@ describe('#updateObjectsSpaces', () => {
|
|||
: [operation]; // 'delete' only uses an operation
|
||||
}
|
||||
);
|
||||
expect(client.bulk).toHaveBeenCalledWith(expect.objectContaining({ body }));
|
||||
expect(client.bulk).toHaveBeenCalledWith(expect.objectContaining({ operations }));
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
import pMap from 'p-map';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import intersection from 'lodash/intersection';
|
||||
|
||||
import type { Logger } from '@kbn/logging';
|
||||
|
@ -155,7 +155,7 @@ export async function updateObjectsSpaces({
|
|||
}));
|
||||
const bulkGetResponse = bulkGetDocs.length
|
||||
? await client.mget<SavedObjectsRawDocSource>(
|
||||
{ body: { docs: bulkGetDocs } },
|
||||
{ docs: bulkGetDocs },
|
||||
{ ignore: [404], meta: true }
|
||||
)
|
||||
: undefined;
|
||||
|
@ -261,7 +261,7 @@ export async function updateObjectsSpaces({
|
|||
|
||||
const { refresh = DEFAULT_REFRESH_SETTING } = options;
|
||||
const bulkOperationResponse = bulkOperationParams.length
|
||||
? await client.bulk({ refresh, body: bulkOperationParams, require_alias: true })
|
||||
? await client.bulk({ refresh, operations: bulkOperationParams, require_alias: true })
|
||||
: undefined;
|
||||
|
||||
// Delete aliases if necessary, ensuring we don't have too many concurrent operations running.
|
||||
|
|
|
@ -189,9 +189,7 @@ describe('SavedObjectsRepository', () => {
|
|||
await successResponse('abc123');
|
||||
expect(client.closePointInTime).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
id: 'abc123',
|
||||
}),
|
||||
id: 'abc123',
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
|
|
@ -15,7 +15,7 @@ import {
|
|||
mockGetSearchDsl,
|
||||
} from '../repository.test.mock';
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import { SavedObjectsRepository } from '../repository';
|
||||
import { loggerMock } from '@kbn/logging-mocks';
|
||||
|
@ -106,9 +106,7 @@ describe('SavedObjectsRepository', () => {
|
|||
await removeReferencesToSuccess(client, repository, type, id, { type });
|
||||
|
||||
expect(client.updateByQuery).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({ ...query }),
|
||||
}),
|
||||
expect.objectContaining({ ...query }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -139,13 +137,11 @@ describe('SavedObjectsRepository', () => {
|
|||
await removeReferencesToSuccess(client, repository, type, id);
|
||||
expect(client.updateByQuery).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
script: expect.objectContaining({
|
||||
params: {
|
||||
type,
|
||||
id,
|
||||
},
|
||||
}),
|
||||
script: expect.objectContaining({
|
||||
params: {
|
||||
type,
|
||||
id,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
expect.anything()
|
||||
|
@ -270,11 +266,10 @@ describe('SavedObjectsRepository', () => {
|
|||
const client = apiExecutionContext.client;
|
||||
expect(client.updateByQuery).toHaveBeenCalledTimes(1);
|
||||
expect(client.updateByQuery).toHaveBeenLastCalledWith(
|
||||
{
|
||||
expect.objectContaining({
|
||||
refresh: false,
|
||||
index: indices,
|
||||
body: expect.any(Object),
|
||||
},
|
||||
}),
|
||||
{ ignore: [404], meta: true }
|
||||
);
|
||||
});
|
||||
|
|
|
@ -43,32 +43,30 @@ export const performRemoveReferencesTo = async <T>(
|
|||
{
|
||||
index: targetIndices,
|
||||
refresh,
|
||||
body: {
|
||||
script: {
|
||||
source: `
|
||||
if (ctx._source.containsKey('references')) {
|
||||
def items_to_remove = [];
|
||||
for (item in ctx._source.references) {
|
||||
if ( (item['type'] == params['type']) && (item['id'] == params['id']) ) {
|
||||
items_to_remove.add(item);
|
||||
}
|
||||
}
|
||||
ctx._source.references.removeAll(items_to_remove);
|
||||
script: {
|
||||
source: `
|
||||
if (ctx._source.containsKey('references')) {
|
||||
def items_to_remove = [];
|
||||
for (item in ctx._source.references) {
|
||||
if ( (item['type'] == params['type']) && (item['id'] == params['id']) ) {
|
||||
items_to_remove.add(item);
|
||||
}
|
||||
`,
|
||||
params: {
|
||||
type,
|
||||
id,
|
||||
},
|
||||
lang: 'painless',
|
||||
}
|
||||
ctx._source.references.removeAll(items_to_remove);
|
||||
}
|
||||
`,
|
||||
params: {
|
||||
type,
|
||||
id,
|
||||
},
|
||||
conflicts: 'proceed',
|
||||
...getSearchDsl(mappings, registry, {
|
||||
namespaces: namespace ? [namespace] : undefined,
|
||||
type: allTypes,
|
||||
hasReference: { type, id },
|
||||
}),
|
||||
lang: 'painless',
|
||||
},
|
||||
conflicts: 'proceed',
|
||||
...(getSearchDsl(mappings, registry, {
|
||||
namespaces: namespace ? [namespace] : undefined,
|
||||
type: allTypes,
|
||||
hasReference: { type, id },
|
||||
}) as Omit<ReturnType<typeof getSearchDsl>, 'sort'>), // TS is complaining and it's unlikely that we sort here
|
||||
},
|
||||
{ ignore: [404], meta: true }
|
||||
);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
import { mockGetCurrentTime, mockPreflightCheckForCreate } from '../repository.test.mock';
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import {
|
||||
type SavedObjectUnsanitizedDoc,
|
||||
type SavedObjectReference,
|
||||
|
@ -190,7 +190,7 @@ describe('#update', () => {
|
|||
expect(client.index).toHaveBeenCalledTimes(1);
|
||||
expect(client.index).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
document: expect.objectContaining({
|
||||
globalType: {
|
||||
foo: 'bar',
|
||||
title: 'Testing',
|
||||
|
@ -219,7 +219,7 @@ describe('#update', () => {
|
|||
expect(client.index).toHaveBeenCalledTimes(1);
|
||||
expect(client.index).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
document: expect.objectContaining({
|
||||
globalType: {
|
||||
foo: 'bar',
|
||||
},
|
||||
|
@ -250,8 +250,8 @@ describe('#update', () => {
|
|||
migrator.migrateDocument.mockImplementationOnce((doc) => ({ ...doc }));
|
||||
await updateSuccess(client, repository, registry, type, id, attributes);
|
||||
expect(
|
||||
(client.index.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>).body!
|
||||
.references
|
||||
(client.index.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>)
|
||||
.document!.references
|
||||
).toEqual([]); // we're indexing a full new doc, serializer adds default if not defined
|
||||
});
|
||||
|
||||
|
@ -262,8 +262,8 @@ describe('#update', () => {
|
|||
references,
|
||||
});
|
||||
expect(
|
||||
(client.index.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>).body!
|
||||
.references
|
||||
(client.index.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>)
|
||||
.document!.references
|
||||
).toEqual(references);
|
||||
client.index.mockClear();
|
||||
};
|
||||
|
@ -277,8 +277,8 @@ describe('#update', () => {
|
|||
references,
|
||||
});
|
||||
expect(
|
||||
(client.index.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>).body!
|
||||
.references
|
||||
(client.index.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>)
|
||||
.document!.references
|
||||
).toEqual(references);
|
||||
client.index.mockClear();
|
||||
};
|
||||
|
@ -292,8 +292,8 @@ describe('#update', () => {
|
|||
references,
|
||||
});
|
||||
expect(
|
||||
(client.index.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>).body!
|
||||
.references
|
||||
(client.index.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>)
|
||||
.document!.references
|
||||
).toEqual(references);
|
||||
client.index.mockClear();
|
||||
};
|
||||
|
@ -324,7 +324,8 @@ describe('#update', () => {
|
|||
...mockTimestampFieldsWithCreated,
|
||||
};
|
||||
expect(
|
||||
(client.create.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>).body!
|
||||
(client.create.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>)
|
||||
.document!
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
|
@ -357,7 +358,8 @@ describe('#update', () => {
|
|||
...mockTimestampFieldsWithCreated,
|
||||
};
|
||||
expect(
|
||||
(client.create.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>).body!
|
||||
(client.create.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>)
|
||||
.document!
|
||||
).toEqual(expectedType);
|
||||
});
|
||||
|
||||
|
@ -383,7 +385,7 @@ describe('#update', () => {
|
|||
index: '.kibana-test_8.0.0-testing',
|
||||
refresh: 'wait_for',
|
||||
require_alias: true,
|
||||
body: expect.objectContaining({
|
||||
document: expect.objectContaining({
|
||||
multiNamespaceIsolatedType: { title: 'Testing' },
|
||||
namespaces: ['default'],
|
||||
references: [],
|
||||
|
@ -403,8 +405,8 @@ describe('#update', () => {
|
|||
references,
|
||||
});
|
||||
expect(
|
||||
(client.index.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>).body!
|
||||
.references
|
||||
(client.index.mock.calls[0][0] as estypes.CreateRequest<SavedObjectsRawDocSource>)
|
||||
.document!.references
|
||||
).toEqual([]);
|
||||
client.index.mockClear();
|
||||
client.create.mockClear();
|
||||
|
|
|
@ -22,6 +22,7 @@ import type {
|
|||
SavedObjectsUpdateResponse,
|
||||
} from '@kbn/core-saved-objects-api-server';
|
||||
import { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal';
|
||||
import type { CreateRequest, IndexRequest } from '@elastic/elasticsearch/lib/api/types';
|
||||
import { DEFAULT_REFRESH_SETTING, DEFAULT_RETRY_COUNT } from '../constants';
|
||||
import { isValidRequest } from '../utils';
|
||||
import { getCurrentTime, getSavedObjectFromSource, mergeForUpdate } from './utils';
|
||||
|
@ -187,12 +188,13 @@ export const executeUpdate = async <T>(
|
|||
validationHelper.validateObjectForCreate(type, migratedUpsert);
|
||||
const rawUpsert = serializer.savedObjectToRaw(migratedUpsert);
|
||||
|
||||
const createRequestParams = {
|
||||
const createRequestParams: CreateRequest = {
|
||||
id: rawUpsert._id,
|
||||
index: commonHelper.getIndexForType(type),
|
||||
refresh,
|
||||
body: rawUpsert._source,
|
||||
document: rawUpsert._source,
|
||||
...(version ? decodeRequestVersion(version) : {}),
|
||||
// @ts-expect-error
|
||||
require_alias: true,
|
||||
};
|
||||
|
||||
|
@ -289,11 +291,11 @@ export const executeUpdate = async <T>(
|
|||
);
|
||||
|
||||
// implement creating the call params
|
||||
const indexRequestParams = {
|
||||
const indexRequestParams: IndexRequest = {
|
||||
id: docToSend._id,
|
||||
index: commonHelper.getIndexForType(type),
|
||||
refresh,
|
||||
body: docToSend._source,
|
||||
document: docToSend._source,
|
||||
// using version from the source doc if not provided as option to avoid erasing changes in case of concurrent calls
|
||||
...decodeRequestVersion(version || migrated!.version),
|
||||
require_alias: true,
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
/**
|
||||
* Type and type guard function for converting a possibly not existent doc to an existent doc.
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import type { Payload } from '@hapi/boom';
|
||||
import {
|
||||
SavedObjectsErrorHelpers,
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
import { isPlainObject } from 'lodash';
|
||||
import { set } from '@kbn/safer-lodash-set';
|
||||
import type { MappingProperty as EsMappingProperty } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { MappingProperty as EsMappingProperty } from '@elastic/elasticsearch/lib/api/types';
|
||||
import type {
|
||||
SavedObjectsTypeMappingDefinition,
|
||||
SavedObjectsFieldMapping,
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import type { Logger } from '@kbn/logging';
|
||||
import type {
|
||||
SavedObjectsFindOptions,
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
mockGetSearchDsl,
|
||||
} from './repository.test.mock';
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import { SavedObjectsRepository } from './repository';
|
||||
import { loggerMock } from '@kbn/logging-mocks';
|
||||
|
@ -440,14 +440,12 @@ describe('SavedObjectsRepository Encryption Extension', () => {
|
|||
) => {
|
||||
expect(client.mget).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: {
|
||||
docs: objects.map(({ type, id }) =>
|
||||
expect.objectContaining({
|
||||
_index,
|
||||
_id: getId(type, id),
|
||||
})
|
||||
),
|
||||
},
|
||||
docs: objects.map(({ type, id }) =>
|
||||
expect.objectContaining({
|
||||
_index,
|
||||
_id: getId(type, id),
|
||||
})
|
||||
),
|
||||
}),
|
||||
expect.anything()
|
||||
);
|
||||
|
|
|
@ -18,7 +18,7 @@ import {
|
|||
mockDeleteLegacyUrlAliases,
|
||||
} from './repository.test.mock';
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import { SavedObjectsRepository } from './repository';
|
||||
import { loggerMock } from '@kbn/logging-mocks';
|
||||
|
@ -234,7 +234,7 @@ describe('SavedObjectsRepository Spaces Extension', () => {
|
|||
id: `${
|
||||
currentSpace.expectedNamespace ? `${currentSpace.expectedNamespace}:` : ''
|
||||
}${type}:${id}`,
|
||||
body: expect.objectContaining(
|
||||
document: expect.objectContaining(
|
||||
currentSpace.expectedNamespace
|
||||
? {
|
||||
namespace: currentSpace.expectedNamespace,
|
||||
|
@ -274,7 +274,7 @@ describe('SavedObjectsRepository Spaces Extension', () => {
|
|||
expect(client.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
id: expect.stringMatching(regex),
|
||||
body: expect.objectContaining(
|
||||
document: expect.objectContaining(
|
||||
currentSpace.expectedNamespace
|
||||
? {
|
||||
namespace: currentSpace.expectedNamespace,
|
||||
|
@ -379,18 +379,16 @@ describe('SavedObjectsRepository Spaces Extension', () => {
|
|||
expect(client.mget).toHaveBeenCalledTimes(1);
|
||||
expect(client.mget).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
docs: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
_id: `${
|
||||
currentSpace.expectedNamespace ? `${currentSpace.expectedNamespace}:` : ''
|
||||
}${obj1.type}:${obj1.id}`,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
_id: `${obj2.type}:${obj2.id}`,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
docs: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
_id: `${
|
||||
currentSpace.expectedNamespace ? `${currentSpace.expectedNamespace}:` : ''
|
||||
}${obj1.type}:${obj1.id}`,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
_id: `${obj2.type}:${obj2.id}`,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
{ ignore: [404], meta: true }
|
||||
);
|
||||
|
@ -570,18 +568,16 @@ describe('SavedObjectsRepository Spaces Extension', () => {
|
|||
expect(client.mget).toHaveBeenCalledTimes(1);
|
||||
expect(client.mget).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
docs: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
_id: `${
|
||||
currentSpace.expectedNamespace ? `${currentSpace.expectedNamespace}:` : ''
|
||||
}${obj1.type}:${obj1.id}`,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
_id: `${obj2.type}:${obj2.id}`,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
docs: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
_id: `${
|
||||
currentSpace.expectedNamespace ? `${currentSpace.expectedNamespace}:` : ''
|
||||
}${obj1.type}:${obj1.id}`,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
_id: `${obj2.type}:${obj2.id}`,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
{ ignore: [404], meta: true }
|
||||
);
|
||||
|
@ -638,7 +634,7 @@ describe('SavedObjectsRepository Spaces Extension', () => {
|
|||
expect(client.bulk).toHaveBeenCalledTimes(1);
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.arrayContaining([
|
||||
operations: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
create: expect.objectContaining({
|
||||
_id: `${
|
||||
|
@ -696,7 +692,7 @@ describe('SavedObjectsRepository Spaces Extension', () => {
|
|||
expect(client.bulk).toHaveBeenCalledTimes(1);
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.arrayContaining([
|
||||
operations: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
index: expect.objectContaining({
|
||||
_id: `${
|
||||
|
@ -855,7 +851,7 @@ describe('SavedObjectsRepository Spaces Extension', () => {
|
|||
expect(client.bulk).toHaveBeenCalledTimes(1);
|
||||
expect(client.bulk).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
body: expect.arrayContaining([
|
||||
operations: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
delete: expect.objectContaining({
|
||||
_id: `${
|
||||
|
|
|
@ -537,9 +537,7 @@ export class SavedObjectsRepository implements ISavedObjectsRepository {
|
|||
this.extensions.securityExtension.auditClosePointInTime();
|
||||
}
|
||||
|
||||
return await this.client.closePointInTime({
|
||||
body: { id },
|
||||
});
|
||||
return await this.client.closePointInTime({ id });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,19 +25,19 @@ describe('RepositoryEsClient', () => {
|
|||
|
||||
it('delegates call to ES client method', async () => {
|
||||
expect(repositoryClient.bulk).toStrictEqual(expect.any(Function));
|
||||
await repositoryClient.bulk({ body: [] });
|
||||
await repositoryClient.bulk({ operations: [] });
|
||||
expect(client.bulk).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('wraps a method call in retryCallCluster', async () => {
|
||||
await repositoryClient.bulk({ body: [] });
|
||||
await repositoryClient.bulk({ operations: [] });
|
||||
expect(retryCallClusterMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('keeps call options unchanged', async () => {
|
||||
expect(repositoryClient.bulk).toStrictEqual(expect.any(Function));
|
||||
const options = { maxRetries: 12 };
|
||||
await repositoryClient.bulk({ body: [] }, options);
|
||||
await repositoryClient.bulk({ operations: [] }, options);
|
||||
expect(client.bulk).toHaveBeenCalledWith(expect.any(Object), options);
|
||||
});
|
||||
|
||||
|
@ -45,7 +45,7 @@ describe('RepositoryEsClient', () => {
|
|||
expect.assertions(1);
|
||||
client.bulk.mockRejectedValue(new Error('reason'));
|
||||
try {
|
||||
await repositoryClient.bulk({ body: [] });
|
||||
await repositoryClient.bulk({ operations: [] });
|
||||
} catch (e) {
|
||||
expect(SavedObjectsErrorHelpers.isSavedObjectsClientError(e)).toBe(true);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { validateAndConvertAggregations } from './validation';
|
||||
|
||||
type AggsMap = Record<string, estypes.AggregationsAggregationContainer>;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { ObjectType } from '@kbn/config-schema';
|
||||
import { isPlainObject, isArray } from 'lodash';
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
import Boom from '@hapi/boom';
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
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';
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
import Boom from '@hapi/boom';
|
||||
import type { SortOrder, SortCombinations } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { SortOrder, SortCombinations } from '@elastic/elasticsearch/lib/api/types';
|
||||
import type { SavedObjectsPitParams } from '@kbn/core-saved-objects-api-server/src/apis';
|
||||
import { getProperty, type IndexMapping } from '@kbn/core-saved-objects-base-server-internal';
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { loggerMock } from '@kbn/logging-mocks';
|
||||
import type { Payload } from 'elastic-apm-node';
|
||||
|
|
|
@ -11,7 +11,7 @@ import type {
|
|||
SortOrder,
|
||||
AggregationsAggregationContainer,
|
||||
SortResults,
|
||||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
} from '@elastic/elasticsearch/lib/api/types';
|
||||
import type { SavedObject } from '../..';
|
||||
|
||||
type KueryNode = any;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import { MappingProperty as EsMappingProperty } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { MappingProperty as EsMappingProperty } from '@elastic/elasticsearch/lib/api/types';
|
||||
import type {
|
||||
SavedObjectsTypeMappingDefinition,
|
||||
SavedObjectsFieldMapping,
|
||||
|
|
|
@ -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/typesWithBodyKey';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { errors as esErrors } from '@elastic/elasticsearch';
|
||||
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||
import {
|
||||
|
|
|
@ -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/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import type {
|
||||
ElasticsearchClient,
|
||||
ElasticsearchCapabilities,
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
import * as Either from 'fp-ts/lib/Either';
|
||||
import * as TaskEither from 'fp-ts/lib/TaskEither';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { errors as EsErrors } from '@elastic/elasticsearch';
|
||||
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||
import type { SavedObjectsRawDoc } from '@kbn/core-saved-objects-server';
|
||||
|
|
|
@ -11,7 +11,7 @@ import type {
|
|||
PropertyName as EsPropertyName,
|
||||
MappingProperty as EsMappingProperty,
|
||||
MappingPropertyBase as EsMappingPropertyBase,
|
||||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
} from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
/**
|
||||
* Describe a saved object type mapping.
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
|
||||
import type { MaybePromise } from '@kbn/utility-types';
|
||||
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||
import type { SavedObjectsNamespaceType } from '@kbn/core-saved-objects-common';
|
||||
|
|
|
@ -16,7 +16,7 @@ import type {
|
|||
AggregationsMultiBucketAggregateBase,
|
||||
AggregationsSingleBucketAggregateBase,
|
||||
SearchTotalHits,
|
||||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
} from '@elastic/elasticsearch/lib/api/types';
|
||||
import type { CoreContext, CoreService } from '@kbn/core-base-server-internal';
|
||||
import type { LoggingConfigType } from '@kbn/core-logging-server-internal';
|
||||
import type { Logger } from '@kbn/logging';
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { InternalCoreStart } from '@kbn/core-lifecycle-server-internal';
|
||||
import { Root } from '@kbn/core-root-server-internal';
|
||||
import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
|
||||
|
|
|
@ -13,7 +13,6 @@ export type {
|
|||
SearchHit,
|
||||
ESSearchResponse,
|
||||
ESSearchRequest,
|
||||
ESSearchRequestWithoutBody,
|
||||
ESSourceOptions,
|
||||
InferSearchResponseOf,
|
||||
AggregationResultOf,
|
||||
|
|
|
@ -7,12 +7,10 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypesWithoutBody from '@elastic/elasticsearch/lib/api/types';
|
||||
import type {
|
||||
Field,
|
||||
QueryDslFieldAndFormat,
|
||||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
// TODO: Remove when all usages have been migrated to non-body
|
||||
import { SearchRequest as SearchRequestWithBodyKey } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { Field, QueryDslFieldAndFormat } from '@elastic/elasticsearch/lib/api/types';
|
||||
import {
|
||||
InferSearchResponseOf,
|
||||
AggregateOf as AggregationResultOf,
|
||||
|
@ -26,8 +24,8 @@ import {
|
|||
} from './search';
|
||||
|
||||
export type ESFilter = estypes.QueryDslQueryContainer;
|
||||
export type ESSearchRequest = estypes.SearchRequest;
|
||||
export type ESSearchRequestWithoutBody = estypesWithoutBody.SearchRequest;
|
||||
// For now, we also accept with body to unblock the migration to without body.
|
||||
export type ESSearchRequest = estypes.SearchRequest | SearchRequestWithBodyKey;
|
||||
export type AggregationOptionsByType = Required<estypes.AggregationsAggregationContainer>;
|
||||
|
||||
// Typings for Elasticsearch queries and aggregations. These are intended to be
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
*/
|
||||
|
||||
import type { ValuesType, UnionToIntersection } from 'utility-types';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import * as estypesWithoutBodyKey from '@elastic/elasticsearch/lib/api/types';
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
// TODO: Remove when all usages have been migrated to non-body
|
||||
import { SearchRequest as SearchRequestWithBodyKey } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
|
||||
interface AggregationsAggregationContainer extends Record<string, any> {
|
||||
aggs?: any;
|
||||
|
@ -61,7 +62,7 @@ type ValueTypeOfField<T> = T extends Record<string, string | number>
|
|||
|
||||
type MaybeArray<T> = T | T[];
|
||||
|
||||
type Fields = Required<Required<estypes.SearchRequest>['body']>['fields'];
|
||||
type Fields = Required<estypes.SearchRequest>['fields'];
|
||||
type DocValueFields = MaybeArray<string | estypes.QueryDslFieldAndFormat>;
|
||||
|
||||
export type ChangePointType =
|
||||
|
@ -635,8 +636,8 @@ type WrapAggregationResponse<T> = keyof UnionToIntersection<T> extends never
|
|||
export type InferSearchResponseOf<
|
||||
TDocument = unknown,
|
||||
TSearchRequest extends
|
||||
| estypes.SearchRequest
|
||||
| (estypesWithoutBodyKey.SearchRequest & { body?: never }) = estypes.SearchRequest,
|
||||
| (estypes.SearchRequest & { body?: never }) // the union is necessary for the check 4 lines below
|
||||
| SearchRequestWithBodyKey = estypes.SearchRequest,
|
||||
TOptions extends { restTotalHitsAsInt?: boolean } = {}
|
||||
> = Omit<estypes.SearchResponse<TDocument>, 'aggregations' | 'hits'> &
|
||||
(TSearchRequest['body'] extends TopLevelAggregationRequest
|
||||
|
@ -656,7 +657,7 @@ export type InferSearchResponseOf<
|
|||
};
|
||||
}) & {
|
||||
hits: HitsOf<
|
||||
TSearchRequest extends estypes.SearchRequest ? TSearchRequest['body'] : TSearchRequest,
|
||||
TSearchRequest extends SearchRequestWithBodyKey ? TSearchRequest['body'] : TSearchRequest,
|
||||
TDocument
|
||||
>;
|
||||
};
|
||||
|
@ -690,5 +691,5 @@ export interface ESQLSearchParams {
|
|||
locale?: string;
|
||||
include_ccs_metadata?: boolean;
|
||||
dropNullColumns?: boolean;
|
||||
params?: estypesWithoutBodyKey.ScalarValue[] | Array<Record<string, string | undefined>>;
|
||||
params?: estypes.ScalarValue[] | Array<Record<string, string | undefined>>;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
import { merge, omit } from 'lodash';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import { getLocalStats, handleLocalStats } from './get_local_stats';
|
||||
import {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import {
|
||||
StatsGetter,
|
||||
StatsCollectionContext,
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
import type { ElasticsearchClient } from '@kbn/core/server';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { TIMEOUT } from './constants';
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { ElasticsearchClient } from '@kbn/core/server';
|
||||
|
||||
export type ESLicense = estypes.LicenseGetLicenseInformation;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { coreMock, elasticsearchServiceMock } from '@kbn/core/server/mocks';
|
||||
import { getStatsWithXpack } from './get_stats_with_xpack';
|
||||
import { SavedObjectsClient } from '@kbn/core/server';
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { getLicenseFetcher } from './license_fetcher';
|
||||
import { loggerMock, type MockedLogger } from '@kbn/logging-mocks';
|
||||
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import { createHash } from 'crypto';
|
||||
import pRetry from 'p-retry';
|
||||
import stringify from 'json-stable-stringify';
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import moment from 'moment';
|
||||
import { BehaviorSubject, firstValueFrom, take, toArray } from 'rxjs';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
|
||||
import {
|
||||
ClusterClientMock,
|
||||
coreMock,
|
||||
|
|
|
@ -61,16 +61,13 @@ export function forecastServiceFactory(mlApi: MlApi) {
|
|||
mlApi.results
|
||||
.anomalySearch(
|
||||
{
|
||||
// @ts-expect-error SearchRequest type has not been updated to include size
|
||||
size: maxResults,
|
||||
body: {
|
||||
query: {
|
||||
bool: {
|
||||
filter: filterCriteria,
|
||||
},
|
||||
query: {
|
||||
bool: {
|
||||
filter: filterCriteria,
|
||||
},
|
||||
sort: [{ forecast_create_timestamp: { order: 'desc' } }],
|
||||
},
|
||||
sort: [{ forecast_create_timestamp: { order: 'desc' } }],
|
||||
},
|
||||
[job.job_id]
|
||||
)
|
||||
|
@ -124,24 +121,21 @@ export function forecastServiceFactory(mlApi: MlApi) {
|
|||
mlApi.results
|
||||
.anomalySearch(
|
||||
{
|
||||
// @ts-expect-error SearchRequest type has not been updated to include size
|
||||
size: 0,
|
||||
body: {
|
||||
query: {
|
||||
bool: {
|
||||
filter: filterCriteria,
|
||||
query: {
|
||||
bool: {
|
||||
filter: filterCriteria,
|
||||
},
|
||||
},
|
||||
aggs: {
|
||||
earliest: {
|
||||
min: {
|
||||
field: 'timestamp',
|
||||
},
|
||||
},
|
||||
aggs: {
|
||||
earliest: {
|
||||
min: {
|
||||
field: 'timestamp',
|
||||
},
|
||||
},
|
||||
latest: {
|
||||
max: {
|
||||
field: 'timestamp',
|
||||
},
|
||||
latest: {
|
||||
max: {
|
||||
field: 'timestamp',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -264,36 +258,33 @@ export function forecastServiceFactory(mlApi: MlApi) {
|
|||
return mlApi.results
|
||||
.anomalySearch$(
|
||||
{
|
||||
// @ts-expect-error SearchRequest type has not been updated to include size
|
||||
size: 0,
|
||||
body: {
|
||||
query: {
|
||||
bool: {
|
||||
filter: filterCriteria,
|
||||
},
|
||||
query: {
|
||||
bool: {
|
||||
filter: filterCriteria,
|
||||
},
|
||||
aggs: {
|
||||
times: {
|
||||
date_histogram: {
|
||||
field: 'timestamp',
|
||||
fixed_interval: `${intervalMs}ms`,
|
||||
min_doc_count: 1,
|
||||
},
|
||||
aggs: {
|
||||
times: {
|
||||
date_histogram: {
|
||||
field: 'timestamp',
|
||||
fixed_interval: `${intervalMs}ms`,
|
||||
min_doc_count: 1,
|
||||
},
|
||||
aggs: {
|
||||
prediction: {
|
||||
[forecastAggs.avg]: {
|
||||
field: 'forecast_prediction',
|
||||
},
|
||||
},
|
||||
aggs: {
|
||||
prediction: {
|
||||
[forecastAggs.avg]: {
|
||||
field: 'forecast_prediction',
|
||||
},
|
||||
forecastUpper: {
|
||||
[forecastAggs.max]: {
|
||||
field: 'forecast_upper',
|
||||
},
|
||||
forecastUpper: {
|
||||
[forecastAggs.max]: {
|
||||
field: 'forecast_upper',
|
||||
},
|
||||
},
|
||||
forecastLower: {
|
||||
[forecastAggs.min]: {
|
||||
field: 'forecast_lower',
|
||||
},
|
||||
},
|
||||
forecastLower: {
|
||||
[forecastAggs.min]: {
|
||||
field: 'forecast_lower',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -368,13 +359,10 @@ export function forecastServiceFactory(mlApi: MlApi) {
|
|||
mlApi.results
|
||||
.anomalySearch(
|
||||
{
|
||||
// @ts-expect-error SearchRequest type has not been updated to include size
|
||||
size: 1,
|
||||
body: {
|
||||
query: {
|
||||
bool: {
|
||||
filter: filterCriteria,
|
||||
},
|
||||
query: {
|
||||
bool: {
|
||||
filter: filterCriteria,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types';
|
||||
import type { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { InferSearchResponseOf } from '@kbn/es-types';
|
||||
import type { KibanaRequest } from '@kbn/core/server';
|
||||
import type { ElasticsearchClient } from '@kbn/core/server';
|
||||
import { entitiesAliasPattern, ENTITY_LATEST, ENTITY_HISTORY } from '@kbn/entities-schema';
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
import { isEmpty } from 'lodash';
|
||||
import type { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types';
|
||||
import type { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { InferSearchResponseOf } from '@kbn/es-types';
|
||||
import type { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common';
|
||||
import type { DataTier } from '@kbn/observability-shared-plugin/common';
|
||||
import { searchExcludedDataTiers } from '@kbn/observability-plugin/common/ui_settings_keys';
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { ESSearchRequest, ESSearchResponse } from '@kbn/es-types';
|
||||
import type { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { ESSearchResponse } from '@kbn/es-types';
|
||||
import type { RuleExecutorServices } from '@kbn/alerting-plugin/server';
|
||||
import type { IUiSettingsClient } from '@kbn/core/server';
|
||||
import type { DataTier } from '@kbn/observability-shared-plugin/common';
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||
import type { CoreRequestHandlerContext } from '@kbn/core-http-request-handler-context-server';
|
||||
import { rangeQuery, typedSearch } from '@kbn/observability-plugin/server/utils/queries';
|
||||
import type * as t from 'io-ts';
|
||||
import moment from 'moment';
|
||||
import type { ESSearchRequest } from '@kbn/es-types';
|
||||
import type { alertDetailsContextRt } from '@kbn/observability-plugin/server/services';
|
||||
import type { LogSourcesService } from '@kbn/logs-data-access-plugin/common/types';
|
||||
import { CONTAINER_ID } from '@kbn/apm-types';
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||
import { rangeQuery, termQuery, typedSearch } from '@kbn/observability-plugin/server/utils/queries';
|
||||
import type * as t from 'io-ts';
|
||||
import moment from 'moment';
|
||||
import type { ESSearchRequest } from '@kbn/es-types';
|
||||
import type { alertDetailsContextRt } from '@kbn/observability-plugin/server/services';
|
||||
import type { LogSourcesService } from '@kbn/logs-data-access-plugin/common/types';
|
||||
import { unflattenKnownApmEventFields } from '@kbn/apm-data-access-plugin/server/utils';
|
||||
|
|
|
@ -14,8 +14,9 @@ import type {
|
|||
TermsEnumRequest,
|
||||
TermsEnumResponse,
|
||||
} from '@elastic/elasticsearch/lib/api/types';
|
||||
import type { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { ElasticsearchClient, KibanaRequest } from '@kbn/core/server';
|
||||
import type { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types';
|
||||
import type { InferSearchResponseOf } from '@kbn/es-types';
|
||||
import { ProcessorEvent } from '@kbn/observability-plugin/common';
|
||||
import { unwrapEsResponse } from '@kbn/observability-plugin/server';
|
||||
import { compact, omit } from 'lodash';
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* 2.0.
|
||||
*/
|
||||
import { isEmpty } from 'lodash';
|
||||
import type { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types';
|
||||
import type { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { InferSearchResponseOf } from '@kbn/es-types';
|
||||
import type { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common';
|
||||
import type { KibanaRequest } from '@kbn/core/server';
|
||||
import { OBSERVABILITY_RULE_TYPE_IDS } from '@kbn/rule-data-utils';
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
import type { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types';
|
||||
import type { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { InferSearchResponseOf } from '@kbn/es-types';
|
||||
import type { KibanaRequest } from '@kbn/core/server';
|
||||
import { searchExcludedDataTiers } from '@kbn/observability-plugin/common/ui_settings_keys';
|
||||
import type { DataTier } from '@kbn/observability-shared-plugin/common';
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
import { isEmpty } from 'lodash';
|
||||
import type { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types';
|
||||
import type { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { InferSearchResponseOf } from '@kbn/es-types';
|
||||
import type { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common';
|
||||
import { OBSERVABILITY_RULE_TYPE_IDS } from '@kbn/rule-data-utils';
|
||||
import type { InventoryRouteHandlerResources } from '../../routes/types';
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types';
|
||||
import { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { InferSearchResponseOf } from '@kbn/es-types';
|
||||
import type { KibanaRequest } from '@kbn/core/server';
|
||||
import { ElasticsearchClient } from '@kbn/core/server';
|
||||
import { entitiesAliasPattern, ENTITY_LATEST } from '@kbn/entities-schema';
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
import { isEmpty } from 'lodash';
|
||||
import { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types';
|
||||
import { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { InferSearchResponseOf } from '@kbn/es-types';
|
||||
import { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common';
|
||||
import { OBSERVABILITY_RULE_TYPE_IDS } from '@kbn/rule-data-utils';
|
||||
import { InvestigateAppRouteHandlerResources } from '../routes/types';
|
||||
|
|
|
@ -10,36 +10,32 @@
|
|||
* valid deprecations
|
||||
*/
|
||||
|
||||
import type { IndicesCreateRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import type { IndicesCreateRequest } from '@elastic/elasticsearch/lib/api/types';
|
||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||
|
||||
const translogSettingsIndexDeprecation: IndicesCreateRequest = {
|
||||
index: 'deprecated_settings',
|
||||
body: {
|
||||
settings: {
|
||||
'translog.retention.size': '1b',
|
||||
'translog.retention.age': '5m',
|
||||
'index.soft_deletes.enabled': true,
|
||||
},
|
||||
settings: {
|
||||
'translog.retention.size': '1b',
|
||||
'translog.retention.age': '5m',
|
||||
'index.soft_deletes.enabled': true,
|
||||
},
|
||||
};
|
||||
|
||||
const multiFieldsIndexDeprecation: IndicesCreateRequest = {
|
||||
index: 'nested_multi_fields',
|
||||
body: {
|
||||
mappings: {
|
||||
properties: {
|
||||
text: {
|
||||
type: 'text',
|
||||
fields: {
|
||||
english: {
|
||||
type: 'text',
|
||||
analyzer: 'english',
|
||||
fields: {
|
||||
english: {
|
||||
type: 'text',
|
||||
analyzer: 'english',
|
||||
},
|
||||
mappings: {
|
||||
properties: {
|
||||
text: {
|
||||
type: 'text',
|
||||
fields: {
|
||||
english: {
|
||||
type: 'text',
|
||||
analyzer: 'english',
|
||||
fields: {
|
||||
english: {
|
||||
type: 'text',
|
||||
analyzer: 'english',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue