0

I started a project in which I use both Mongo, Elasticsearch and spring boot.

With either technologies by itself, the project works just fine. However with both together, they conflict. I saw this particular article that seemed to be similar to my issue. https://jira.spring.io/browse/DATAES-57 So I tried it out and it the problem is still there.

I put these on the Main class

@EnableAutoConfiguration(exclude = MongoRepositoriesAutoConfiguration.class)
@EnableMongoRepositories(basePackages = "com.searchizi.mongo.repository")
@EnableElasticsearchRepositories(basePackages = "com.searchizi.elasticsearch.repository")
@ComponentScan
public class Application implements CommandLineRunner { … }

A shortened form the the exception trace is this

The class SearchiziUser is in the com.searchizi.mongo.model package. It is not on the Elasticsearch scan path.

Caused by: java.lang.IllegalArgumentException: Unable to identify index name. SearchiziUser is not a Document. Make sure the document class is annotated with @Document(indexName="foo")
    at org.springframework.util.Assert.isTrue(Assert.java:65)
    at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.getPersistentEntityFor(ElasticsearchTemplate.java:869)
    at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.createIndexIfNotCreated(ElasticsearchTemplate.java:684)
    at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.createIndex(ElasticsearchTemplate.java:135)
    at org.springframework.data.elasticsearch.repository.support.AbstractElasticsearchRepository.createIndex(AbstractElasticsearchRepository.java:80)
    at org.springframework.data.elasticsearch.repository.support.AbstractElasticsearchRepository.<init>(AbstractElasticsearchRepository.java:72)
    at org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.<init>(SimpleElasticsearchRepository.java:36)

The scanning for each repository type should be separated but apparently it is not. Any idea what to do?

2 Answers 2

1

This is clearly a bug in Spring Data Elasticsearch as it seems to scan for domain types in packages it actually shouldn't. I filed DATAES-?? for you. Also, I filed a ticket so that Spring Data Elasticsearch supports the new multi-store configuration improvements so that you shouldn't have to explicitly configure separate packages.

On a side note, excluding the auto-configuration is not necessary if you set up @EnableMongoRepositories as it will automatically disable Spring Boot's auto-configuration.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks I will create an example project and attach a link to it in jira.spring.io/browse/DATAES-136
0

I faced this exception and I resolved by change version of elasticsearch and mongodb lib versions

<!-- Spring data mongodb -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
            <version>1.7.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
            <version>1.10.0.RELEASE</version>
        </dependency>

        <!-- mongodb java driver -->
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
        </dependency>

        <!-- ELASTICSEARCH -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-elasticsearch</artifactId>
            <version>1.2.0.RELEASE</version>
        </dependency>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.