private boolean purgeDocumentsForStream(final ElasticsearchClient elasticClient, final Long streamId)
            throws LoggedException {
        final List<String> indexNames = getTargetIndexNames(elasticClient, streamId);
        if (indexNames != null && !indexNames.isEmpty()) {
            LOGGER.debug("Purging documents for StreamId {} from indices: {}", streamId, indexNames);
            try {
                // Delete against one index at a time. We don't delete against all indices, as this may cause
                // the cluster limit `search.max_open_scroll_context` to be exceeded.
                for (final String indexName : indexNames) {
                    final DeleteByQueryRequest deleteRequest = DeleteByQueryRequest.of(r -> r
                            .index(indexName)
                            .scrollSize((long) batchSize)
                            .refresh(true)
                            .query(q -> q
                                    .term(t -> t
                                            .field(ElasticIndexConstants.STREAM_ID)
                                            .value(streamId)
                                    )
                            )
                    );

                    final DeleteByQueryResponse deleteResponse = elasticClient.deleteByQuery(deleteRequest);
                    final long tookSeconds = deleteResponse.took() != null
                            ? deleteResponse.took() / 1000
                            : 0;

                    LOGGER.info("Deleted {} documents matching StreamId: {} from index: {}, took {} seconds",
                            deleteResponse.deleted(), streamId, indexName, tookSeconds);
                }
            } catch (IOException e) {
                fatalError("Failed to purge documents for StreamId: " + streamId, e);
                return false;
            }
        }
        return true;
    }
Delete documents from the target index, where the indexed field `StreamId` matches one of the provided IDs
stroom-search/stroom-search-elastic/src/main/java/stroom/search/elastic/indexing/ElasticIndexingFilter.java