Java Code Examples for org.elasticsearch.action.delete.DeleteResponse#isFound()
The following examples show how to use
org.elasticsearch.action.delete.DeleteResponse#isFound() .
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: IndexTransaction.java From es-service-parent with Apache License 2.0 | 6 votes |
/** * 删除文档 * * @param id */ public boolean deleteDocById(String docId) { try { // 删除 DeleteResponse resp = ESClient.getClient() .prepareDelete(this.currentIndexName, this.indexType.getTypeName(), docId) .setOperationThreaded(false).execute().actionGet(); // 刷新 ESClient.getClient().admin().indices() .refresh(new RefreshRequest(this.currentIndexName)).actionGet(); if (resp.isFound()) { log.warn("delete index sunccess,indexname:{},type:{},delete {} items", this.indexType.getIndexName(), this.indexType.getTypeName(), 1); return resp.isFound(); } } catch (Exception e) { log.error("delete Doc fail,indexname:{},type:{}", this.indexType.getIndexName(), this.indexType.getTypeName()); } return false; }
Example 2
Source File: ESDeleteTask.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void onResponse(DeleteResponse response) { if (!response.isFound()) { result.set(TaskResult.ZERO); } else { result.set(TaskResult.ONE_ROW); } }
Example 3
Source File: QuestionElasticSearchIndexBuilder.java From sakai with Educational Community License v2.0 | 5 votes |
@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 4
Source File: BaseElasticSearchIndexBuilder.java From sakai with Educational Community License v2.0 | 5 votes |
protected void executeBulkRequest(BulkRequestBuilder bulkRequest) { BulkResponse bulkResponse = bulkRequest.execute().actionGet(); getLog().info("Bulk request of batch size: " + bulkRequest.numberOfActions() + " took " + bulkResponse.getTookInMillis() + " ms in index builder: " + getName()); for (BulkItemResponse response : bulkResponse.getItems()) { if (response.getResponse() instanceof DeleteResponse) { DeleteResponse deleteResponse = response.getResponse(); if (response.isFailed()) { getLog().error("Problem deleting doc: " + response.getId() + " in index builder: " + getName() + " error: " + response.getFailureMessage()); } else if (!deleteResponse.isFound()) { getLog().debug("ES could not find a doc with id: " + deleteResponse.getId() + " to delete in index builder: " + getName()); } else { getLog().debug("ES deleted a doc with id: " + deleteResponse.getId() + " in index builder: " + getName()); } } else if (response.getResponse() instanceof IndexResponse) { IndexResponse indexResponse = response.getResponse(); if (response.isFailed()) { getLog().error("Problem updating content for doc: " + response.getId() + " in index builder: " + getName() + " error: " + response.getFailureMessage()); } else { getLog().debug("ES indexed content for doc with id: " + indexResponse.getId() + " in index builder: " + getName()); } } } }
Example 5
Source File: BaseElasticSearchIndexBuilder.java From sakai with Educational Community License v2.0 | 5 votes |
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 6
Source File: TransportClient.java From elasticsearch-jest-example with MIT License | 5 votes |
/** * 仅仅只删除索引 * @param index * @param type * @param id */ private static void deleteIndex(String index, String type, String id){ Client client = createTransportClient(); DeleteResponse response = client.prepareDelete(index, type, id) .execute() .actionGet(); boolean isFound = response.isFound(); System.out.println("索引是否 存在:"+isFound); // 发现doc已删除则返回true System.out.println("****************index ***********************"); // Index name String _index = response.getIndex(); // Type name String _type = response.getType(); // Document ID (generated or not) String _id = response.getId(); // Version (if it's the first time you index this document, you will get: 1) long _version = response.getVersion(); System.out.println(_index+","+_type+","+_id+","+_version); //优化索引 OptimizeRequest optimizeRequest = new OptimizeRequest(index); OptimizeResponse optimizeResponse = client.admin().indices().optimize(optimizeRequest).actionGet(); System.out.println(optimizeResponse.getTotalShards()+","+optimizeResponse.getSuccessfulShards()+","+optimizeResponse.getFailedShards()); //刷新索引 FlushRequest flushRequest = new FlushRequest(index); flushRequest.force(true); FlushResponse flushResponse = client.admin().indices().flush(flushRequest).actionGet(); System.out.println(flushResponse.getTotalShards()+","+flushResponse.getSuccessfulShards()+","+flushResponse.getFailedShards()); }
Example 7
Source File: QuestionElasticSearchIndexBuilder.java From sakai with Educational Community License v2.0 | 5 votes |
@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 8
Source File: BaseElasticSearchIndexBuilder.java From sakai with Educational Community License v2.0 | 5 votes |
protected void executeBulkRequest(BulkRequestBuilder bulkRequest) { BulkResponse bulkResponse = bulkRequest.execute().actionGet(); getLog().info("Bulk request of batch size: " + bulkRequest.numberOfActions() + " took " + bulkResponse.getTookInMillis() + " ms in index builder: " + getName()); for (BulkItemResponse response : bulkResponse.getItems()) { if (response.getResponse() instanceof DeleteResponse) { DeleteResponse deleteResponse = response.getResponse(); if (response.isFailed()) { getLog().error("Problem deleting doc: " + response.getId() + " in index builder: " + getName() + " error: " + response.getFailureMessage()); } else if (!deleteResponse.isFound()) { getLog().debug("ES could not find a doc with id: " + deleteResponse.getId() + " to delete in index builder: " + getName()); } else { getLog().debug("ES deleted a doc with id: " + deleteResponse.getId() + " in index builder: " + getName()); } } else if (response.getResponse() instanceof IndexResponse) { IndexResponse indexResponse = response.getResponse(); if (response.isFailed()) { getLog().error("Problem updating content for doc: " + response.getId() + " in index builder: " + getName() + " error: " + response.getFailureMessage()); } else { getLog().debug("ES indexed content for doc with id: " + indexResponse.getId() + " in index builder: " + getName()); } } } }
Example 9
Source File: BaseElasticSearchIndexBuilder.java From sakai with Educational Community License v2.0 | 5 votes |
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 10
Source File: ProviderParamsDao.java From usergrid with Apache License 2.0 | 5 votes |
/** * @param username Username owning the provider params to be deleted * @return whether or not provider params existed for given username */ public boolean delete( String username ) { DeleteResponse response = elasticSearchClient.getClient() .prepareDelete( DAO_INDEX_KEY, DAO_TYPE_KEY, username ) .setRefresh( true ) .execute() .actionGet(); return response.isFound(); }
Example 11
Source File: UserDao.java From usergrid with Apache License 2.0 | 5 votes |
/** * Deletes a <code>User</code> with given <code>username</code> from storage * * @param username Name of the user which will be deleted * @return whether such a user existed in storage */ public boolean delete( String username ) { DeleteResponse response = elasticSearchClient.getClient() .prepareDelete( DAO_INDEX_KEY, DAO_TYPE_KEY, username ) .setRefresh( true ) .execute() .actionGet(); return response.isFound(); }
Example 12
Source File: RunDao.java From usergrid with Apache License 2.0 | 5 votes |
/** * * @param run * @return */ public boolean delete( Run run ) { DeleteResponse response = elasticSearchClient.getClient() .prepareDelete( DAO_INDEX_KEY, DAO_TYPE_KEY, run.getId() ) .setRefresh( true ) .execute() .actionGet(); return response.isFound(); }
Example 13
Source File: RunnerDao.java From usergrid with Apache License 2.0 | 5 votes |
/** * @param runnerUrl Runner with matching runnerUrl id will be deleted * @return Whether such a Runner had existed */ public boolean delete( String runnerUrl ) { DeleteResponse response = elasticSearchClient.getClient() .prepareDelete( DAO_INDEX_KEY, DAO_TYPE_KEY, runnerUrl ) .setRefresh( true ) .execute() .actionGet(); return response.isFound(); }
Example 14
Source File: RunResultDao.java From usergrid with Apache License 2.0 | 5 votes |
/** * Deletes the RunResult with given id field from elastic search * * @param id Corresponds to the result of RunResult.getId() which used as index id in ES * @return Whether the operation succeeded */ public boolean delete( String id ) { DeleteResponse response = elasticSearchClient.getClient() .prepareDelete( DAO_INDEX_KEY, DAO_TYPE_KEY, id ) .setRefresh( true ) .execute() .actionGet(); return response.isFound(); }
Example 15
Source File: EsDoc.java From AsuraFramework with Apache License 2.0 | 2 votes |
/** * 删除文档 * @param indexName * @param indexType * @param id * @return */ public boolean deleteDocument(String indexName, String indexType, String id) { TransportClient client = esClientFactory.getClient(); DeleteResponse indexResponse=client.prepareDelete(esClientFactory.getIndexs(indexName), indexType, id).get(); return indexResponse.isFound(); }