@@ -303,6 +303,16 @@ async function createResource (currentUser, resource) {
303
303
createdBy : currentUser . handle || currentUser . sub
304
304
} , resource ) )
305
305
306
+ // Create resources in ES
307
+ const esClient = await helper . getESClient ( )
308
+ await esClient . create ( {
309
+ index : config . ES . ES_INDEX ,
310
+ type : config . ES . ES_TYPE ,
311
+ id : ret . id ,
312
+ body : _ . pick ( ret , payloadFields ) ,
313
+ refresh : 'true' // refresh ES so that it is visible for read operations instantly
314
+ } )
315
+
306
316
// console.log('Created resource:', ret)
307
317
308
318
await helper . postEvent ( config . RESOURCE_CREATE_TOPIC , _ . pick ( ret , payloadFields ) )
@@ -347,6 +357,15 @@ async function deleteResource (currentUser, resource) {
347
357
348
358
await ret . delete ( )
349
359
360
+ // delete from ES
361
+ const esClient = await helper . getESClient ( )
362
+ await esClient . delete ( {
363
+ index : config . ES . ES_INDEX ,
364
+ type : config . ES . ES_TYPE ,
365
+ id : ret . id ,
366
+ refresh : 'true' // refresh ES so that it is effective for read operations instantly
367
+ } )
368
+
350
369
await helper . postEvent ( config . RESOURCE_DELETE_TOPIC , _ . pick ( ret , payloadFields ) )
351
370
return ret
352
371
} catch ( err ) {
0 commit comments