Search in sources :

Example 1 with ESDeleteRequest

use of com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest.ESDeleteRequest in project canal by alibaba.

the class ES7xTemplate method delete.

@Override
public void delete(ESMapping mapping, Object pkVal, Map<String, Object> esFieldData) {
    if (mapping.get_id() != null) {
        ESDeleteRequest esDeleteRequest = this.esConnection.new ES7xDeleteRequest(mapping.get_index(), pkVal.toString());
        getBulk().add(esDeleteRequest);
        commitBulk();
    } else {
        ESSearchRequest esSearchRequest = this.esConnection.new ESSearchRequest(mapping.get_index()).setQuery(QueryBuilders.termQuery(mapping.getPk(), pkVal)).size(10000);
        SearchResponse response = esSearchRequest.getResponse();
        for (SearchHit hit : response.getHits()) {
            ESUpdateRequest esUpdateRequest = this.esConnection.new ES7xUpdateRequest(mapping.get_index(), hit.getId()).setDoc(esFieldData);
            getBulk().add(esUpdateRequest);
            commitBulk();
        }
    }
}
Also used : ESDeleteRequest(com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest.ESDeleteRequest) SearchHit(org.elasticsearch.search.SearchHit) ESUpdateRequest(com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest.ESUpdateRequest) ESSearchRequest(com.alibaba.otter.canal.client.adapter.es7x.support.ESConnection.ESSearchRequest) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 2 with ESDeleteRequest

use of com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest.ESDeleteRequest in project canal by alibaba.

the class ES6xTemplate method delete.

@Override
public void delete(ESSyncConfig.ESMapping mapping, Object pkVal, Map<String, Object> esFieldData) {
    if (mapping.get_id() != null) {
        ESDeleteRequest esDeleteRequest = this.esConnection.new ES6xDeleteRequest(mapping.get_index(), mapping.get_type(), pkVal.toString());
        getBulk().add(esDeleteRequest);
        commitBulk();
    } else {
        ESSearchRequest esSearchRequest = this.esConnection.new ESSearchRequest(mapping.get_index(), mapping.get_type()).setQuery(QueryBuilders.termQuery(mapping.getPk(), pkVal)).size(10000);
        SearchResponse response = esSearchRequest.getResponse();
        for (SearchHit hit : response.getHits()) {
            ESUpdateRequest esUpdateRequest = this.esConnection.new ES6xUpdateRequest(mapping.get_index(), mapping.get_type(), hit.getId()).setDoc(esFieldData);
            getBulk().add(esUpdateRequest);
            commitBulk();
        }
    }
}
Also used : ESDeleteRequest(com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest.ESDeleteRequest) SearchHit(org.elasticsearch.search.SearchHit) ESUpdateRequest(com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest.ESUpdateRequest) ESSearchRequest(com.alibaba.otter.canal.client.adapter.es6x.support.ESConnection.ESSearchRequest) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

ESDeleteRequest (com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest.ESDeleteRequest)2 ESUpdateRequest (com.alibaba.otter.canal.client.adapter.es.core.support.ESBulkRequest.ESUpdateRequest)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 SearchHit (org.elasticsearch.search.SearchHit)2 ESSearchRequest (com.alibaba.otter.canal.client.adapter.es6x.support.ESConnection.ESSearchRequest)1 ESSearchRequest (com.alibaba.otter.canal.client.adapter.es7x.support.ESConnection.ESSearchRequest)1