Skip to content

Commit d8d5d32

Browse files
committed
✨ Use typings in runRequest elasticsearch
1 parent 5519434 commit d8d5d32

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

backend/src/runRequest.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getClient } from './elasticsearch';
22
import loggerStream from './logger';
33
import { BodyResponse, ScrolledResponse } from './models/body';
4+
import { ResultRawES } from './models/result';
45

56
const log = (json:any) => {
67
loggerStream.write(JSON.stringify({
@@ -15,7 +16,7 @@ const isBodyResponse = (body: BodyResponse|ScrolledResponse): body is BodyRespon
1516
return 'query' in body;
1617
}
1718

18-
export const runRequest = async (body: BodyResponse|ScrolledResponse, scroll: string): Promise<any> => {
19+
export const runRequest = async (body: BodyResponse|ScrolledResponse, scroll: string): Promise<ResultRawES> => {
1920
const client = getClient();
2021
let operation = 'unknown';
2122
try {
@@ -52,26 +53,26 @@ export const runRequest = async (body: BodyResponse|ScrolledResponse, scroll: st
5253
});
5354

5455
return {
56+
took: 0,
5557
hits: {
5658
total: {
57-
value: 1
59+
value: 0
5860
},
59-
hits: [
60-
{
61-
_id: 0,
62-
_source: {
63-
status: error.statusCode || 500,
64-
statusText: error.message || 'Internal Server Error',
65-
error: true
66-
}
67-
}
68-
]
69-
}
61+
max_score: 0,
62+
hits: []
63+
},
64+
status: error.statusCode || 500,
65+
statusText: error.message || 'Internal Server Error',
66+
error: true
7067
};
7168
}
7269
};
7370

74-
export const runBulkRequest = async (bulkRequest: any): Promise<any> => {
71+
interface ResultBulkES {
72+
responses: ResultRawES[];
73+
}
74+
75+
export const runBulkRequest = async (bulkRequest: any): Promise<ResultBulkES> => {
7576
const client = getClient();
7677
try {
7778
const response = await client.msearch(bulkRequest);

0 commit comments

Comments
 (0)