@@ -303,6 +303,16 @@ async function createResource (currentUser, resource) {
303303 createdBy : currentUser . handle || currentUser . sub
304304 } , resource ) )
305305
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+
306316 // console.log('Created resource:', ret)
307317
308318 await helper . postEvent ( config . RESOURCE_CREATE_TOPIC , _ . pick ( ret , payloadFields ) )
@@ -347,6 +357,15 @@ async function deleteResource (currentUser, resource) {
347357
348358 await ret . delete ( )
349359
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+
350369 await helper . postEvent ( config . RESOURCE_DELETE_TOPIC , _ . pick ( ret , payloadFields ) )
351370 return ret
352371 } catch ( err ) {
0 commit comments