@Test void testCreateIndexThrowsElasticsearchException() { Index index = Index.create("indexname"); IndexSettings indexSettings = IndexSettings.create(1, 1); FieldMapping idField = FieldMapping.create("id", MappingType.TEXT, emptyList()); Mapping mapping = Mapping.create("type", ImmutableList.of(idField)); Stream<Mapping> mappings = Stream.of(mapping); when(indicesAdminClient.prepareCreate("indexname")).thenReturn(createIndexRequestBuilder); when(createIndexRequestBuilder.setSettings(any(Settings.class))) .thenReturn(createIndexRequestBuilder); when(createIndexRequestBuilder.addMapping(eq("type"), any(Mapping.class))) .thenReturn(createIndexRequestBuilder); when(createIndexRequestBuilder.get()) .thenThrow(new ElasticsearchException("error creating index")); Exception exception = assertThrows( IndexException.class, () -> clientFacade.createIndex(index, indexSettings, mappings)); assertThat(exception.getMessage()).containsPattern("Error creating index 'indexname'\\."); }
public void createIndex(Index index, IndexSettings indexSettings, Stream<Mapping> mappingStream) { if (LOG.isTraceEnabled()) { LOG.trace("Creating index '{}' ...", index.getName()); } CreateIndexRequestBuilder createIndexRequest = createIndexRequest(index, indexSettings, mappingStream); CreateIndexResponse createIndexResponse; try { createIndexResponse = createIndexRequest.get(); } catch (ResourceAlreadyExistsException e) { LOG.debug("", e); throw new IndexAlreadyExistsException(index.getName()); } catch (ElasticsearchException e) { LOG.error("", e); throw new IndexException(format("Error creating index '%s'.", index.getName())); } if (!createIndexResponse.isAcknowledged()) { LOG.warn("Index '{}' creation possibly failed (acknowledged=false)", index.getName()); } if (!createIndexResponse.isShardsAcked()) { LOG.warn("Index '{}' creation possibly failed (shards_acknowledged=false)", index.getName()); } if (LOG.isDebugEnabled()) { LOG.debug("Created index '{}'.", index.getName()); } }
ClientFacade implements Closeable { public void createIndex(Index index, IndexSettings indexSettings, Stream<Mapping> mappingStream) { if (LOG.isTraceEnabled()) { LOG.trace("Creating index '{}' ...", index.getName()); } CreateIndexRequestBuilder createIndexRequest = createIndexRequest(index, indexSettings, mappingStream); CreateIndexResponse createIndexResponse; try { createIndexResponse = createIndexRequest.get(); } catch (ResourceAlreadyExistsException e) { LOG.debug("", e); throw new IndexAlreadyExistsException(index.getName()); } catch (ElasticsearchException e) { LOG.error("", e); throw new IndexException(format("Error creating index '%s'.", index.getName())); } if (!createIndexResponse.isAcknowledged()) { LOG.warn("Index '{}' creation possibly failed (acknowledged=false)", index.getName()); } if (!createIndexResponse.isShardsAcked()) { LOG.warn("Index '{}' creation possibly failed (shards_acknowledged=false)", index.getName()); } if (LOG.isDebugEnabled()) { LOG.debug("Created index '{}'.", index.getName()); } } }
ClientFacade implements Closeable { public void createIndex(Index index, IndexSettings indexSettings, Stream<Mapping> mappingStream) { if (LOG.isTraceEnabled()) { LOG.trace("Creating index '{}' ...", index.getName()); } CreateIndexRequestBuilder createIndexRequest = createIndexRequest(index, indexSettings, mappingStream); CreateIndexResponse createIndexResponse; try { createIndexResponse = createIndexRequest.get(); } catch (ResourceAlreadyExistsException e) { LOG.debug("", e); throw new IndexAlreadyExistsException(index.getName()); } catch (ElasticsearchException e) { LOG.error("", e); throw new IndexException(format("Error creating index '%s'.", index.getName())); } if (!createIndexResponse.isAcknowledged()) { LOG.warn("Index '{}' creation possibly failed (acknowledged=false)", index.getName()); } if (!createIndexResponse.isShardsAcked()) { LOG.warn("Index '{}' creation possibly failed (shards_acknowledged=false)", index.getName()); } if (LOG.isDebugEnabled()) { LOG.debug("Created index '{}'.", index.getName()); } } ClientFacade(Client client); }
ClientFacade implements Closeable { public void createIndex(Index index, IndexSettings indexSettings, Stream<Mapping> mappingStream) { if (LOG.isTraceEnabled()) { LOG.trace("Creating index '{}' ...", index.getName()); } CreateIndexRequestBuilder createIndexRequest = createIndexRequest(index, indexSettings, mappingStream); CreateIndexResponse createIndexResponse; try { createIndexResponse = createIndexRequest.get(); } catch (ResourceAlreadyExistsException e) { LOG.debug("", e); throw new IndexAlreadyExistsException(index.getName()); } catch (ElasticsearchException e) { LOG.error("", e); throw new IndexException(format("Error creating index '%s'.", index.getName())); } if (!createIndexResponse.isAcknowledged()) { LOG.warn("Index '{}' creation possibly failed (acknowledged=false)", index.getName()); } if (!createIndexResponse.isShardsAcked()) { LOG.warn("Index '{}' creation possibly failed (shards_acknowledged=false)", index.getName()); } if (LOG.isDebugEnabled()) { LOG.debug("Created index '{}'.", index.getName()); } } ClientFacade(Client client); void createIndex(Index index, IndexSettings indexSettings, Stream<Mapping> mappingStream); boolean indexesExist(Index index); void deleteIndex(Index index); void refreshIndexes(); long getCount(Index index); long getCount(QueryBuilder query, Index index); SearchHits search(QueryBuilder query, int from, int size, List<Index> indexes); SearchHits search(QueryBuilder query, int from, int size, Sort sort, Index index); Aggregations aggregate(
      List<AggregationBuilder> aggregations, QueryBuilder query, Index index); Explanation explain(SearchHit searchHit, QueryBuilder query); void index(Index index, Document document); void deleteById(Index index, Document document); void processDocumentActions(Stream<DocumentAction> documentActions); @Override void close(); }
ClientFacade implements Closeable { public void createIndex(Index index, IndexSettings indexSettings, Stream<Mapping> mappingStream) { if (LOG.isTraceEnabled()) { LOG.trace("Creating index '{}' ...", index.getName()); } CreateIndexRequestBuilder createIndexRequest = createIndexRequest(index, indexSettings, mappingStream); CreateIndexResponse createIndexResponse; try { createIndexResponse = createIndexRequest.get(); } catch (ResourceAlreadyExistsException e) { LOG.debug("", e); throw new IndexAlreadyExistsException(index.getName()); } catch (ElasticsearchException e) { LOG.error("", e); throw new IndexException(format("Error creating index '%s'.", index.getName())); } if (!createIndexResponse.isAcknowledged()) { LOG.warn("Index '{}' creation possibly failed (acknowledged=false)", index.getName()); } if (!createIndexResponse.isShardsAcked()) { LOG.warn("Index '{}' creation possibly failed (shards_acknowledged=false)", index.getName()); } if (LOG.isDebugEnabled()) { LOG.debug("Created index '{}'.", index.getName()); } } ClientFacade(Client client); void createIndex(Index index, IndexSettings indexSettings, Stream<Mapping> mappingStream); boolean indexesExist(Index index); void deleteIndex(Index index); void refreshIndexes(); long getCount(Index index); long getCount(QueryBuilder query, Index index); SearchHits search(QueryBuilder query, int from, int size, List<Index> indexes); SearchHits search(QueryBuilder query, int from, int size, Sort sort, Index index); Aggregations aggregate(
      List<AggregationBuilder> aggregations, QueryBuilder query, Index index); Explanation explain(SearchHit searchHit, QueryBuilder query); void index(Index index, Document document); void deleteById(Index index, Document document); void processDocumentActions(Stream<DocumentAction> documentActions); @Override void close();  }