Skip to content

Commit f504dee

Browse files
authored
try to use built in ES helper to bulk index records into ES (#55888)
1 parent 3f9ee67 commit f504dee

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/search/scripts/index/utils/indexing-elasticsearch-utils.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ export async function populateIndex(
4040
options: Options,
4141
) {
4242
console.log(chalk.yellow(`\nIndexing ${chalk.bold(indexName)}`))
43-
const bulkOperations = records.flatMap((doc) => [{ index: { _index: indexAlias } }, doc])
44-
45-
const bulkOptions = {
46-
refresh: false,
47-
timeout: '5m',
48-
}
4943

5044
const attempts = options.retries || 0
5145
const sleepTime = options.sleepTime || DEFAULT_SLEEPTIME_SECONDS * 1000
@@ -57,7 +51,15 @@ export async function populateIndex(
5751
const t0 = new Date()
5852
const bulkResponse = await retryOnErrorTest(
5953
(error) => error instanceof errors.ResponseError && error.meta.statusCode === 429,
60-
() => client.bulk({ operations: bulkOperations, ...bulkOptions }),
54+
() =>
55+
client.helpers.bulk({
56+
datasource: records,
57+
onDocument: () => ({ index: { _index: indexAlias } }),
58+
flushBytes: 10_000_000, // stop before breaker trips
59+
concurrency: 2, // back-off a bit
60+
refreshOnCompletion: true,
61+
timeout: '5m',
62+
}),
6163
{
6264
attempts,
6365
sleepTime,

0 commit comments

Comments
 (0)