Hello all,
This post will mainly talk about "Elasticsearch delete data".
Elasticsearch can be deleted flexibly. Today, we will introduce you how to deletion by ID.
Code:
package com.sojson.core.elasticsearch.manager;
import org.elasticsearch.action.delete.DeleteResponse;
import com.sojson.common.model.SOBanggKey;
import com.sojson.core.elasticsearch.utils.ESTools;
public class DeleteManager {
/**
* Delete by ID
* @param key
* @return
*/
public static int deleteSOBanggByKey(SOBanggKey key) {
String prefix = "%sx_x%s";
String id = String.format(prefix, key.getId(),key.getGid());
DeleteResponse result = ESTools.client.prepareDelete().setRefresh(true).setIndex(MappingManager.INDEX)
.setType(MappingManager.B_TYPE)
.setId(id)
.setRefresh(true)
.execute().actionGet();
//Find and Delete
boolean isfound = result.isFound();
return isfound?1:0;
}
}
Any solutions will be appreciated!