The deletion of Elasticsearch is also very flexible, next time I introduce, DeleteByQuery
the way. Today, we will introduce a deletion based on the ID. On the 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 {
/**
* Deleted by ID
* @param key
* @return
*/
public static int Deletesobanggbykey (Sobanggkey key) {
Here can be ignored, assemble an ID of my business logic
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)//Set ID
. Setrefresh (True)//Refresh
. Execute (). Actionget ();
Whether to find and delete
Boolean isfound = Result.isfound ();
return isfound?1:0;
}
}
Elasticsearch Tutorials (eight) elasticsearch delete deleting data (Java)