1
1
import { getClient } from './elasticsearch' ;
2
2
import loggerStream from './logger' ;
3
3
import { BodyResponse , ScrolledResponse } from './models/body' ;
4
+ import { ResultRawES } from './models/result' ;
4
5
5
6
const log = ( json :any ) => {
6
7
loggerStream . write ( JSON . stringify ( {
@@ -15,7 +16,7 @@ const isBodyResponse = (body: BodyResponse|ScrolledResponse): body is BodyRespon
15
16
return 'query' in body ;
16
17
}
17
18
18
- export const runRequest = async ( body : BodyResponse | ScrolledResponse , scroll : string ) : Promise < any > => {
19
+ export const runRequest = async ( body : BodyResponse | ScrolledResponse , scroll : string ) : Promise < ResultRawES > => {
19
20
const client = getClient ( ) ;
20
21
let operation = 'unknown' ;
21
22
try {
@@ -52,26 +53,26 @@ export const runRequest = async (body: BodyResponse|ScrolledResponse, scroll: st
52
53
} ) ;
53
54
54
55
return {
56
+ took : 0 ,
55
57
hits : {
56
58
total : {
57
- value : 1
59
+ value : 0
58
60
} ,
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
70
67
} ;
71
68
}
72
69
} ;
73
70
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 > => {
75
76
const client = getClient ( ) ;
76
77
try {
77
78
const response = await client . msearch ( bulkRequest ) ;
0 commit comments