@@ -61,7 +61,7 @@ export interface IElasticModelConfig {
61
61
excludedFields ?: string [ ] ;
62
62
}
63
63
64
- export class ElasticModel < T extends Item > {
64
+ class ElasticModel < T extends Item > {
65
65
client : Client ;
66
66
protected index : string ;
67
67
protected idField : string ;
@@ -123,9 +123,12 @@ export class ElasticModel<T extends Item> {
123
123
body : query
124
124
} ;
125
125
const response = await this . client . search < T > ( params ) ;
126
- // @ts -ignore
127
- const total =
128
- typeof response . hits . total === 'number' ? response . hits . total : response . hits . total . value ;
126
+ let total : number ;
127
+ if ( typeof response . hits . total === 'number' ) {
128
+ total = response . hits . total ;
129
+ } else {
130
+ total = ( response . hits . total as { value : number } ) . value ;
131
+ }
129
132
return {
130
133
items : response . hits . hits . map ( hit => hit . _source ) ,
131
134
total,
@@ -139,7 +142,7 @@ export class ElasticModel<T extends Item> {
139
142
* read more - https://www.npmjs.com/package/bodybuilder
140
143
* Call query.exec at the end to execute the query
141
144
*/
142
- buildQuery ( ) : IBodyBuilder < T > {
145
+ queryBuilder ( ) : IBodyBuilder < T > {
143
146
const self = this ;
144
147
const query = ( bodyBuilder ( ) as unknown ) as IBodyBuilder < T > ;
145
148
query . exec = function ( ) {
@@ -211,7 +214,6 @@ export class ElasticModel<T extends Item> {
211
214
async createIndexIfMissing ( ) {
212
215
// check if index already exists
213
216
const indexExists = await this . client . indices . exists ( { index : this . index } ) ;
214
- console . log ( { indexExists} ) ;
215
217
if ( indexExists ) return true ;
216
218
217
219
const params : IndicesCreateParams = { index : this . index , body : { } } ;
@@ -224,8 +226,8 @@ export class ElasticModel<T extends Item> {
224
226
params . body . settings = this . settings ;
225
227
}
226
228
227
- console . log ( JSON . stringify ( params , null , 2 ) ) ;
228
-
229
229
return this . client . indices . create ( params ) ;
230
230
}
231
231
}
232
+
233
+ export default ElasticModel ;
0 commit comments