Java Code Examples for org.elasticsearch.action.delete.DeleteResponse#getResult()
The following examples show how to use
org.elasticsearch.action.delete.DeleteResponse#getResult() .
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: ESNestedSearchService.java From search-spring-boot-starter with Apache License 2.0 | 6 votes |
/** * 根据文档唯一Id删除指定的文档 * * @param esObject 删除参数 * @return <code>true</code>文档删除成功,<code>true</code>未找到对应文档. */ public SearchBaseResult<Boolean> delete(final DeleteESObject esObject) { final DeleteRequestBuilder deleteRequest = getDeleteRequest(esObject); try { SearchLogger.log(deleteRequest); if (esObject.isRefresh()) { deleteRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL); } DeleteResponse deleteResponse = deleteRequest.execute().actionGet(); SearchLogger.log(deleteRequest); if (DocWriteResponse.Result.DELETED == deleteResponse.getResult()) { return SearchBaseResult.success(Boolean.TRUE, Boolean.class); } if (DocWriteResponse.Result.NOT_FOUND == deleteResponse.getResult()) { return SearchBaseResult.success(Boolean.FALSE, Boolean.class); } return SearchBaseResult.faild(ESErrorCode.ELASTIC_ERROR_CODE, "ES返回结果不在预期范围内"); } catch (Exception ex) { SearchLogger.error("delete", ex); return SearchBaseResult.faild(ESErrorCode.ELASTIC_ERROR_CODE, "esMsg:" + ex.getMessage()); } }
Example 2
Source File: ElasticSearchDAOV5.java From conductor with Apache License 2.0 | 6 votes |
@Override public void removeWorkflow(String workflowId) { try { long startTime = Instant.now().toEpochMilli(); DeleteRequest request = new DeleteRequest(indexName, WORKFLOW_DOC_TYPE, workflowId); DeleteResponse response = elasticSearchClient.delete(request).actionGet(); if (response.getResult() == DocWriteResponse.Result.DELETED) { logger.error("Index removal failed - document not found by id: {}", workflowId); } long endTime = Instant.now().toEpochMilli(); logger.debug("Time taken {} for removing workflow: {}", endTime - startTime, workflowId); Monitors.recordESIndexTime("remove_workflow", WORKFLOW_DOC_TYPE, endTime - startTime); Monitors.recordWorkerQueueSize("indexQueue", ((ThreadPoolExecutor) executorService).getQueue().size()); } catch (Exception e) { logger.error("Failed to remove workflow {} from index", workflowId, e); Monitors.error(className, "remove"); } }
Example 3
Source File: ElasticSearchRestDAOV5.java From conductor with Apache License 2.0 | 6 votes |
@Override public void removeWorkflow(String workflowId) { long startTime = Instant.now().toEpochMilli(); DeleteRequest request = new DeleteRequest(indexName, WORKFLOW_DOC_TYPE, workflowId); try { DeleteResponse response = elasticSearchClient.delete(request); if (response.getResult() == DocWriteResponse.Result.NOT_FOUND) { logger.error("Index removal failed - document not found by id: {}", workflowId); } long endTime = Instant.now().toEpochMilli(); logger.debug("Time taken {} for removing workflow: {}", endTime - startTime, workflowId); Monitors.recordESIndexTime("remove_workflow", WORKFLOW_DOC_TYPE, endTime - startTime); Monitors.recordWorkerQueueSize("indexQueue", ((ThreadPoolExecutor) executorService).getQueue().size()); } catch (Exception e) { logger.error("Failed to remove workflow {} from index", workflowId, e); Monitors.error(className, "remove"); } }
Example 4
Source File: ElasticSearchRestDAOV6.java From conductor with Apache License 2.0 | 6 votes |
@Override public void removeWorkflow(String workflowId) { long startTime = Instant.now().toEpochMilli(); String docType = StringUtils.isBlank(docTypeOverride) ? WORKFLOW_DOC_TYPE : docTypeOverride; DeleteRequest request = new DeleteRequest(workflowIndexName, docType, workflowId); try { DeleteResponse response = elasticSearchClient.delete(request); if (response.getResult() == DocWriteResponse.Result.NOT_FOUND) { logger.error("Index removal failed - document not found by id: {}", workflowId); } long endTime = Instant.now().toEpochMilli(); logger.debug("Time taken {} for removing workflow: {}", endTime - startTime, workflowId); Monitors.recordESIndexTime("remove_workflow", WORKFLOW_DOC_TYPE, endTime - startTime); Monitors.recordWorkerQueueSize("indexQueue", ((ThreadPoolExecutor) executorService).getQueue().size()); } catch (IOException e) { logger.error("Failed to remove workflow {} from index", workflowId, e); Monitors.error(className, "remove"); } }
Example 5
Source File: ElasticSearchDAOV6.java From conductor with Apache License 2.0 | 6 votes |
@Override public void removeWorkflow(String workflowId) { try { long startTime = Instant.now().toEpochMilli(); DeleteRequest request = new DeleteRequest(workflowIndexName, WORKFLOW_DOC_TYPE, workflowId); DeleteResponse response = elasticSearchClient.delete(request).actionGet(); if (response.getResult() == DocWriteResponse.Result.DELETED) { LOGGER.error("Index removal failed - document not found by id: {}", workflowId); } long endTime = Instant.now().toEpochMilli(); LOGGER.debug("Time taken {} for removing workflow: {}", endTime - startTime, workflowId); Monitors.recordESIndexTime("remove_workflow", WORKFLOW_DOC_TYPE, endTime - startTime); Monitors.recordWorkerQueueSize("indexQueue", ((ThreadPoolExecutor) executorService).getQueue().size()); } catch (Throwable e) { LOGGER.error("Failed to remove workflow {} from index", workflowId, e); Monitors.error(CLASS_NAME, "remove"); } }
Example 6
Source File: ElasticSearchTypeImpl.java From core-ng-project with Apache License 2.0 | 6 votes |
@Override public boolean delete(DeleteRequest request) { var watch = new StopWatch(); String index = request.index == null ? this.index : request.index; boolean deleted = false; try { var deleteRequest = new org.elasticsearch.action.delete.DeleteRequest(index, request.id); DeleteResponse response = elasticSearch.client().delete(deleteRequest, RequestOptions.DEFAULT); deleted = response.getResult() == DocWriteResponse.Result.DELETED; return deleted; } catch (IOException e) { throw new UncheckedIOException(e); } finally { long elapsed = watch.elapsed(); ActionLogContext.track("elasticsearch", elapsed, 0, deleted ? 1 : 0); logger.debug("delete, index={}, id={}, elapsed={}", index, request.id, elapsed); checkSlowOperation(elapsed); } }
Example 7
Source File: EsAbstractBehavior.java From fess with Apache License 2.0 | 5 votes |
@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 8
Source File: FessEsClient.java From fess with Apache License 2.0 | 5 votes |
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 9
Source File: EsAbstractBehavior.java From fess with Apache License 2.0 | 5 votes |
@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 10
Source File: EsAbstractBehavior.java From fess with Apache License 2.0 | 5 votes |
@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 11
Source File: ElasticsearchClusterRunner.java From elasticsearch-cluster-runner with Apache License 2.0 | 5 votes |
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 12
Source File: ElasticsearchClusterRunner.java From elasticsearch-cluster-runner with Apache License 2.0 | 5 votes |
@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 13
Source File: ElasticSearchController.java From springboot-learn with MIT License | 5 votes |
@DeleteMapping("/delete/book/novel") public ResponseEntity delete(@RequestParam(name = "id", defaultValue = "") String id) { // 查询结果 DeleteResponse result = transportClient.prepareDelete(INDEX, TYPE, id) .get(); return new ResponseEntity(result.getResult(), HttpStatus.OK); }
Example 14
Source File: ElasticSearchRestHighImpl.java From sunbird-lms-service with MIT License | 4 votes |
/** * This method will remove data from ES based on identifier. * * @param index String * @param type String * @param identifier String */ @Override public Future<Boolean> delete(String index, String identifier) { long startTime = System.currentTimeMillis(); ProjectLogger.log( "ElasticSearchRestHighImpl:delete: method started at ==" + startTime, LoggerEnum.PERF_LOG.name()); Promise<Boolean> promise = Futures.promise(); if (StringUtils.isNotEmpty(identifier) && StringUtils.isNotEmpty(index)) { DeleteRequest delRequest = new DeleteRequest(index, _DOC, identifier); ActionListener<DeleteResponse> listener = new ActionListener<DeleteResponse>() { @Override public void onResponse(DeleteResponse deleteResponse) { if (deleteResponse.getResult() == DocWriteResponse.Result.NOT_FOUND) { ProjectLogger.log( "ElasticSearchRestHighImpl:delete:OnResponse: Document not found for index : " + index + " , identifier : " + identifier, LoggerEnum.INFO.name()); promise.success(false); } else { promise.success(true); } } @Override public void onFailure(Exception e) { ProjectLogger.log( "ElasticSearchRestHighImpl:delete: Async Failed due to error :" + e, LoggerEnum.INFO.name()); promise.failure(e); } }; ConnectionManager.getRestClient().deleteAsync(delRequest, listener); } else { ProjectLogger.log( "ElasticSearchRestHighImpl:delete: " + "provided index or identifier is null, index = " + index + "," + " identifier = " + identifier, LoggerEnum.INFO.name()); promise.failure(ProjectUtil.createClientException(ResponseCode.invalidData)); } ProjectLogger.log( "ElasticSearchRestHighImpl:delete: method end ==" + " ,Total time elapsed = " + calculateEndTime(startTime), LoggerEnum.PERF_LOG.name()); return promise.future(); }
Example 15
Source File: ElasticsearchClient.java From yacy_grid_mcp with GNU Lesser General Public License v2.1 | 4 votes |
private boolean deleteInternal(String indexName, String typeName, final String id) { DeleteResponse response = elasticsearchClient.prepareDelete(indexName, typeName, id).get(); return response.getResult() == DocWriteResponse.Result.DELETED; }
Example 16
Source File: CommonWebpageDAO.java From spider with GNU General Public License v3.0 | 2 votes |
/** * 根据id删除网页 * * @param id 网页id * @return 是否删除 */ public boolean deleteById(String id) { DeleteResponse response = client.prepareDelete(INDEX_NAME, TYPE_NAME, id).get(); return response.getResult() == DeleteResponse.Result.DELETED; }
Example 17
Source File: SpiderInfoDAO.java From spider with GNU General Public License v3.0 | 2 votes |
/** * 根据id删除网页模板 * * @param id 网页模板id * @return 是否删除 */ public boolean deleteById(String id) { DeleteResponse response = client.prepareDelete(INDEX_NAME, TYPE_NAME, id).get(); return response.getResult() == DeleteResponse.Result.DELETED; }
Example 18
Source File: CommonWebpageDAO.java From Gather-Platform with GNU General Public License v3.0 | 2 votes |
/** * 根据id删除网页 * * @param id 网页id * @return 是否删除 */ public boolean deleteById(String id) { DeleteResponse response = client.prepareDelete(INDEX_NAME, TYPE_NAME, id).get(); return response.getResult() == DeleteResponse.Result.DELETED; }
Example 19
Source File: SpiderInfoDAO.java From Gather-Platform with GNU General Public License v3.0 | 2 votes |
/** * 根据id删除网页模板 * * @param id 网页模板id * @return 是否删除 */ public boolean deleteById(String id) { DeleteResponse response = client.prepareDelete(INDEX_NAME, TYPE_NAME, id).get(); return response.getResult() == DeleteResponse.Result.DELETED; }