dimanche 8 mars 2015

Guidance on how to index Elasticsearch documents using Spring Data

My application uses both Spring Data JPA and Spring Data Elasticsearch.


I plan to first persist the JPA entities, then map them to a slightly different java class (the Elasticsearch document) and finally index that document into the Elasticsearch index.


However, I have a few questions as how, where and when to index the documents.



  • Is indexing a time consuming process that should be asynchronous?

  • What design pattern could help me avoid having problematic code such as the following?


saveAdvertisement method from AdvertisementService:



public void saveAdvertisement(Advertisement jpaAdvertisement) {
jpaAdvertisementRepository.save(jpaAdvertisement);
//somehow map the jpa entity to the es document
elasticSearchTemplate.index(esAdvertisement);
}


whereby I have to have two concerns in the same method:



  1. JPA persist

  2. Elasticsearch indexing


Aucun commentaire:

Enregistrer un commentaire