当前位置: 首页>>代码示例>>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;未经允许,请勿转载。