Update helpers to use new multisearch types (#2697) (#2698)

* Update helpers to use correct multisearch types

The spec combined definitions for search and multisearch bodies in
https://github.com/elastic/elasticsearch-specification/pull/2960.

* Stop copying project files to Dockerfile

Slightly faster run times for codegen, hopefully.

(cherry picked from commit b2a490718d)

Co-authored-by: Josh Mock <joshua.mock@elastic.co>
This commit is contained in:
github-actions[bot]
2025-04-04 12:33:43 -05:00
committed by GitHub
parent 1fec78ed36
commit 3b6c2e1be6
3 changed files with 7 additions and 12 deletions

View File

@ -12,5 +12,3 @@ WORKDIR /usr/src/app
COPY package.json . COPY package.json .
RUN npm install RUN npm install
COPY . .

View File

@ -25,6 +25,3 @@ USER ${BUILDER_UID}:${BUILDER_GID}
# install dependencies # install dependencies
COPY package.json . COPY package.json .
RUN npm install RUN npm install
# copy project files
COPY . .

View File

@ -41,7 +41,7 @@ export interface MsearchHelperOptions extends T.MsearchRequest {
export interface MsearchHelper extends Promise<void> { export interface MsearchHelper extends Promise<void> {
stop: (error?: Error | null) => void stop: (error?: Error | null) => void
search: <TDocument = unknown>(header: T.MsearchMultisearchHeader, body: T.MsearchMultisearchBody) => Promise<MsearchHelperResponse<TDocument>> search: <TDocument = unknown>(header: T.MsearchMultisearchHeader, body: T.SearchSearchRequestBody) => Promise<MsearchHelperResponse<TDocument>>
} }
export interface MsearchHelperResponse<TDocument> { export interface MsearchHelperResponse<TDocument> {
@ -362,7 +362,7 @@ export default class Helpers {
// TODO: support abort a single search? // TODO: support abort a single search?
// NOTE: the validation checks are synchronous and the callback/promise will // NOTE: the validation checks are synchronous and the callback/promise will
// be resolved in the same tick. We might want to fix this in the future. // be resolved in the same tick. We might want to fix this in the future.
search<TDocument = unknown> (header: T.MsearchMultisearchHeader, body: T.MsearchMultisearchBody): Promise<MsearchHelperResponse<TDocument>> { search<TDocument = unknown> (header: T.MsearchMultisearchHeader, body: T.SearchSearchRequestBody): Promise<MsearchHelperResponse<TDocument>> {
if (stopReading) { if (stopReading) {
const error = stopError === null const error = stopError === null
? new ConfigurationError('The msearch processor has been stopped') ? new ConfigurationError('The msearch processor has been stopped')
@ -397,7 +397,7 @@ export default class Helpers {
async function iterate (): Promise<void> { async function iterate (): Promise<void> {
const { semaphore, finish } = buildSemaphore() const { semaphore, finish } = buildSemaphore()
const msearchBody: Array<T.MsearchMultisearchHeader | T.MsearchMultisearchBody> = [] const msearchBody: Array<T.MsearchMultisearchHeader | T.SearchSearchRequestBody> = []
const callbacks: any[] = [] const callbacks: any[] = []
let loadedOperations = 0 let loadedOperations = 0
timeoutRef = setTimeout(onFlushTimeout, flushInterval) // eslint-disable-line timeoutRef = setTimeout(onFlushTimeout, flushInterval) // eslint-disable-line
@ -490,7 +490,7 @@ export default class Helpers {
} }
} }
function send (msearchBody: Array<T.MsearchMultisearchHeader | T.MsearchMultisearchBody>, callbacks: any[]): void { function send (msearchBody: Array<T.MsearchMultisearchHeader | T.SearchSearchRequestBody>, callbacks: any[]): void {
/* istanbul ignore if */ /* istanbul ignore if */
if (running > concurrency) { if (running > concurrency) {
throw new Error('Max concurrency reached') throw new Error('Max concurrency reached')
@ -508,7 +508,7 @@ export default class Helpers {
} }
} }
function msearchOperation (msearchBody: Array<T.MsearchMultisearchHeader | T.MsearchMultisearchBody>, callbacks: any[], done: () => void): void { function msearchOperation (msearchBody: Array<T.MsearchMultisearchHeader | T.SearchSearchRequestBody>, callbacks: any[], done: () => void): void {
let retryCount = retries let retryCount = retries
// Instead of going full on async-await, which would make the code easier to read, // Instead of going full on async-await, which would make the code easier to read,
@ -516,7 +516,7 @@ export default class Helpers {
// This because every time we use async await, V8 will create multiple promises // This because every time we use async await, V8 will create multiple promises
// behind the scenes, making the code slightly slower. // behind the scenes, making the code slightly slower.
tryMsearch(msearchBody, callbacks, retrySearch) tryMsearch(msearchBody, callbacks, retrySearch)
function retrySearch (msearchBody: Array<T.MsearchMultisearchHeader | T.MsearchMultisearchBody>, callbacks: any[]): void { function retrySearch (msearchBody: Array<T.MsearchMultisearchHeader | T.SearchSearchRequestBody>, callbacks: any[]): void {
if (msearchBody.length > 0 && retryCount > 0) { if (msearchBody.length > 0 && retryCount > 0) {
retryCount -= 1 retryCount -= 1
setTimeout(tryMsearch, wait, msearchBody, callbacks, retrySearch) setTimeout(tryMsearch, wait, msearchBody, callbacks, retrySearch)
@ -528,7 +528,7 @@ export default class Helpers {
// This function never returns an error, if the msearch operation fails, // This function never returns an error, if the msearch operation fails,
// the error is dispatched to all search executors. // the error is dispatched to all search executors.
function tryMsearch (msearchBody: Array<T.MsearchMultisearchHeader | T.MsearchMultisearchBody>, callbacks: any[], done: (msearchBody: Array<T.MsearchMultisearchHeader | T.MsearchMultisearchBody>, callbacks: any[]) => void): void { function tryMsearch (msearchBody: Array<T.MsearchMultisearchHeader | T.SearchSearchRequestBody>, callbacks: any[], done: (msearchBody: Array<T.MsearchMultisearchHeader | T.SearchSearchRequestBody>, callbacks: any[]) => void): void {
client.msearch(Object.assign({}, msearchOptions, { body: msearchBody }), reqOptions as TransportRequestOptionsWithMeta) client.msearch(Object.assign({}, msearchOptions, { body: msearchBody }), reqOptions as TransportRequestOptionsWithMeta)
.then(results => { .then(results => {
const retryBody = [] const retryBody = []