fedicrawl/application/src/Storage/Nodes/deleteDomainNodes.ts

33 wiersze
776 B
TypeScript

import { ElasticClient } from '../ElasticClient'
import nodeIndex from '../Definitions/nodeIndex'
export const deleteDomainNodes = async (
elastic: ElasticClient,
domains: string[]
): Promise<number> => {
await elastic.indices.refresh({ index: nodeIndex })
const result = await elastic.deleteByQuery({
index: nodeIndex,
query: {
bool: {
should: domains.map((domain) => {
return {
regexp: {
domain: {
value: '(.*\\.)?' + domain,
case_insensitive: true
}
}
}
}),
minimum_should_match: 1
}
}
})
console.info('Deleted domain nodes', {
count: result.deleted ?? 0,
domains
})
return result.deleted ?? 0
}