Skip to content

Commit cff05ea

Browse files
heiskrCopilot
andauthored
Set 5s request timeout on Elasticsearch client (#60398)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b4fa813 commit cff05ea

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/search/lib/helpers/get-client.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { Client } from '@elastic/elasticsearch'
22
import { safeUrlDisplay } from '@/search/lib/helpers/strings'
33

4-
export function getElasticsearchClient(overrideURL = '', verbose = false): Client {
4+
const DEFAULT_REQUEST_TIMEOUT = 5000
5+
6+
export function getElasticsearchClient(
7+
overrideURL = '',
8+
verbose = false,
9+
options?: { requestTimeout?: number },
10+
): Client {
511
const node = getElasticsearchURL(overrideURL)
612
if (verbose) {
713
console.log('Connecting to Elasticsearch URL:', safeUrlDisplay(node))
814
}
9-
const client = new Client({ node })
15+
const client = new Client({
16+
node,
17+
requestTimeout: options?.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT,
18+
})
1019
return client
1120
}
1221

src/search/scripts/index/lib/index-ai-search-autocomplete.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ type Options = {
2626
}
2727

2828
export async function indexAISearchAutocomplete(options: Options) {
29-
const client = getElasticsearchClient(undefined, options.verbose)
29+
const client = getElasticsearchClient(undefined, options.verbose, {
30+
requestTimeout: 5 * 60 * 1000,
31+
})
3032
await client.ping() // Will throw if not available
3133

3234
console.log(

src/search/scripts/index/lib/index-general-search.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export async function indexGeneralSearch(sourceDirectory: string, opts: Options)
4242
throw new Error("Can't combine --language and --not-language")
4343
}
4444

45-
const client = getElasticsearchClient(opts.elasticsearchUrl, opts.verbose)
45+
const client = getElasticsearchClient(opts.elasticsearchUrl, opts.verbose, {
46+
requestTimeout: 5 * 60 * 1000,
47+
})
4648
await client.ping() // Will throw if not available
4749

4850
let versions: string[] | 'all' = []

0 commit comments

Comments
 (0)