Runnable indexRunner = new Runnable() {
public void run() {
try {
String id=content.getIdentifier()+"_"+content.getLanguageId();
Client client=new ESClient().getClient();
BulkRequestBuilder bulk=client.prepareBulk();
IndiciesInfo info=APILocator.getIndiciesAPI().loadIndicies();
bulk.add(client.prepareDelete(info.live, "content", id));
if(info.reindex_live!=null)
bulk.add(client.prepareDelete(info.reindex_live, "content", id));
if(!onlyLive) {
// here we search for relationship fields pointing to this
// content to be deleted. Those contentlets are reindexed
// to avoid left those fields making noise in the index
for(Relationship rel : relationships) {
String q = "";
boolean isSameStructRelationship = rel.getParentStructureInode().equalsIgnoreCase(rel.getChildStructureInode());
if(isSameStructRelationship)
q = "+type:content +(" + rel.getRelationTypeValue() + "-parent:" + content.getIdentifier() + " " +
rel.getRelationTypeValue() + "-child:" + content.getIdentifier() + ") ";
else
q = "+type:content +" + rel.getRelationTypeValue() + ":" + content.getIdentifier();
List<Contentlet> related = APILocator.getContentletAPI().search(q, -1, 0, null, APILocator.getUserAPI().getSystemUser(), false);
indexContentletList(bulk, related, false);
}
bulk.add(client.prepareDelete(info.working, "content", id));
if(info.reindex_working!=null)
bulk.add(client.prepareDelete(info.reindex_working, "content", id));
}
bulk.execute().actionGet();
}
catch(Exception ex) {
throw new ElasticSearchException(ex.getMessage(),ex);
}