001package org.xbib.elasticsearch.action.websocket.bulk; 002 003import org.elasticsearch.action.delete.DeleteRequest; 004import org.elasticsearch.client.Client; 005import org.elasticsearch.client.Requests; 006import org.elasticsearch.common.inject.Inject; 007import org.elasticsearch.common.settings.Settings; 008import org.xbib.elasticsearch.websocket.InteractiveChannel; 009import org.xbib.elasticsearch.websocket.InteractiveController; 010import org.xbib.elasticsearch.websocket.InteractiveRequest; 011 012import java.io.IOException; 013 014/** 015 * Bulk delete action 016 */ 017public class BulkDeleteAction extends BulkHandler { 018 019 private final static String TYPE = "delete"; 020 021 @Inject 022 public BulkDeleteAction(Settings settings, Client client, InteractiveController controller) { 023 super(settings, client); 024 controller.registerHandler(TYPE, this); 025 } 026 027 @Override 028 public void handleRequest(final InteractiveRequest request, final InteractiveChannel channel) { 029 String index = request.paramAsString("index"); 030 String type = request.paramAsString("type"); 031 String id = request.paramAsString("id"); 032 try { 033 if (index == null) { 034 channel.sendResponse(TYPE, new IllegalArgumentException("index is null")); 035 return; 036 } 037 if (type == null) { 038 channel.sendResponse(TYPE, new IllegalArgumentException("type is null")); 039 return; 040 } 041 if (id == null) { 042 channel.sendResponse(TYPE, new IllegalArgumentException("id is null")); 043 return; 044 } 045 DeleteRequest deleteRequest = Requests.deleteRequest(index).type(type).id(id); 046 add(deleteRequest, channel); 047 } catch (IOException ex) { 048 try { 049 channel.sendResponse(TYPE, ex); 050 } catch (IOException ex1) { 051 logger.error("error while sending exception"); 052 } 053 } 054 } 055}