Elasticsearch Tutorials (eight) elasticsearch delete deleting data (Java)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.