Got it

Elasticsearch delete data

Latest reply: Nov 21, 2021 15:36:41 307 2 2 0 0

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:

  1. package com.sojson.core.elasticsearch.manager;

  2. import org.elasticsearch.action.delete.DeleteResponse;

  3. import com.sojson.common.model.SOBanggKey;

  4. import com.sojson.core.elasticsearch.utils.ESTools;

  5. public class DeleteManager {

  6. /**

  7. * Delete by ID

  8. * @param key

  9. * @return

  10. */

  11. public static int deleteSOBanggByKey(SOBanggKey key) {

  12. String prefix = "%sx_x%s";

  13. String id = String.format(prefix, key.getId(),key.getGid());

  14. DeleteResponse result = ESTools.client.prepareDelete().setRefresh(true).setIndex(MappingManager.INDEX)

  15.    .setType(MappingManager.B_TYPE)

  16.    .setId(id)

  17.    .setRefresh(true)

  18.    .execute().actionGet();

  19.   //Find and Delete

  20.   boolean isfound = result.isFound();

  21.   return isfound?1:0;

  22. }

  23. }


Any solutions will be appreciated!

  • x
  • convention:

olive.zhao
Admin Created Nov 16, 2021 07:17:44

Thanks for your sharing!
View more
  • x
  • convention:

user_4358465
Created Nov 21, 2021 15:36:41

Interesting. Thank you for sharing!
View more
  • x
  • convention:

Comment

You need to log in to comment to the post Login | Register
Comment

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits

Login

Block
Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Reminder
Please bind your phone number to obtain invitation bonus.
Information Protection Guide
Thanks for using Huawei Enterprise Support Community! We will help you learn how we collect, use, store and share your personal information and the rights you have in accordance with Privacy Policy and User Agreement.