@Override public GetResponse get(GetRequest getRequest) throws IOException { try { return transportClient.get(getRequest).get(); } catch (Exception e) { throw new IOException(e); } }
/** * Check health of cluster. */ @Override public Health getClusterHealth() { try { ClusterHealthResponse chr = esProvider.getClient().admin() .cluster().health(new ClusterHealthRequest()).get(); return Health.valueOf( chr.getStatus().name() ); } catch ( Exception ex ) { ex.printStackTrace(); logger.error( "Error connecting to ElasticSearch", ex.getMessage() ); } // this is bad, red alert! return Health.RED; }
private boolean indexExists(final String index) { IndicesExistsRequest request = new IndicesExistsRequest(index); try { return elasticSearchClient.admin().indices().exists(request).get().isExists(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } }
private boolean doesMappingExist(final String index, final String mappingName) { GetMappingsRequest request = new GetMappingsRequest() .indices(index); try { GetMappingsResponse response = elasticSearchClient.admin() .indices() .getMappings(request) .get(); return response.getMappings() .get(index) .containsKey(mappingName); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } }
IndicesExistsResponse indicesExistResponse = indicesExistBld.execute().get(); if ( !indicesExistResponse.isExists() ) { showError( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.Error.NoIndex" ) ); String shards = "" + lafInd.get().getSuccessfulShards() + "/" + lafInd.get().getTotalShards(); showMessage( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.TestIndex.TestOK", shards ) ); break;
private void deleteAllIndices() { ImmutableOpenMap<String, IndexMetaData> indices = elasticSearchClient.admin().cluster() .prepareState().get().getState() .getMetaData().getIndices(); indices.forEach(cursor -> { try { elasticSearchClient.admin() .indices() .delete(new DeleteIndexRequest(cursor.value.getIndex().getName())) .get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } }); }
static void blockOnFutures(List<ActionFuture<Void>> futures) { for (ActionFuture<Void> future : futures) { try { future.get(); } catch (ExecutionException e) { // Ignore as we are only interested in waiting for the close process to complete. Logging // close exceptions happens elsewhere. } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } }
private void deleteIndex(final String fromIndex) { try { // sync client.admin().indices().delete(new DeleteIndexRequest(fromIndex)).get(); } catch (InterruptedException e) { System.err.println("interrupted while deleting index " + fromIndex); e.printStackTrace(); } catch (ExecutionException e) { System.err.println("failed to deleting index " + fromIndex); e.printStackTrace(); } }
@Override public Void execute(final Client client) throws ElasticsearchException { try { IndexResponse response = client.index(request).get(); } catch (Exception e) { throw new EsSetupRuntimeException(e); } return null; }
@Override public Void execute(final Client client) throws ElasticsearchException { try { DeleteResponse response = client.delete(request).get(); } catch (Exception e) { throw new EsSetupRuntimeException(e); } return null; }
@Override public Void execute(final Client client) throws ElasticsearchException { try { DeleteResponse response = client.delete(request).get(); } catch (Exception e) { throw new EsSetupRuntimeException(e); } return null; }
@Override public Void execute(final Client client) throws ElasticsearchException { try { IndexResponse response = client.index(request).get(); } catch (Exception e) { throw new EsSetupRuntimeException(e); } return null; }
@SneakyThrows({ ExecutionException.class, InterruptedException.class }) protected boolean indexExist(String indexName) { // check if existing before final ActionFuture<IndicesExistsResponse> indexExistFuture = esClient.getClient().admin().indices().exists(new IndicesExistsRequest(indexName)); IndicesExistsResponse response; response = indexExistFuture.get(); return response.isExists(); }
@Override public Void execute(final Client client) throws ElasticsearchException { try { PutIndexTemplateResponse response = client.admin().indices().execute(PutIndexTemplateAction.INSTANCE, request).get(); if (!response.isAcknowledged()) { throw new EsSetupRuntimeException("Exception when putting index template"); } } catch (Exception e) { throw new EsSetupRuntimeException(e); } return null; }
@Override public Void execute(final Client client) throws ElasticsearchException { try { PutIndexTemplateResponse response = client.admin().indices().execute(PutIndexTemplateAction.INSTANCE, request).get(); if (!response.isAcknowledged()) { throw new EsSetupRuntimeException("Exception when putting index template"); } } catch (Exception e) { throw new EsSetupRuntimeException(e); } return null; }
@Override protected void processBatch(List<ElasticsearchDocument> batch) throws ExecutionException, InterruptedException { BulkRequestBuilder bulk = client.prepareBulk(); batch.forEach(entry -> bulk.add( client.prepareIndex(indexFactory.createIndex(), typeName).setSource(entry.bytes(), XContentType.JSON))); bulk.execute().get(); }
@Test public void TestEmpty() throws ExecutionException, InterruptedException { CacheStatsPerFieldResponse r = client.admin().cluster() .execute(CacheStatsPerFieldAction.INSTANCE, new CacheStatsPerFieldRequest()) .get(); for (CacheStatsPerFieldStats s : r) { assertThat(s.fieldEntries().size(), equalTo(0)); } }
private SearchResponse searchPublishedMessages(int limit, QueryBuilder query) throws InterruptedException, ExecutionException { return elasticClient.prepareSearch(SchemaManager.PUBLISHED_ALIAS_NAME) .setTypes(SchemaManager.PUBLISHED_TYPE) .setTrackScores(true) .setQuery(query) .addSort(TIMESTAMP_SECONDS, SortOrder.ASC) .setSize(limit) .execute() .get(); }
private void awaitUntilPersisted(QueryBuilder query) { await().atMost(ONE_MINUTE).until(() -> { SearchResponse response = elasticsearch.client().prepareSearch(indexFactory.createIndex()) .setTypes(SchemaManager.SENT_TYPE) .setQuery(query) .execute().get(); return response.getHits().getTotalHits() == 1; }); }
private void awaitUntilMessageIsIndexed(QueryBuilder query) { await().atMost(ONE_MINUTE).until(() -> { SearchResponse response = elasticsearch.client().prepareSearch(frontendIndexFactory.createIndex()) .setTypes(SchemaManager.PUBLISHED_TYPE) .setQuery(query) .execute().get(); return response.getHits().getTotalHits() == 1; }); }