Description

Indices are not being created when using reactive repositories

Expectation

Given the following configuration: RestApplication.kt

@SpringBootApplication
@EnableReactiveElasticsearchRepositories
class RestApplication

fun main(args: Array<String>) {
    runApplication<RestApplication>(*args)
}

CustomerRepository

@Repository
interface CustomerRepository : ReactiveCrudRepository<Customer, UUID> {
    fun findByNameOrEmail(
        name: String,
        email: String,
        pageable: Pageable
    ): Flux<Customer>
}

Customer.kt

@Document(
    indexName = "customer",
    shards = 3,
    replicas = 3,
    refreshInterval = "1s",
    createIndex = true
)
@Setting(settingPath = "es-config/analyzers.json")
data class Customer(
    @Id val id: UUID,
    @Field(type = FieldType.Keyword) val firstName: String,
    @Field(type = FieldType.Keyword) val lastName: String,
    @Field(type = FieldType.Text, analyzer = "autocomplete_index", searchAnalyzer = "autocomplete_search") val email: String,
    @Field(type = FieldType.Text, analyzer = "autocomplete_index", searchAnalyzer = "autocomplete_search")
    val name: String = "$firstName $lastName",
    val phoneNumbers: List<String>,
    var createdAt: Long
)

When the application has started Then the index must have been created with the configured properties

Current behavior

No index was created

Observations

Debugging the code I've noticed that the SimpleElasticsearchRepository extends AbstractElasticsearchRepository which has in its constructor the following code:

        this.indexOperations = operations.indexOps(this.entityClass);
        try {
            if (createIndexAndMapping() && !indexOperations.exists()) {
                createIndex();
                putMapping();
            }
        } catch (Exception exception) {
            LOGGER.warn("Cannot create index: {}", exception.getMessage());
        }

But its reactive sibling SimpleReactiveElasticsearchRepository has no similar strategy or block.

Comment From: philwebb

This looks like an issue in the Spring Data Elastic Search project. I've raised a JIRA for them to look into. You can subscribe to https://jira.spring.io/browse/DATAES-906 for updates.

Comment From: sothawo

this is implemented since version 4.1 M1 (2020.0.0), so it's available in the milestone repo