Search in sources :

Example 1 with IndexSettings

use of org.molgenis.data.elasticsearch.generator.model.IndexSettings in project molgenis by molgenis.

the class ClientFacadeTest method testCreateIndexAlreadyExists.

@Test
void testCreateIndexAlreadyExists() throws IOException {
    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(indicesClient.create(any(CreateIndexRequest.class), eq(RequestOptions.DEFAULT))).thenThrow(new ResourceAlreadyExistsException("Index already exists"));
    var exception = assertThrows(IndexAlreadyExistsException.class, () -> clientFacade.createIndex(index, indexSettings, mappings));
    assertEquals(List.of("indexname"), exception.getIndices());
}
Also used : IndexSettings(org.molgenis.data.elasticsearch.generator.model.IndexSettings) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) Index(org.molgenis.data.elasticsearch.generator.model.Index) Mapping(org.molgenis.data.elasticsearch.generator.model.Mapping) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) Test(org.junit.jupiter.api.Test)

Example 2 with IndexSettings

use of org.molgenis.data.elasticsearch.generator.model.IndexSettings in project molgenis by molgenis.

the class ClientFacadeTest method testCreateIndexResponseNotAcknowledgedNoExceptions.

@Test
void testCreateIndexResponseNotAcknowledgedNoExceptions() throws IOException {
    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(indicesClient.create(any(CreateIndexRequest.class), eq(RequestOptions.DEFAULT))).thenReturn(createIndexResponse);
    when(createIndexResponse.isAcknowledged()).thenReturn(false);
    when(createIndexResponse.isShardsAcknowledged()).thenReturn(false);
    clientFacade.createIndex(index, indexSettings, mappings);
    verify(mockAppender).doAppend(matcher(TRACE, "Creating index 'indexname' ..."));
    verify(mockAppender).doAppend(matcher(WARN, "Index 'indexname' creation possibly failed (acknowledged=false)"));
    verify(mockAppender).doAppend(matcher(WARN, "Index 'indexname' creation possibly failed (shards_acknowledged=false)"));
    verify(mockAppender).doAppend(matcher(DEBUG, "Created index 'indexname'."));
}
Also used : IndexSettings(org.molgenis.data.elasticsearch.generator.model.IndexSettings) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) Index(org.molgenis.data.elasticsearch.generator.model.Index) Mapping(org.molgenis.data.elasticsearch.generator.model.Mapping) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) Test(org.junit.jupiter.api.Test)

Example 3 with IndexSettings

use of org.molgenis.data.elasticsearch.generator.model.IndexSettings in project molgenis by molgenis.

the class ClientFacadeTest method testCreateIndexThrowsElasticsearchException.

@Test
void testCreateIndexThrowsElasticsearchException() throws IOException {
    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(indicesClient.create(any(CreateIndexRequest.class), eq(RequestOptions.DEFAULT))).thenThrow(new ElasticsearchException("error creating index"));
    var exception = assertThrows(IndexCreateException.class, () -> clientFacade.createIndex(index, indexSettings, mappings));
    assertEquals(List.of("indexname"), exception.getIndices());
}
Also used : IndexSettings(org.molgenis.data.elasticsearch.generator.model.IndexSettings) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) Index(org.molgenis.data.elasticsearch.generator.model.Index) Mapping(org.molgenis.data.elasticsearch.generator.model.Mapping) FieldMapping(org.molgenis.data.elasticsearch.generator.model.FieldMapping) ElasticsearchException(org.elasticsearch.ElasticsearchException) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) Test(org.junit.jupiter.api.Test)

Example 4 with IndexSettings

use of org.molgenis.data.elasticsearch.generator.model.IndexSettings in project molgenis by molgenis.

the class ElasticsearchService method createIndex.

@Override
public void createIndex(EntityType entityType) {
    Index index = contentGenerators.createIndex(entityType);
    IndexSettings indexSettings = IndexSettings.create();
    Mapping mapping = contentGenerators.createMapping(entityType);
    clientFacade.createIndex(index, indexSettings, Stream.of(mapping));
}
Also used : IndexSettings(org.molgenis.data.elasticsearch.generator.model.IndexSettings) Index(org.molgenis.data.elasticsearch.generator.model.Index) Mapping(org.molgenis.data.elasticsearch.generator.model.Mapping)

Aggregations

Index (org.molgenis.data.elasticsearch.generator.model.Index)4 IndexSettings (org.molgenis.data.elasticsearch.generator.model.IndexSettings)4 Mapping (org.molgenis.data.elasticsearch.generator.model.Mapping)4 CreateIndexRequest (org.elasticsearch.client.indices.CreateIndexRequest)3 Test (org.junit.jupiter.api.Test)3 FieldMapping (org.molgenis.data.elasticsearch.generator.model.FieldMapping)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 ResourceAlreadyExistsException (org.elasticsearch.ResourceAlreadyExistsException)1