1

I have an application where MongoDB is used as primary data store and Elasticsearch for all the searches. Now I'm not sure how to do mapping properly because when annotating the model class with both MongoDB and Elasticsearch @Document annotations(as on the example below) I'm getting the error as follows.

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property insert found for type Customer!

// my model definition excerpt    
@org.springframework.data.mongodb.core.mapping.Document(collection="companies")
    @org.springframework.data.elasticsearch.annotations.Document(indexName = "netnotes", type = "company")
    public class Customer implements Serializable{
     ....
    }

My questions is the same as here How to modeling when use Spring data mongo and Spring data elasticearch? but there is no answer ...

Community
  • 1
  • 1
David Marko
  • 2,477
  • 3
  • 27
  • 58
  • Just read your older post. One question: you want to use ElasticSearch as a "cached" layer for your Mongo store? Or why do you want to store both? – daniel.eichten Oct 02 '15 at 14:43
  • ElasticSearch si not suitable for primary data storage and MongoDB search capabilities doesnt fit our requirements. MongoDb is data store here and ElasticSearch for all our data searches. – David Marko Oct 02 '15 at 16:47
  • Ok, understood. Then I'd use a river to update ES and use just empty derived Entity classes with one Annotation only. You can then also create a custom Service which maps read operations against ES repo and writes to Mongo. – daniel.eichten Oct 03 '15 at 10:52

1 Answers1

1

I had same issue, after some reading realized that Spring JPA bundles and factories repositories together so you have an elastic repository attempting to resolve your mongo entity.

You basically have to put your repositories in separate packages to prevent collision in either your mongo or elastic configuration repository scanning.

For me I just had to isolate my elastic search config to have it work, kept my mongo as before.

Refer to fixes stated in the below links for solutions.

https://jira.spring.io/browse/DATAES-57

How do you use both Spring Data JPA and Spring Data Elasticsearch repositories on the same domain class in a Spring Boot application?

James
  • 95
  • 8