Commit ceafaa0d authored by Matija Obreza's avatar Matija Obreza

Delete ES index

parent f63b18ed
......@@ -66,6 +66,18 @@ public interface ElasticService {
*/
void realias(String aliasName, String indexName);
/**
* Delete an ES alias
*
* @param aliasName
*/
void deleteAlias(String aliasName);
/**
* Delete an unused index (no aliases)
*
* @param indexName
*/
void deleteIndex(String indexName);
}
......@@ -64,6 +64,7 @@ import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
import org.springframework.data.elasticsearch.core.query.UpdateQueryBuilder;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import com.hazelcast.core.ILock;
......@@ -524,6 +525,16 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
}
}
}
/**
* Delete an index
*/
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
public void deleteIndex(String indexName) {
LOG.warn("Deleting Elasticsearch index " + indexName);
elasticsearchTemplate.deleteIndex(indexName);
}
private void createIndex(String indexName, Map<?, ?> indexMapping, Map<?, ?> settings) {
LOG.info("Creating index " + indexName);
......
......@@ -132,4 +132,10 @@ public class ElasticSearchController {
elasticService.deleteAlias(aliasName);
return "redirect:/admin/elastic/";
}
@RequestMapping(method = RequestMethod.POST, value = "/action", params = { "action=delete-index", "indexName" })
public String deleteIndex(@RequestParam(name = "indexName") String indexName) {
elasticService.deleteIndex(indexName);
return "redirect:/admin/elastic/";
}
}
......@@ -26,6 +26,7 @@
Index:<input type="text" name="indexName" />
<button type="submit" class="btn btn-primary" value="realias" name="action">Move alias</button>
<button type="submit" class="btn btn-default" value="delete-alias" name="action">Delete alias</button>
<button type="submit" class="btn btn-default" value="delete-index" name="action">Delete index</button>
</form>
<h3>Indexes and their aliases</h3>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment