use of org.opensearch.ad.util.RestHandlerUtils in project anomaly-detection by opensearch-project.
the class AbstractAnomalyDetectorActionHandler method checkADNameExists.
protected void checkADNameExists(String detectorId, boolean indexingDryRun) throws IOException {
if (anomalyDetectionIndices.doesAnomalyDetectorIndexExist()) {
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
// src/main/resources/mappings/anomaly-detectors.json#L14
boolQueryBuilder.must(QueryBuilders.termQuery("name.keyword", anomalyDetector.getName()));
if (StringUtils.isNotBlank(detectorId)) {
boolQueryBuilder.mustNot(QueryBuilders.termQuery(RestHandlerUtils._ID, detectorId));
}
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(boolQueryBuilder).timeout(requestTimeout);
SearchRequest searchRequest = new SearchRequest(ANOMALY_DETECTORS_INDEX).source(searchSourceBuilder);
client.search(searchRequest, ActionListener.wrap(searchResponse -> onSearchADNameResponse(searchResponse, detectorId, anomalyDetector.getName(), indexingDryRun), exception -> listener.onFailure(exception)));
} else {
tryIndexingAnomalyDetector(indexingDryRun);
}
}
Aggregations