當前位置: 首頁>>代碼示例>>Java>>正文


Java DeleteRequestBuilder類代碼示例

本文整理匯總了Java中org.elasticsearch.action.delete.DeleteRequestBuilder的典型用法代碼示例。如果您正苦於以下問題:Java DeleteRequestBuilder類的具體用法?Java DeleteRequestBuilder怎麽用?Java DeleteRequestBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DeleteRequestBuilder類屬於org.elasticsearch.action.delete包,在下文中一共展示了DeleteRequestBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: batchDelete

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
/**
 * 批量刪除
 *
 * @param transportClient
 */
private static void batchDelete(TransportClient transportClient) throws IOException {
	BulkRequestBuilder bulkRequestBuilder = transportClient.prepareBulk();

	DeleteRequestBuilder deleteRequestBuilder1 = transportClient.prepareDelete("product_index", "product", "1");
	DeleteRequestBuilder deleteRequestBuilder2 = transportClient.prepareDelete("product_index", "product", "2");
	DeleteRequestBuilder deleteRequestBuilder3 = transportClient.prepareDelete("product_index", "product", "3");

	bulkRequestBuilder.add(deleteRequestBuilder1);
	bulkRequestBuilder.add(deleteRequestBuilder2);
	bulkRequestBuilder.add(deleteRequestBuilder3);

	BulkResponse bulkResponse = bulkRequestBuilder.get();
	for (BulkItemResponse bulkItemResponse : bulkResponse.getItems()) {
		logger.info("--------------------------------version= " + bulkItemResponse.getVersion());
	}

}
 
開發者ID:judasn,項目名稱:Elasticsearch-Tutorial-zh-CN,代碼行數:23,代碼來源:BaseDemo.java

示例2: execute

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
/**
 * Executes the list with requests as a bulk with maximum number of requests per bulk
 * @param requests
 * @param maxRequestsPerBulk
 * @return
 * @throws SQLException
 */
private int execute(List<?> requests, int maxRequestsPerBulk) throws SQLException{
	int result = 0;
	BulkRequestBuilder bulkReq = client.prepareBulk();
	for(Object req : requests){
		if(req instanceof IndexRequest)	bulkReq.add((IndexRequest)req);
		else if(req instanceof UpdateRequest) bulkReq.add((UpdateRequest)req);
		else if(req instanceof DeleteRequest) bulkReq.add((DeleteRequest)req);
		else if(req instanceof IndexRequestBuilder) bulkReq.add((IndexRequestBuilder)req);
		else if(req instanceof UpdateRequestBuilder) bulkReq.add((UpdateRequestBuilder)req);
		else if(req instanceof DeleteRequestBuilder) bulkReq.add((DeleteRequestBuilder)req);
		else throw new SQLException("Type "+req.getClass()+" cannot be added to a bulk request");
		
		if(bulkReq.numberOfActions() > maxRequestsPerBulk){
			result += bulkReq.get().getItems().length;
			bulkReq = client.prepareBulk();
		}
	}
	
	if(bulkReq.numberOfActions() > 0){
		result += bulkReq.get().getItems().length;
	}
	return result;
}
 
開發者ID:Anchormen,項目名稱:sql4es,代碼行數:31,代碼來源:ESUpdateState.java

示例3: removeTransaction

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
@Override
public void removeTransaction(String tenantId, String name) throws Exception {
    TransactionConfig config = new TransactionConfig();
    config.setDeleted(true);
    config.setLastUpdated(clock.millis());

    // Remove valid version of the transaction config
    IndexRequestBuilder builder = client.getClient().prepareIndex(client.getIndex(tenantId),
            TXN_CONFIG_TYPE, name).setRouting(name)
            .setSource(mapper.writeValueAsString(config));

    builder.execute().actionGet();

    // Remove invalid version of the transaction config, which may or may not exist
    DeleteRequestBuilder deletion = client.getClient().prepareDelete(client.getIndex(tenantId),
            TXN_CONFIG_INVALID_TYPE, name);

    deletion.execute().actionGet();

    if (msgLog.isTraceEnabled()) {
        msgLog.tracef("Remove transaction config with name[%s]", name);
    }
}
 
開發者ID:hawkular,項目名稱:hawkular-apm,代碼行數:24,代碼來源:ConfigurationServiceElasticsearch.java

示例4: unindex

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
@Override
public void unindex(String appid, ParaObject po) {
	if (po == null || StringUtils.isBlank(po.getId()) || StringUtils.isBlank(appid)) {
		return;
	}
	try {
		DeleteRequestBuilder drb = client().prepareDelete(getIndexName(appid), getType(), po.getId());
		ActionListener<DeleteResponse> responseHandler = ElasticSearchUtils.getIndexResponseHandler();
		if (isAsyncEnabled()) {
			drb.execute(responseHandler);
		} else {
			responseHandler.onResponse(drb.execute().actionGet());
		}
		logger.debug("Search.unindex() {}", po.getId());
	} catch (Exception e) {
		logger.warn(null, e);
	}
}
 
開發者ID:Erudika,項目名稱:para-search-elasticsearch,代碼行數:19,代碼來源:ElasticSearch.java

示例5: testDeleteNotFound

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
@Test
public void testDeleteNotFound() throws Exception {
    String id = "1";
    DeleteRequestBuilder mockDeleteRequestBuilder = mock(DeleteRequestBuilder.class);
    ListenableActionFuture mockListenableActionFuture = mock(ListenableActionFuture.class);
    DeleteResponse mockDeleteResponse = mock(DeleteResponse.class);

    when(client.prepareDelete("steckbrief", "steckbrief", id)).thenReturn(mockDeleteRequestBuilder);
    when(mockDeleteRequestBuilder.execute()).thenReturn(mockListenableActionFuture);
    when(mockListenableActionFuture.actionGet()).thenReturn(mockDeleteResponse);
    when(mockDeleteResponse.isFound()).thenReturn(false);

    ResponseEntity response = documentController.delete(id);

    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
 
開發者ID:pivio,項目名稱:pivio-server,代碼行數:17,代碼來源:DocumentControllerTest.java

示例6: run

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
@Override
public void run() {
    SearchResponse searchResponse = client.prepareSearch(searchIndex)
            .setTypes("Document")
            .setQuery(QueryBuilders.boolQuery()
                    .mustNot(QueryBuilders.hasChildQuery("DocumentInSystem", QueryBuilders.matchAllQuery())))
            .setSize(9999)
            .get();

    BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
    for (SearchHit searchHit : searchResponse.getHits().hits()) {
        DeleteRequestBuilder delete = client.prepareDelete(searchIndex, "Document", searchHit.getId());
        bulkRequestBuilder.add(delete);
    }

    if (bulkRequestBuilder.numberOfActions() > 0) {
        bulkRequestBuilder.get();
    }
}
 
開發者ID:nlpie,項目名稱:nlptab,代碼行數:20,代碼來源:DeleteOrphanedDocuments.java

示例7: deleteSeries

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
@Override
public AsyncFuture<DeleteSeries> deleteSeries(final DeleteSeries.Request request) {
    final DateRange range = request.getRange();

    final FindSeriesIds.Request findIds =
        new FindSeriesIds.Request(request.getFilter(), range, request.getLimit());

    return doto(c -> findSeriesIds(findIds).lazyTransform(ids -> {
        final List<Callable<AsyncFuture<Void>>> deletes = new ArrayList<>();

        for (final String id : ids.getIds()) {
            deletes.add(() -> {
                final List<DeleteRequestBuilder> requests = c.delete(TYPE_METADATA, id);

                return async.collectAndDiscard(requests
                    .stream()
                    .map(ActionRequestBuilder::execute)
                    .map(this::bind)
                    .collect(Collectors.toList()));
            });
        }

        return async.eventuallyCollect(deletes, newDeleteCollector(), deleteParallelism);
    }));
}
 
開發者ID:spotify,項目名稱:heroic,代碼行數:26,代碼來源:MetadataBackendKV.java

示例8: getDeleteRequest

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
private DeleteRequestBuilder getDeleteRequest(Object object) {
    String typeName = MappingProcessor.getIndexTypeName(object.getClass());
    Object objectId = objectProcessor.getIdValue(object);
    if (objectId == null) {
        throw new ElasticSearchOsemException("Unable to find object id");
    }
    logger.debug("Get delete object request, type:{}, id: {}", typeName, objectId);
    DeleteRequestBuilder deleteRequestBuilder = client.prepareDelete(getIndexName(), typeName, objectId.toString());
    String routing = objectProcessor.getRoutingId(object);
    if (routing != null) {
        deleteRequestBuilder.setRouting(routing);
    }
    String parent = objectProcessor.getParentId(object);
    if (parent != null) {
        deleteRequestBuilder.setParent(parent);
    }
    return deleteRequestBuilder;
}
 
開發者ID:kzwang,項目名稱:elasticsearch-osem,代碼行數:19,代碼來源:ElasticSearchIndexerImpl.java

示例9: deleteDocument

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
@Override
public void deleteDocument(SearchContext searchContext, String uid)
        throws SearchException {

    try {
        Client client = getClient();

        DeleteRequestBuilder deleteRequestBuilder = client.prepareDelete(
                Utilities.getIndexName(searchContext),
                "documents", uid);

        Future<DeleteResponse> future = deleteRequestBuilder.execute();

        DeleteResponse deleteResponse = future.get();

    } catch (Exception e) {
        throw new SearchException("Unable to delete document " + uid, e);
    }
}
 
開發者ID:R-Knowsys,項目名稱:elasticray,代碼行數:20,代碼來源:ElasticsearchIndexWriter.java

示例10: delete

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
/**
 * 刪除索引.
 * http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-delete.html
 * @param typeName
 * @param id
 * @return
 */
public boolean delete(String typeName, String id)  throws SearchException {
       Timer.Context timer = searchMetrics.indexTimer(typeName, "delId");
	try {
		DeleteRequestBuilder deleter = client.prepareDelete(indexName,
				typeName, id);
		DeleteResponse actionGet = deleter.execute().actionGet();
           searchMetrics.indexIncr(typeName, "delId");
		if (!actionGet.isNotFound()) {
			return true;
		}
		return false;
	} catch (Exception e) {
           searchMetrics.failedIncr(typeName, "delId", e);
           logger.error("delete index Error. ", e);
           throw new SearchException("delete index Error. typeName="+typeName+", id="+id, e);
	}finally {
           timer.stop();
       }
   }
 
開發者ID:yamingd,項目名稱:argo,代碼行數:27,代碼來源:ElasticSearchTemplate.java

示例11: executeDeleteRequest

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
private void executeDeleteRequest(final StreamInput streamInput, final DeleteRequestBuilder builder) {
    builder.execute(wrap(res -> {
        processRequests(streamInput);
        // continue
    }, e -> {
        if (senderRequestRetryCount >= 0) {
            if (requestErrorCount > senderRequestRetryCount) {
                logger.error("[Sender][" + index + "][" + requestErrorCount + "] Failed to delete [" + builder.request().index() + "]["
                        + builder.request().type() + "][" + builder.request().id() + "]", e);
                requestErrorCount = 0;
                writeError(requestPosition, builder.request(), wrap(r -> processRequests(streamInput), ex -> {
                    logger.warn("[Sender][" + index + "] Failed to store an error request.", ex);
                    processRequests(streamInput);
                }));
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("[" + requestErrorCount + "] Failed to delete [" + builder.request().index() + "]["
                            + builder.request().type() + "][" + builder.request().id() + "]", e);
                }
                requestErrorCount++;
                executeDeleteRequest(streamInput, builder);
            }
        } else {
            IOUtils.closeQuietly(streamInput);
            retryWithError("Failed to delete (" + builder.request() + ")", e);
            // retry
        }
    }));
}
 
開發者ID:codelibs,項目名稱:elasticsearch-indexing-proxy,代碼行數:30,代碼來源:RequestSender.java

示例12: createDeleteRequest

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
public static DeleteRequestBuilder createDeleteRequest(final Client client, final StreamInput streamInput, final String index)
        throws IOException {
    final DeleteRequestBuilder builder = client.prepareDelete();
    final DeleteRequest request = builder.request();
    request.readFrom(streamInput);
    if (index != null) {
        request.index(index);
    }
    return builder;
}
 
開發者ID:codelibs,項目名稱:elasticsearch-indexing-proxy,代碼行數:11,代碼來源:RequestUtils.java

示例13: delete

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
@Override
public void delete(String key) throws IOException {
  try {
    DeleteRequestBuilder builder = client.prepareDelete();
    builder.setIndex(defaultIndex);
    builder.setType("doc");
    builder.setId(key);
    builder.execute().actionGet();
  } catch (ElasticsearchException e) {
    throw makeIOException(e);
  }
}
 
開發者ID:jorcox,項目名稱:GeoCrawler,代碼行數:13,代碼來源:ElasticIndexWriter.java

示例14: call

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
@Override
public Observable<Optional<PersistentServiceDef>> call(final PersistentServiceDef persistentServiceDef) {

    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

    final String id = persistentServiceDef.getId();

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Request {%s,%s,%s}", elasticSearch.defaultType(), elasticSearch.serviceDefTypeIndex(), id));
    }


    DeleteRequestBuilder request =
            elasticSearch.get()
                    .prepareDelete(
                            elasticSearch.serviceDefTypeIndex(),
                            elasticSearch.defaultType(),
                            id)
                    .setTimeout(timeValueMillis(elasticSearch.getDefaultDeleteTimeout() - 10))
                    .setVersion(persistentServiceDef.getVersion());

    return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultDeleteTimeout())
            .map(new Func1<Optional<DeleteResponse>, Optional<PersistentServiceDef>>() {
                @Override
                public Optional<PersistentServiceDef> call(Optional<DeleteResponse> oDeleteResponse) {
                    if (oDeleteResponse.isPresent()) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug(format("Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.serviceDefTypeIndex(), id, Jsonify.toString(oDeleteResponse.get())));
                        }
                        return fromNullable(persistentServiceDef);
                    } else {
                        LOGGER.debug(format("Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.serviceDefTypeIndex(), id, "null"));
                        return absent();
                    }
                }
            });
}
 
開發者ID:pitchpoint-solutions,項目名稱:sfs,代碼行數:38,代碼來源:DeleteServiceDef.java

示例15: call

import org.elasticsearch.action.delete.DeleteRequestBuilder; //導入依賴的package包/類
@Override
public Observable<Optional<PersistentAccount>> call(PersistentAccount persistentAccount) {
    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Remove Request {%s,%s,%s,%d}", elasticSearch.defaultType(), elasticSearch.accountIndex(), persistentAccount.getId(), persistentAccount.getPersistentVersion()));
    }


    DeleteRequestBuilder request =
            elasticSearch.get()
                    .prepareDelete(
                            elasticSearch.accountIndex(),
                            elasticSearch.defaultType(),
                            persistentAccount.getId())
                    .setTimeout(timeValueMillis(elasticSearch.getDefaultDeleteTimeout() - 10))
                    .setVersion(persistentAccount.getPersistentVersion());

    return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultDeleteTimeout())
            .map(oDeleteResponse -> {
                if (oDeleteResponse.isPresent()) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Remove Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.accountIndex(), persistentAccount.getId(), persistentAccount.getPersistentVersion(), Jsonify.toString(oDeleteResponse.get())));
                    }
                    return of(persistentAccount);
                } else {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Remove Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.accountIndex(), persistentAccount.getId(), persistentAccount.getPersistentVersion(), "null"));
                    }
                    return absent();
                }
            });
}
 
開發者ID:pitchpoint-solutions,項目名稱:sfs,代碼行數:34,代碼來源:RemoveAccount.java


注:本文中的org.elasticsearch.action.delete.DeleteRequestBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。