diff --git a/packages/api/src/elastic/labels.ts b/packages/api/src/elastic/labels.ts index 90c930ac2..9ba712701 100644 --- a/packages/api/src/elastic/labels.ts +++ b/packages/api/src/elastic/labels.ts @@ -136,7 +136,7 @@ export const deleteLabelInPages = async ( refresh: ctx.refresh, }) - if (body.updated === 0) return false + console.log('updated pages', body.updated) await ctx.pubsub.entityDeleted(EntityType.LABEL, label, ctx.uid) @@ -146,3 +146,56 @@ export const deleteLabelInPages = async ( return false } } + +export const updateLabelInPage = async ( + label: Label, + ctx: PageContext +): Promise => { + try { + const { body } = await client.updateByQuery({ + index: INDEX_ALIAS, + body: { + script: { + source: `ctx._source.labels.removeIf(h -> h.name == params.label.name); + ctx._source.labels.add(params.label)`, + lang: 'painless', + params: { + label: label, + }, + }, + query: { + bool: { + filter: [ + { + term: { + userId: ctx.uid, + }, + }, + { + nested: { + path: 'labels', + query: { + term: { + 'labels.name': label.name, + }, + }, + }, + }, + ], + }, + }, + }, + refresh: ctx.refresh, + }) + + console.log('updated pages', body.updated) + + await ctx.pubsub.entityUpdated