private void deleteKeys(List<ActiveRuleKey> keys) {
   BulkIndexer bulk = new BulkIndexer(esClient, INDEX);
   bulk.start();
   SearchRequestBuilder search =
       esClient
           .prepareSearch(INDEX)
           .setTypes(TYPE_ACTIVE_RULE)
           .setQuery(QueryBuilders.boolQuery().must(termsQuery(FIELD_ACTIVE_RULE_KEY, keys)));
   bulk.addDeletion(search);
   bulk.stop();
 }
 public void deleteProfile(String qualityProfileKey) {
   BulkIndexer bulk = new BulkIndexer(esClient, INDEX);
   bulk.start();
   SearchRequestBuilder search =
       esClient
           .prepareSearch(INDEX)
           .setTypes(TYPE_ACTIVE_RULE)
           .setQuery(
               QueryBuilders.boolQuery()
                   .must(termsQuery(FIELD_ACTIVE_RULE_PROFILE_KEY, qualityProfileKey)));
   bulk.addDeletion(search);
   bulk.stop();
 }
 private static long doIndex(BulkIndexer bulk, Iterator<FileSourcesUpdaterHelper.Row> dbRows) {
   long maxUpdatedAt = 0L;
   bulk.start();
   while (dbRows.hasNext()) {
     FileSourcesUpdaterHelper.Row row = dbRows.next();
     for (UpdateRequest updateRequest : row.getUpdateRequests()) {
       bulk.add(updateRequest);
     }
     maxUpdatedAt = Math.max(maxUpdatedAt, row.getUpdatedAt());
   }
   bulk.stop();
   return maxUpdatedAt;
 }
  private static long doIndex(BulkIndexer bulk, Iterator<ActiveRuleDoc> activeRules) {
    bulk.start();
    long maxDate = 0L;
    while (activeRules.hasNext()) {
      ActiveRuleDoc activeRule = activeRules.next();
      bulk.add(newIndexRequest(activeRule));

      // it's more efficient to sort programmatically than in SQL on some databases (MySQL for
      // instance)
      maxDate = Math.max(maxDate, activeRule.updatedAt());
    }
    bulk.stop();
    return maxDate;
  }
  private long doIndex(long lastUpdatedAt, @Nullable String projectUuid) {
    final BulkIndexer bulk = new BulkIndexer(esClient, INDEX);
    bulk.setLarge(lastUpdatedAt == 0L);

    DbSession dbSession = dbClient.openSession(false);
    try {
      TestResultSetIterator rowIt =
          TestResultSetIterator.create(dbClient, dbSession, lastUpdatedAt, projectUuid);
      long maxUpdatedAt = doIndex(bulk, rowIt);
      rowIt.close();
      return maxUpdatedAt;

    } finally {
      dbSession.close();
    }
  }
 public void deleteByFile(String fileUuid) {
   SearchRequestBuilder searchRequest =
       esClient
           .prepareSearch(INDEX)
           .setTypes(TYPE)
           .setQuery(
               QueryBuilders.filteredQuery(
                   QueryBuilders.matchAllQuery(),
                   FilterBuilders.termFilter(FIELD_FILE_UUID, fileUuid).cache(false)));
   BulkIndexer.delete(esClient, INDEX, searchRequest);
 }
 public void deleteByProject(String projectUuid) {
   SearchRequestBuilder searchRequest =
       esClient
           .prepareSearch(INDEX)
           .setRouting(projectUuid)
           .setTypes(TYPE)
           .setQuery(
               QueryBuilders.filteredQuery(
                   QueryBuilders.matchAllQuery(),
                   FilterBuilders.termFilter(TestIndexDefinition.FIELD_PROJECT_UUID, projectUuid)
                       .cache(false)));
   BulkIndexer.delete(esClient, INDEX, searchRequest);
 }
 private BulkIndexer createBulkIndexer(boolean large) {
   BulkIndexer bulk = new BulkIndexer(esClient, INDEX);
   bulk.setLarge(large);
   return bulk;
 }
Beispiel #9
0
 /**
  * Delete all the documents matching the given search request. This method is blocking. Index is
  * refreshed, so docs are not searchable as soon as method is executed.
  *
  * <p>Note that the parameter indexName could be removed if progress logs are not needed.
  */
 public static void delete(EsClient client, String indexName, SearchRequestBuilder searchRequest) {
   BulkIndexer bulk = new BulkIndexer(client, indexName);
   bulk.start();
   bulk.addDeletion(searchRequest);
   bulk.stop();
 }