io.searchbox.core.Delete Java Examples

The following examples show how to use io.searchbox.core.Delete. 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: JestServiceImpl.java    From EserKnife with Apache License 2.0 6 votes vote down vote up
@Override
public JestResult deleteBulk(String clustName, String indexName, String Type, List<SearchResultDetailVO> results) {
    JestResult result = null ;
    try {
        Bulk.Builder bulkBulder = new Bulk.Builder().defaultIndex(indexName).defaultType(Type);
        if(CollectionUtils.isNotEmpty(results)){
            for (SearchResultDetailVO resultDetailVO:results){
                bulkBulder.addAction(new Delete.Builder(resultDetailVO.getId()).index(indexName).type(Type).build());
            }
        }
        result = JestManager.getJestClient(clustName).execute(bulkBulder.build());
    } catch (Exception e) {
        e.printStackTrace();
        LOGGER.error("deleteBulk失败:",e);
    }
    return result ;

}
 
Example #2
Source File: ESRegistry.java    From apiman with Apache License 2.0 6 votes vote down vote up
/**
 * @see io.apiman.gateway.engine.IRegistry#retireApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public void retireApi(Api api, final IAsyncResultHandler<Void> handler) {
    final String id = getApiId(api);

    try {
        Delete delete = new Delete.Builder(id).index(getIndexName()).type("api").build(); //$NON-NLS-1$
        JestResult result = getClient().execute(delete);
        if (result.isSucceeded()) {
            handler.handle(AsyncResultImpl.create((Void) null));
        } else {
            handler.handle(AsyncResultImpl.create(new ApiNotFoundException(Messages.i18n.format("ESRegistry.ApiNotFound")))); //$NON-NLS-1$
        }
    } catch (IOException e) {
        handler.handle(AsyncResultImpl.create(new PublishingException(Messages.i18n.format("ESRegistry.ErrorRetiringApi"), e))); //$NON-NLS-1$
    }
}
 
Example #3
Source File: EsSyncIncrement.java    From easy-sync with Apache License 2.0 5 votes vote down vote up
private void doSync(List<ConsumerRecord> records) throws Exception {

        Bulk.Builder bulk = new Bulk.Builder().defaultIndex(indexName).defaultType(Const.ES_TYPE);
        for (ConsumerRecord record : records) {
            logger.info("[incr] {}={}",indexName,record.value());
            Row row = JSON.parseObject(record.value(), Row.class);
            if(columnMap==null){
                columnMap=databaseService.getColumnMap(row.getDatabase(),row.getTable());
            }
            String id = record.key();
            if (row.getType().equalsIgnoreCase("insert") || (row.getType().equalsIgnoreCase("update"))) {
                LinkedHashMap<String, Object> data = row.getData();
                Map map = (convertKafka2Es(data));
                Index index = new Index.Builder(map).id(id).build();
                bulk.addAction(index);

            } else if (row.getType().equalsIgnoreCase("delete")) {
                Delete delete = new Delete.Builder(id).build();
                bulk.addAction(delete);
            } else {
                //
            }
        }


            BulkResult br = jest.getJestClient().execute(bulk.build());
            if (!br.isSucceeded()) {
                logger.error("error={}, failItems={}", br.getErrorMessage(), JSON.toJSONString(br.getFailedItems()));
                //   br.getFailedItems().get(0).
                throw new RuntimeException("bulk error");
            }


            //   buffer.add(record);

    }
 
Example #4
Source File: DeletableRecord.java    From jkes with Apache License 2.0 5 votes vote down vote up
public Delete toDeleteRequest() {
  Delete.Builder req = new Delete.Builder(key.id)
          .index(key.index)
          .type(key.type);
  if (version != null) {
    req.setParameter("version_type", versionType).setParameter("version", version);
  }
  return req.build();
}
 
Example #5
Source File: JestClient.java    From wES with MIT License 5 votes vote down vote up
@Override
public boolean delete(IEsItem doc) throws Exception {
	Delete.Builder builder = new Delete.Builder(doc.getId());
	if (doc.getIndex() != null) {
		builder.index(doc.getIndex());
	}
	if (doc.getType() != null) {
		builder.type(doc.getType());
	}
	DocumentResult result = _exec(builder.build());
	if (result != null) {
		return true;
	}
	return false;
}
 
Example #6
Source File: IndexFunctionsDaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * The delete document by id function will delete a document in the index by the document id.
 */
@Override
public final void deleteDocumentById(String indexName, String documentType, String id)
{
    LOGGER.info("Deleting Elasticsearch document from index, indexName={}, documentType={}, id={}.", indexName, documentType, id);

    Action action = new Delete.Builder(id).index(indexName).type(documentType).build();

    JestResult result = jestClientHelper.execute(action);

    LOGGER.info("Deleting Elasticsearch document from index, indexName={}, documentType={}, id={} is successfully {}. ", indexName, documentType, id,
        result.isSucceeded());
}
 
Example #7
Source File: IndexFunctionsDaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * The delete index documents function will delete a list of document in the index by a list of document ids.
 */
@Override
public final void deleteIndexDocuments(String indexName, String documentType, List<Long> ids)
{
    LOGGER.info("Deleting Elasticsearch documents from index, indexName={}, documentType={}, ids={}.", indexName, documentType,
        ids.stream().map(Object::toString).collect(Collectors.joining(",")));

    List<String> allIndices = getAliases(indexName);

    allIndices.forEach((index) -> {
    // Prepare a bulk request builder
    Bulk.Builder bulkBuilder = new Bulk.Builder();


    // For each document prepare a delete request and add it to the bulk request builder
    ids.forEach(id ->
    {
        BulkableAction action = new Delete.Builder(id.toString()).index(index).type(documentType).build();
        bulkBuilder.addAction(action);
    });

    JestResult jestResult = jestClientHelper.execute(bulkBuilder.build());
    // If there are failures log them
    if (!jestResult.isSucceeded())
    {
        LOGGER.error("Bulk response error = {}", jestResult.getErrorMessage());
    }
    });

}
 
Example #8
Source File: ESSharedStateComponent.java    From apiman with Apache License 2.0 5 votes vote down vote up
/**
 * @see io.apiman.gateway.engine.components.ISharedStateComponent#clearProperty(java.lang.String, java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
 */
@Override
public <T> void clearProperty(final String namespace, final String propertyName, final IAsyncResultHandler<Void> handler) {
    String id = getPropertyId(namespace, propertyName);

    Delete delete = new Delete.Builder(id).index(getIndexName()).type("sharedStateProperty").build(); //$NON-NLS-1$
    try {
        getClient().execute(delete);
        handler.handle(AsyncResultImpl.create((Void) null));
    } catch (Throwable e) {
        handler.handle(AsyncResultImpl.<Void>create(e));
    }
}
 
Example #9
Source File: EsResetter.java    From apiman with Apache License 2.0 5 votes vote down vote up
@Override
public void reset() {
    try {
        CountDownLatch latch = new CountDownLatch(1);

        // Important! Or will get cached client that assumes the DB schema has already been created
        // and subtly horrible things will happen, and you'll waste a whole day debugging it! :-)
        DefaultEsClientFactory.clearClientCache();

        getClient().executeAsync(new Delete.Builder(getDefaultIndexName()).build(),
                new JestResultHandler<JestResult>() {

            @Override
            public void completed(JestResult result) {
                latch.countDown();
                System.out.println("=== Deleted index: " + result.getJsonString());
            }

            @Override
            public void failed(Exception ex) {
                latch.countDown();
                System.err.println("=== Failed to delete index: " + ex.getMessage());
                throw new RuntimeException(ex);
            }
        });

        Flush flush = new Flush.Builder().build();
        getClient().execute(flush);
        Thread.sleep(100);

        latch.await();
    } catch (IOException | InterruptedException e) {
        throw new RuntimeException(e);
    }
}
 
Example #10
Source File: JestTest.java    From springBoot-study with Apache License 2.0 2 votes vote down vote up
/**
* 删除数据
* @param indexName
* @param typeName
* @param id
* @return
* @throws Exception
*/
public boolean delete(JestClient jestClient,String indexName, String typeName, String id) throws Exception {  
    DocumentResult dr = jestClient.execute(new Delete.Builder(id).index(indexName).type(typeName).build());  
    return dr.isSucceeded();  
}
 
Example #11
Source File: JestTest.java    From java-study with Apache License 2.0 2 votes vote down vote up
/**
* 删除数据
* @param indexName
* @param typeName
* @param id
* @return
* @throws Exception
*/
public boolean delete(JestClient jestClient,String indexName, String typeName, String id) throws Exception {  
    DocumentResult dr = jestClient.execute(new Delete.Builder(id).index(indexName).type(typeName).build());  
    return dr.isSucceeded();  
}