Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { ElasticsearchClient, Logger } from '@kbn/core/server';
import type { ESQLSearchResponse } from '@kbn/es-types';

const BATCH_SIZE = 5 * 1024 * 1024; // 5MB
const RETRY_ON_CONFLICT = 3;

interface IngestEntitiesParams {
esClient: ElasticsearchClient;
Expand Down Expand Up @@ -86,7 +87,16 @@ export async function ingestEntities({
retries: 2,
onDocument: (doc) => {
const { _id, ...document } = doc;
return [{ index: { _index: targetIndex, _id: _id as string } }, document];
return [
{
update: {
_index: targetIndex,
_id: _id as string,
retry_on_conflict: RETRY_ON_CONFLICT,
},
},
{ doc: document, doc_as_upsert: true },
];
},
onDrop: (dropped) => {
// Log dropped documents but don't throw - allows bulk operation to continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const searchDocById = async (esClient: EsClient, id: string) => {
await esClient.indices.refresh({ index: LATEST_INDEX });
return await esClient.search({
index: LATEST_INDEX,
version: true,
query: {
bool: {
filter: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ apiTest.describe('Entity Store Logs Extraction', { tag: ENTITY_STORE_TAGS }, ()
expect(firstExtractionResponse.body).toMatchObject({ count: 1 });

const beforeSubType = await searchDocById(esClient, 'user:latest-test');

expect(beforeSubType.hits.hits).toHaveLength(1);
expect(beforeSubType.hits.hits[0]._version).toBe(1);
expect(beforeSubType.hits.hits[0]._source).toMatchObject({
'@timestamp': '2026-02-13T11:00:00.000Z',
'entity.id': 'user:latest-test',
Expand Down Expand Up @@ -253,6 +255,7 @@ apiTest.describe('Entity Store Logs Extraction', { tag: ENTITY_STORE_TAGS }, ()

const afterSubType = await searchDocById(esClient, 'user:latest-test');
expect(afterSubType.hits.hits).toHaveLength(1);
expect(afterSubType.hits.hits[0]._version).toBe(2);
expect(afterSubType.hits.hits[0]._source).toMatchObject({
'@timestamp': '2026-02-13T11:01:00.000Z',
'entity.id': 'user:latest-test',
Expand Down Expand Up @@ -318,6 +321,7 @@ apiTest.describe('Entity Store Logs Extraction', { tag: ENTITY_STORE_TAGS }, ()

const updatedSubType = await searchDocById(esClient, 'user:latest-test');
expect(updatedSubType.hits.hits).toHaveLength(1);
expect(updatedSubType.hits.hits[0]._version).toBe(3);
expect(updatedSubType.hits.hits[0]._source).toMatchObject({
'@timestamp': '2026-02-13T11:02:04.000Z',
'entity.id': 'user:latest-test',
Expand Down Expand Up @@ -349,6 +353,7 @@ apiTest.describe('Entity Store Logs Extraction', { tag: ENTITY_STORE_TAGS }, ()

const updatedLatestDomain = await searchDocById(esClient, 'user:latest-test');
expect(updatedLatestDomain.hits.hits).toHaveLength(1);
expect(updatedLatestDomain.hits.hits[0]._version).toBe(4);
expect(updatedLatestDomain.hits.hits[0]._source).toMatchObject({
'@timestamp': '2026-02-13T11:03:00.000Z',
'entity.id': 'user:latest-test',
Expand Down