org.elasticsearch.action.delete.DeleteRequestBuilder Java Examples

The following examples show how to use org.elasticsearch.action.delete.DeleteRequestBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ESRequestMapperTest.java    From syncer with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static void remoteCheck(AbstractClient client, List<Object> builderList) throws ExecutionException, InterruptedException {
  for (Object builder : builderList) {
    BulkRequestBuilder bulkRequestBuilder = null;
    if (builder instanceof IndexRequestBuilder) {
      bulkRequestBuilder = client.prepareBulk().add((IndexRequestBuilder) builder);
    } else if (builder instanceof UpdateRequestBuilder) {
      bulkRequestBuilder = client.prepareBulk().add((UpdateRequestBuilder) builder);
    }  else if (builder instanceof DeleteRequestBuilder) {
      bulkRequestBuilder = client.prepareBulk().add((DeleteRequestBuilder) builder);
    } else {
      fail();
    }
    BulkResponse bulkItemResponses = bulkRequestBuilder.execute().get();
    assertFalse(Arrays.stream(bulkItemResponses.getItems()).anyMatch(BulkItemResponse::isFailed));
  }
}
 
Example #2
Source File: BaseDemo.java    From Elasticsearch-Tutorial-zh-CN with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 批量删除
 *
 * @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());
	}

}
 
Example #3
Source File: DefaultElasticSearchService.java    From vertx-elasticsearch-service with Apache License 2.0 6 votes vote down vote up
@Override
public void delete(String index, String type, String id, DeleteOptions options, Handler<AsyncResult<com.hubrick.vertx.elasticsearch.model.DeleteResponse>> resultHandler) {

    final DeleteRequestBuilder builder = client.prepareDelete(index, type, id);
    populateDeleteRequestBuilder(builder, options);

    builder.execute(new ActionListener<DeleteResponse>() {
        @Override
        public void onResponse(DeleteResponse deleteResponse) {
            resultHandler.handle(Future.succeededFuture(mapToDeleteResponse(deleteResponse)));
        }

        @Override
        public void onFailure(Exception t) {
            handleFailure(resultHandler, t);
        }
    });

}
 
Example #4
Source File: ESUpdateState.java    From sql4es with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: FessEsClient.java    From fess with Apache License 2.0 5 votes vote down vote up
public boolean delete(final String index, final String id, final Number seqNo, final Number primaryTerm) {
    try {
        final DeleteRequestBuilder builder = client.prepareDelete().setIndex(index).setId(id).setRefreshPolicy(RefreshPolicy.IMMEDIATE);
        if (seqNo != null) {
            builder.setIfSeqNo(seqNo.longValue());
        }
        if (primaryTerm != null) {
            builder.setIfPrimaryTerm(primaryTerm.longValue());
        }
        final DeleteResponse response = builder.execute().actionGet(ComponentUtil.getFessConfig().getIndexDeleteTimeout());
        return response.getResult() == Result.DELETED;
    } catch (final ElasticsearchException e) {
        throw new FessEsClientException("Failed to delete: " + index + "/" + id + "@" + seqNo + ":" + primaryTerm, e);
    }
}
 
Example #6
Source File: ModelsAction.java    From zentity with Apache License 2.0 5 votes vote down vote up
/**
 * Delete one entity model by its type.
 *
 * @param entityType The entity type.
 * @param client     The client that will communicate with Elasticsearch.
 * @return The response from Elasticsearch.
 * @throws ForbiddenException
 */
private static DeleteResponse deleteEntityModel(String entityType, NodeClient client) throws ForbiddenException {
    DeleteRequestBuilder request = client.prepareDelete(INDEX_NAME, "doc", entityType);
    request.setRefreshPolicy("wait_for");
    try {
        return request.get();
    } catch (IndexNotFoundException e) {
        try {
            SetupAction.createIndex(client);
        } catch (ElasticsearchSecurityException se) {
            throw new ForbiddenException("The .zentity-models index does not exist and you do not have the 'create_index' privilege. An authorized user must create the index by submitting: POST _zentity/_setup");
        }
        return request.get();
    }
}
 
Example #7
Source File: RemoveContainer.java    From sfs with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<Optional<PersistentContainer>> call(PersistentContainer persistentContainer) {
    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

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


    DeleteRequestBuilder request =
            elasticSearch.get()
                    .prepareDelete(
                            elasticSearch.containerIndex(),
                            elasticSearch.defaultType(),
                            persistentContainer.getId())
                    .setTimeout(timeValueMillis(elasticSearch.getDefaultDeleteTimeout() - 10))
                    .setVersion(persistentContainer.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.containerIndex(), persistentContainer.getId(), persistentContainer.getPersistentVersion(), Jsonify.toString(oDeleteResponse.get())));
                    }
                    return of(persistentContainer);
                } else {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Remove Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), persistentContainer.getId(), persistentContainer.getPersistentVersion(), "null"));
                    }
                    return absent();
                }
            });
}
 
Example #8
Source File: RemoveObject.java    From sfs with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<Optional<PersistentObject>> call(PersistentObject persistentObject) {
    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

    PersistentContainer persistentContainer = persistentObject.getParent();

    String objectIndex = elasticSearch.objectIndex(persistentContainer.getName());

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


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

    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(), objectIndex, persistentObject.getId(), persistentObject.getPersistentVersion(), Jsonify.toString(oDeleteResponse.get())));
                    }
                    return of(persistentObject);
                } else {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Remove Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), objectIndex, persistentObject.getId(), persistentObject.getPersistentVersion(), "null"));
                    }
                    return absent();
                }
            });
}
 
Example #9
Source File: RemoveContainerKey.java    From sfs with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<Optional<PersistentContainerKey>> call(PersistentContainerKey persistentContainerKey) {
    final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch();

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


    DeleteRequestBuilder request =
            elasticSearch.get()
                    .prepareDelete(
                            elasticSearch.containerKeyIndex(),
                            elasticSearch.defaultType(),
                            persistentContainerKey.getId())
                    .setTimeout(timeValueMillis(elasticSearch.getDefaultDeleteTimeout() - 10))
                    .setVersion(persistentContainerKey.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.containerKeyIndex(), persistentContainerKey.getId(), persistentContainerKey.getPersistentVersion(), Jsonify.toString(oDeleteResponse.get())));
                    }
                    return of(persistentContainerKey);
                } else {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(format("Remove Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerKeyIndex(), persistentContainerKey.getId(), persistentContainerKey.getPersistentVersion(), "null"));
                    }
                    return absent();
                }
            });
}
 
Example #10
Source File: BaseElasticSearchIndexBuilder.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected void deleteDocumentWithParams(Map<String, Object> deleteParams) {
    final DeleteRequestBuilder deleteRequestBuilder = prepareDeleteDocument(deleteParams);
    final DeleteResponse deleteResponse = deleteDocumentWithRequest(deleteRequestBuilder);

    if (getLog().isDebugEnabled()) {
        if (!deleteResponse.isFound()) {
            getLog().debug("Could not delete doc with by id: " + deleteParams.get(DELETE_RESOURCE_KEY_DOCUMENT_ID)
                    + " in index builder [" + getName() + "] because the document wasn't found");
        } else {
            getLog().debug("ES deleted a doc with id: " + deleteResponse.getId() + " in index builder ["
                    + getName() + "]");
        }
    }
}
 
Example #11
Source File: InternalEsClient.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * バルクリクエストのDELETEリクエストを作成する.
 * @param index インデックス名
 * @param routingId ルーティングID
 * @param data バルクドキュメント情報
 * @return 作成したDELETEリクエスト
 */
private DeleteRequestBuilder createDeleteRequest(String index, String routingId, EsBulkRequest data) {
    DeleteRequestBuilder request = esTransportClient.prepareDelete(index, data.getType(), data.getId());
    if (routingFlag) {
        request = request.setRouting(routingId);
    }
    return request;
}
 
Example #12
Source File: EsAbstractBehavior.java    From fess with Apache License 2.0 5 votes vote down vote up
@Override
protected int delegateDelete(final Entity entity, final DeleteOption<? extends ConditionBean> option) {
    final EsAbstractEntity esEntity = (EsAbstractEntity) entity;
    final DeleteRequestBuilder builder = createDeleteRequest(esEntity);

    final DeleteResponse response = builder.execute().actionGet(deleteTimeout);
    return response.getResult() == Result.DELETED ? 1 : 0;
}
 
Example #13
Source File: InternalEsClient.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * バルクリクエストのDELETEリクエストを作成する.
 * @param index インデックス名
 * @param routingId ルーティングID
 * @param data バルクドキュメント情報
 * @return 作成したDELETEリクエスト
 */
private DeleteRequestBuilder createDeleteRequest(String index, String routingId, EsBulkRequest data) {
    DeleteRequestBuilder request = esTransportClient.prepareDelete(index, data.getType(), data.getId());
    if (routingFlag) {
        request = request.setRouting(routingId);
    }
    return request;
}
 
Example #14
Source File: ElasticsearchClusterRunner.java    From elasticsearch-cluster-runner with Apache License 2.0 5 votes vote down vote up
@Deprecated
public DeleteResponse delete(final String index, final String type, final String id,
        final BuilderCallback<DeleteRequestBuilder> builder) {
    final DeleteResponse actionGet = builder.apply(client().prepareDelete(index, type, id)).execute().actionGet();
    if (actionGet.getResult() != Result.DELETED) {
        onFailure("Failed to delete " + id + " from " + index + "/" + type + ".", actionGet);
    }
    return actionGet;
}
 
Example #15
Source File: ElasticsearchClusterRunner.java    From elasticsearch-cluster-runner with Apache License 2.0 5 votes vote down vote up
public DeleteResponse delete(final String index, final String id,
        final BuilderCallback<DeleteRequestBuilder> builder) {
    final DeleteResponse actionGet = builder.apply(client().prepareDelete().setIndex(index).setId(id)).execute().actionGet();
    if (actionGet.getResult() != Result.DELETED) {
        onFailure("Failed to delete " + id + " from " + index + ".", actionGet);
    }
    return actionGet;
}
 
Example #16
Source File: QuestionElasticSearchIndexBuilder.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
protected void deleteDocumentWithParams(Map<String, Object> deleteParams) {
    final DeleteRequestBuilder deleteRequestBuilder = prepareDeleteDocument(deleteParams);
    final DeleteResponse deleteResponse = deleteDocumentWithRequest(deleteRequestBuilder);
    if (getLog().isDebugEnabled()) {
        if (!deleteResponse.isFound()) {
            getLog().debug("Could not delete doc with by id: " + deleteParams.get(DELETE_RESOURCE_KEY_ITEM)
                    + " in index builder [" + getName() + "] because the document wasn't found");
        } else {
            getLog().debug("ES deleted a doc with id: " + deleteResponse.getId() + " in index builder ["
                    + getName() + "]");
        }
    }
}
 
Example #17
Source File: BaseElasticSearchIndexBuilder.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected void deleteDocumentWithParams(Map<String, Object> deleteParams) {
    final DeleteRequestBuilder deleteRequestBuilder = prepareDeleteDocument(deleteParams);
    final DeleteResponse deleteResponse = deleteDocumentWithRequest(deleteRequestBuilder);

    if (getLog().isDebugEnabled()) {
        if (!deleteResponse.isFound()) {
            getLog().debug("Could not delete doc with by id: " + deleteParams.get(DELETE_RESOURCE_KEY_DOCUMENT_ID)
                    + " in index builder [" + getName() + "] because the document wasn't found");
        } else {
            getLog().debug("ES deleted a doc with id: " + deleteResponse.getId() + " in index builder ["
                    + getName() + "]");
        }
    }
}
 
Example #18
Source File: TestDeleteElasticsearch5.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException {
    currentTimeMillis = System.currentTimeMillis();
    documentId = String.valueOf(currentTimeMillis);
    mockDeleteProcessor = new DeleteElasticsearch5() {

        @Override
        protected DeleteRequestBuilder prepareDeleteRequest(String index, String docId, String docType) {
            return null;
        }

        @Override
        protected DeleteResponse doDelete(DeleteRequestBuilder requestBuilder)
                throws InterruptedException, ExecutionException {
            return deleteResponse;
        }

        @Override
        public void setup(ProcessContext context) {
        }

    };

    runner = TestRunners.newTestRunner(mockDeleteProcessor);

    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.CLUSTER_NAME, "elasticsearch");
    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.HOSTS, "127.0.0.1:9300");
    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.PING_TIMEOUT, "5s");
    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.SAMPLER_INTERVAL, "5s");

    runner.setProperty(DeleteElasticsearch5.INDEX, INDEX1);
    runner.assertNotValid();
    runner.setProperty(DeleteElasticsearch5.TYPE, TYPE1);
    runner.assertNotValid();
    runner.setProperty(DeleteElasticsearch5.DOCUMENT_ID, "${documentId}");
    runner.assertValid();
}
 
Example #19
Source File: ElasticIndexWriter.java    From nutch-htmlunit with Apache License 2.0 5 votes vote down vote up
@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);
  }
}
 
Example #20
Source File: EsAbstractBehavior.java    From fess with Apache License 2.0 5 votes vote down vote up
protected DeleteRequestBuilder createDeleteRequest(final EsAbstractEntity esEntity) {
    final DeleteRequestBuilder builder = client.prepareDelete().setIndex(asEsIndex()).setId(esEntity.asDocMeta().id());
    final RequestOptionCall<DeleteRequestBuilder> deleteOption = esEntity.asDocMeta().deleteOption();
    if (deleteOption != null) {
        deleteOption.callback(builder);
    }
    return builder;
}
 
Example #21
Source File: DeIndexOperation.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public void doOperation( final Client client, final BulkRequestBuilder bulkRequest ) {


    for ( final String index : indexes ) {
        final DeleteRequestBuilder builder =
                client.prepareDelete( index, IndexingUtils.ES_ENTITY_TYPE, documentId );
        bulkRequest.add( builder );
    }
}
 
Example #22
Source File: EsAbstractBehavior.java    From fess with Apache License 2.0 5 votes vote down vote up
@Override
protected int delegateDelete(final Entity entity, final DeleteOption<? extends ConditionBean> option) {
    final EsAbstractEntity esEntity = (EsAbstractEntity) entity;
    final DeleteRequestBuilder builder = createDeleteRequest(esEntity);

    final DeleteResponse response = builder.execute().actionGet(deleteTimeout);
    return response.getResult() == Result.DELETED ? 1 : 0;
}
 
Example #23
Source File: EsAbstractBehavior.java    From fess with Apache License 2.0 5 votes vote down vote up
protected DeleteRequestBuilder createDeleteRequest(final EsAbstractEntity esEntity) {
    final DeleteRequestBuilder builder = client.prepareDelete().setIndex(asEsIndex()).setId(esEntity.asDocMeta().id());
    final RequestOptionCall<DeleteRequestBuilder> deleteOption = esEntity.asDocMeta().deleteOption();
    if (deleteOption != null) {
        deleteOption.callback(builder);
    }
    return builder;
}
 
Example #24
Source File: EsAbstractBehavior.java    From fess with Apache License 2.0 5 votes vote down vote up
@Override
protected int delegateDelete(final Entity entity, final DeleteOption<? extends ConditionBean> option) {
    final EsAbstractEntity esEntity = (EsAbstractEntity) entity;
    final DeleteRequestBuilder builder = createDeleteRequest(esEntity);

    final DeleteResponse response = builder.execute().actionGet(deleteTimeout);
    return response.getResult() == Result.DELETED ? 1 : 0;
}
 
Example #25
Source File: EsAbstractBehavior.java    From fess with Apache License 2.0 5 votes vote down vote up
protected DeleteRequestBuilder createDeleteRequest(final EsAbstractEntity esEntity) {
    final DeleteRequestBuilder builder = client.prepareDelete().setIndex(asEsIndex()).setId(esEntity.asDocMeta().id());
    final RequestOptionCall<DeleteRequestBuilder> deleteOption = esEntity.asDocMeta().deleteOption();
    if (deleteOption != null) {
        deleteOption.callback(builder);
    }
    return builder;
}
 
Example #26
Source File: ESNestedSearchService.java    From search-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * 按条件删除文档
 *
 * @param esObject 删除请求参数
 * @return <code>true</code>全部删除成功,<code>false</code>部分删除失败.
 */
public SearchBaseResult<Boolean> conditionDelete(final ConditionDeleteESObject esObject) {
    SearchBaseResult<Boolean> SearchResult = new SearchBaseResult<>();
    BulkRequestBuilder bulkRequestBuilder = transportClient.prepareBulk();
    BulkResponse bulkResponse;
    try {
        final List<String> docIds = getAccordConditionDocIds(esObject.getConditions(), esObject);
        if (CollectionUtils.isEmpty(docIds)) {
            SearchLogger.log(bulkRequestBuilder);
            SearchResult.setResult(Boolean.TRUE);
            return SearchResult;
        }

        for (String docId : docIds) {
            final DeleteRequestBuilder deleteRequestBuilder = transportClient.prepareDelete(esObject.getIndexName(),
                    esObject.getTypeName(), docId);
            bulkRequestBuilder.add(deleteRequestBuilder);
        }
        if (esObject.isRefresh()) {
            bulkRequestBuilder.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);
        }
        SearchLogger.log(bulkRequestBuilder);
        bulkResponse = bulkRequestBuilder.execute().get();
        SearchLogger.log(bulkResponse);
    } catch (Exception ex) {
        SearchLogger.error("conditionDelete", ex);
        SearchResult.setStatus(new Status(ESErrorCode.ELASTIC_ERROR_CODE, "esMsg:" + ex.getMessage()));
        return SearchResult;
    }
    SearchResult.setResult(!bulkResponse.hasFailures());
    return SearchResult;
}
 
Example #27
Source File: BsSearchLogBhv.java    From fess with Apache License 2.0 4 votes vote down vote up
public void delete(SearchLog entity, RequestOptionCall<DeleteRequestBuilder> opLambda) {
    entity.asDocMeta().deleteOption(opLambda);
    doDelete(entity, null);
}
 
Example #28
Source File: TestDeleteElasticsearch5.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeleteNonRetryableException() throws IOException {
    mockDeleteProcessor = new DeleteElasticsearch5() {

        @Override
        protected DeleteRequestBuilder prepareDeleteRequest(String index, String docId, String docType) {
            return null;
        }

        @Override
        protected DeleteResponse doDelete(DeleteRequestBuilder requestBuilder)
                throws InterruptedException, ExecutionException {
            throw new InterruptedException("exception");
        }

        @Override
        public void setup(ProcessContext context) {
        }

    };
    runner = TestRunners.newTestRunner(mockDeleteProcessor);

    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.CLUSTER_NAME, "elasticsearch");
    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.HOSTS, "127.0.0.1:9300");
    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.PING_TIMEOUT, "5s");
    runner.setProperty(AbstractElasticsearch5TransportClientProcessor.SAMPLER_INTERVAL, "5s");

    runner.setProperty(DeleteElasticsearch5.INDEX, INDEX1);
    runner.setProperty(DeleteElasticsearch5.TYPE, TYPE1);
    runner.setProperty(DeleteElasticsearch5.DOCUMENT_ID, "${documentId}");
    runner.assertValid();

    runner.enqueue(new byte [] {}, new HashMap<String, String>() {{
        put("documentId", documentId);
    }});
    runner.run(1, true, true);

    runner.assertAllFlowFilesTransferred(DeleteElasticsearch5.REL_FAILURE, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(DeleteElasticsearch5.REL_FAILURE).get(0);
    assertNotNull(out);
    assertEquals("exception",out.getAttribute(DeleteElasticsearch5.ES_ERROR_MESSAGE));
    out.assertAttributeEquals(DeleteElasticsearch5.ES_REST_STATUS, null);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_FILENAME, documentId);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_INDEX, INDEX1);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_TYPE, TYPE1);
}
 
Example #29
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public DeleteRequestBuilder prepareDelete() {
    return new DeleteRequestBuilder(this, DeleteAction.INSTANCE, null);
}
 
Example #30
Source File: BsUserInfoBhv.java    From fess with Apache License 2.0 4 votes vote down vote up
public void delete(UserInfo entity, RequestOptionCall<DeleteRequestBuilder> opLambda) {
    entity.asDocMeta().deleteOption(opLambda);
    doDelete(entity, null);
}