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

33 wiersze
776 B
TypeScript
Czysty Zwykły widok Historia

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