diff --git a/packages/api/src/elastic/pages.ts b/packages/api/src/elastic/pages.ts index 64e86d63c..60fd7247e 100644 --- a/packages/api/src/elastic/pages.ts +++ b/packages/api/src/elastic/pages.ts @@ -309,7 +309,7 @@ export const getPageByParam = async ( id: body.hits.hits[0]._id, } as Page } catch (e) { - console.error('failed to get pages by param in elastic', e) + console.error('failed to get page by param in elastic', e) return undefined } } @@ -509,3 +509,33 @@ export const countByCreatedAt = async ( return 0 } } + +export const deletePagesByParam = async ( + param: Record +): Promise => { + try { + const params = { + query: { + bool: { + filter: Object.keys(param).map((key) => { + return { + term: { + [key]: param[key as K], + }, + } + }), + }, + }, + } + + const { body } = await client.deleteByQuery({ + index: INDEX_ALIAS, + body: params, + }) + + return body.deleted > 0 + } catch (e) { + console.error('failed to delete pages by param in elastic', e) + return false + } +}