Source:
<code>public Response toolsIndexGet(SecurityContext securityContext) { if (!config.getEsConfiguration().getHostname().isEmpty()) { List<Entry> published = getPublished(); try (RestClient restClient = RestClient .builder(new HttpHost(config.getEsConfiguration().getHostname(), config.getEsConfiguration().getPort(), "http")) .build()) { try { <START> restClient.performRequest("DELETE", "/tools"); <END> } catch (Exception e) { LOG.warn("Could not delete previous elastic search Tools index, not an issue if this is cold start", e); } try { restClient.performRequest("DELETE", "/workflows"); } catch (Exception e) { LOG.warn("Could not delete previous elastic search Workflows index, not an issue if this is cold start", e); } URL urlTools = Resources.getResource("queries/mapping_tool.json"); String textTools = Resources.toString(urlTools, StandardCharsets.UTF_8); HttpEntity mappingEntityTools = new NStringEntity(textTools, ContentType.APPLICATION_JSON); URL urlWorkflows = Resources.getResource("queries/mapping_workflow.json"); String textWorkflows = Resources.toString(urlWorkflows, StandardCharsets.UTF_8); HttpEntity mappingEntityWorkflows = new NStringEntity(textWorkflows, ContentType.APPLICATION_JSON); restClient.performRequest("PUT", "/tools", Collections.emptyMap(), mappingEntityTools); restClient.performRequest("PUT", "/workflows", Collections.emptyMap(), mappingEntityWorkflows); if (!published.isEmpty()) { publicStateManager.bulkUpsert(published); } } catch (IOException e) { LOG.error("Could not create elastic search index", e); throw new CustomWebApplicationException(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR); } return Response.ok().entity(published.size()).build(); } return Response.ok().entity(0).build(); }</code><technical_language>above, deleting tools deleting workflows a re-usable method in case want add new indices some day (perhaps notebooks services)</technical_language>

Target:
public Response toolsIndexGet(SecurityContext securityContext) { if (!config.getEsConfiguration().getHostname().isEmpty()) { List<Entry> published = getPublished(); try (RestClient restClient = RestClient .builder(new HttpHost(config.getEsConfiguration().getHostname(), config.getEsConfiguration().getPort(), "http")) .build()) { deleteIndex(restClient, "tools"); deleteIndex(restClient, "workflows"); URL urlTools = Resources.getResource("queries/mapping_tool.json"); String textTools = Resources.toString(urlTools, StandardCharsets.UTF_8); HttpEntity mappingEntityTools = new NStringEntity(textTools, ContentType.APPLICATION_JSON); URL urlWorkflows = Resources.getResource("queries/mapping_workflow.json"); String textWorkflows = Resources.toString(urlWorkflows, StandardCharsets.UTF_8); HttpEntity mappingEntityWorkflows = new NStringEntity(textWorkflows, ContentType.APPLICATION_JSON); restClient.performRequest("PUT", "/tools", Collections.emptyMap(), mappingEntityTools); restClient.performRequest("PUT", "/workflows", Collections.emptyMap(), mappingEntityWorkflows); if (!published.isEmpty()) { publicStateManager.bulkUpsert(published); } } catch (IOException e) { LOG.error("Could not create elastic search index", e); throw new CustomWebApplicationException(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR); } return Response.ok().entity(published.size()).build(); } return Response.ok().entity(0).build(); }