Search in sources :

Example 1 with METAALERTS_INDEX

use of org.apache.metron.elasticsearch.dao.ElasticsearchMetaAlertDao.METAALERTS_INDEX in project metron by apache.

the class ElasticsearchMetaAlertUpdateDao method update.

@Override
public Document update(Document update, Optional<String> index) throws IOException {
    if (MetaAlertConstants.METAALERT_TYPE.equals(update.getSensorType())) {
        // We've been passed an update to the meta alert.
        throw new UnsupportedOperationException("Meta alerts cannot be directly updated");
    } else {
        Map<Document, Optional<String>> updates = new HashMap<>();
        updates.put(update, index);
        try {
            // We need to update an alert itself.  Only that portion of the update can be delegated.
            // We still need to get meta alerts potentially associated with it and update.
            SearchResponse response = getMetaAlertsForAlert(update.getGuid());
            Collection<Document> metaAlerts = response.getResults().stream().map(result -> toDocument(result, update.getTimestamp())).collect(Collectors.toList());
            // Each meta alert needs to be updated with the new alert
            for (Document metaAlert : metaAlerts) {
                replaceAlertInMetaAlert(metaAlert, update);
                updates.put(metaAlert, Optional.of(METAALERTS_INDEX));
            }
        } catch (IndexNotFoundException e) {
            List<String> indicesNotFound = e.getMetadata(INDEX_NOT_FOUND_INDICES_KEY);
            // Otherwise throw the exception.
            if (indicesNotFound.size() != 1 || !METAALERTS_INDEX.equals(indicesNotFound.get(0))) {
                throw e;
            }
        }
        // Run the alert's update
        elasticsearchDao.batchUpdate(updates);
        return update;
    }
}
Also used : MetaAlertStatus(org.apache.metron.indexing.dao.metaalert.MetaAlertStatus) MetaAlertConstants(org.apache.metron.indexing.dao.metaalert.MetaAlertConstants) HashMap(java.util.HashMap) QueryBuilders.nestedQuery(org.elasticsearch.index.query.QueryBuilders.nestedQuery) AbstractLuceneMetaAlertUpdateDao(org.apache.metron.indexing.dao.metaalert.lucene.AbstractLuceneMetaAlertUpdateDao) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Map(java.util.Map) SearchResult(org.apache.metron.indexing.dao.search.SearchResult) MetaAlertCreateRequest(org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest) SearchHit(org.elasticsearch.search.SearchHit) Document(org.apache.metron.indexing.dao.update.Document) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) QueryBuilders.boolQuery(org.elasticsearch.index.query.QueryBuilders.boolQuery) ElasticsearchUtils(org.apache.metron.elasticsearch.utils.ElasticsearchUtils) CommentAddRemoveRequest(org.apache.metron.indexing.dao.update.CommentAddRemoveRequest) Collection(java.util.Collection) MetaScores(org.apache.metron.indexing.dao.metaalert.MetaScores) IOException(java.io.IOException) GetRequest(org.apache.metron.indexing.dao.search.GetRequest) ScoreMode(org.apache.lucene.search.join.ScoreMode) Constants(org.apache.metron.common.Constants) Collectors(java.util.stream.Collectors) MetaAlertRetrieveLatestDao(org.apache.metron.indexing.dao.metaalert.MetaAlertRetrieveLatestDao) QueryBuilders.termQuery(org.elasticsearch.index.query.QueryBuilders.termQuery) List(java.util.List) METAALERTS_INDEX(org.apache.metron.elasticsearch.dao.ElasticsearchMetaAlertDao.METAALERTS_INDEX) InvalidCreateException(org.apache.metron.indexing.dao.search.InvalidCreateException) Optional(java.util.Optional) MetaAlertConfig(org.apache.metron.indexing.dao.metaalert.MetaAlertConfig) InnerHitBuilder(org.elasticsearch.index.query.InnerHitBuilder) Collections(java.util.Collections) SearchResponse(org.apache.metron.indexing.dao.search.SearchResponse) Optional(java.util.Optional) HashMap(java.util.HashMap) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) List(java.util.List) Document(org.apache.metron.indexing.dao.update.Document) SearchResponse(org.apache.metron.indexing.dao.search.SearchResponse)

Aggregations

IOException (java.io.IOException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 ScoreMode (org.apache.lucene.search.join.ScoreMode)1 Constants (org.apache.metron.common.Constants)1 METAALERTS_INDEX (org.apache.metron.elasticsearch.dao.ElasticsearchMetaAlertDao.METAALERTS_INDEX)1 ElasticsearchUtils (org.apache.metron.elasticsearch.utils.ElasticsearchUtils)1 MetaAlertConfig (org.apache.metron.indexing.dao.metaalert.MetaAlertConfig)1 MetaAlertConstants (org.apache.metron.indexing.dao.metaalert.MetaAlertConstants)1 MetaAlertCreateRequest (org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest)1 MetaAlertRetrieveLatestDao (org.apache.metron.indexing.dao.metaalert.MetaAlertRetrieveLatestDao)1 MetaAlertStatus (org.apache.metron.indexing.dao.metaalert.MetaAlertStatus)1 MetaScores (org.apache.metron.indexing.dao.metaalert.MetaScores)1 AbstractLuceneMetaAlertUpdateDao (org.apache.metron.indexing.dao.metaalert.lucene.AbstractLuceneMetaAlertUpdateDao)1 GetRequest (org.apache.metron.indexing.dao.search.GetRequest)1