What is the best way to use Spring and ElasticSearch? - spring

I have to implement some application by using springframework.
All i have to do is just select from repository (no RDBMS, maybe lucene or elastic search core) and Display some view pages for customers. that is not save or update but read.
What is the best way to select for repositories in spring framework ?

You can use spring-data-elasticsearch which is the Spring Data implementation for ElasticSearch.
In order to get started, you may like to refer to https://www.mkyong.com/spring-boot/spring-boot-spring-data-elasticsearch-example/ which explains the integration with an example. Although it is a bit old but provide you with enough information to get it working.

Related

What is the best way to maintain queries in Spring boot application?

In My Application, Using the below technologies
Spring boot 2.7.x
Cassandra
spring batch 5. x
java 11
As part of this, I need to extract data from the Cassandra database and need to write out the file
so here I need to use queries to fetch data so
just want to know what is the best way to maintain all queries at one place so any query changes come in the future, I shouldn't build the app rather just need to modify the query.
Using a repository class is necessary. If you are using JPA i recommend using a repository for each Entity class. With JDBC it is possible to create a single repository which contains all the queries. To access the query methodes i would use a service class. In this way your code is structured well and maintainable for future changes.

In-memory elastic search

I have a scenario where I want to query database once and after that want to cache the whole data in memory.
I got the suggestion for in-memory elastic search, I have googled it understand what it is and how can I implement it in my spring boot application, but I didn't find any appropriate solution.
Any suggestion on this like how can I implement this in my spring boot app and what would be the approach.
There used to be an in-memory storage type in Elasticsearch in 1.x, but it has been removed in 2.x and later versions. If your working set is small enough it might be mapped to memory in full, but you cannot really control that other than having enough memory.
If you want to run an embedded / in-process Elasticsearch with your Spring Boot application that feature was removed in 5.x and this blog post explains why.

Spring boot , Elasticsearch

Searched over the net but unable to find the satisfying approach.
I am new to spring boot and aware of starter dependancies,
I want to develop a springboot app using elastic search as a storage system.
Wherever i searched i found that somewhere my service class will have to implement some interface from springframework for ES crud operations.
Is there any other way without implementing or extending the components.
I myself want to create transport client and want to query ES by my code or methods not by overidden ones.
Please if you ahve ever seen any projects you can redirect me to that link .
Thanks.
Assuming I understand you correctly, you can use the Elasticsearch REST client: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low.html
You supply the JSON entities for the queries and parse the responses yourself. Its pretty basic in what it does, so you're not dependent on a lot of third party stuff to perform operations.

What options do I have regarding indexing PDFs while running on Elasticsearch 1.x and Spring Data 1.x, especially if I want to upgrade?

We have a new requirement on our Elasticsearch - to index PDFs. We are still running on Elasticsearch version 1.x (and Spring Data 1.3.4).
I look at the documentation for Elasticsearch 5 and they have new ways of supporting PDFs in 5 (and I would like to upgrade).
So given all this the way I see it I have the following options:
Sit tight and wait for Spring Data to support Elasticsearch 5. This is viable if it is not too far away (please let us know, Spring Data and Elasticsearch dev) although given the business urgency on this feature I don't think I have much leeway
Move off Spring data altogether - this is not as crazy as it sounds as given the complexity of my queries I don't use the Spring Data repositories a great deal. I do however use them for inserting data. I would have to provide my own implementations of the current repository interfaces. It would be work but I wouldn't need to wait for any one and would not need to use any outdated plugins etc
Somehow run on Elasticsearch 5 with Spring Data 2.x/3.x. Will this work at all? Chances are it probably won't even startup.
Upgrade my Elasticsearch/Spring Data to 2.x and use the "old" way of indexing PDFs.
Which option is the best way to go?

Hibernate with MongoDB

I'm looking for resources showing how to integrate MongoDB with Hibernate (preferably from within spring) so that I can switch between a RDBMS and a NoSql alternative: does anyone have experience doing this?
You can't easily do this. The point of Hibernate is to map Java Objects to a relational database. Although Hibernate abstracts a lot of details away you still need to understand how relational databases work with things such as foreign and primary keys, and the performance implications of queries you run. MongoDB requires an entire different way of designing your database focusing on objects instead of columns and tables. while you may be able to create a Hibernate dialect for MongoDB creating a design that would work on both a relational database and a NoSql database will give you a design that works poorly on both.
What about Hibernate OGM? It provides JPA for No-SQL databases.
Migration would be easier if you use Spring MongoTemplate (similar to HibernateTemplate). Among its features is support for JPA annotations (although, I'm not sure to what extent).
See more: http://www.springsource.org/spring-data/mongodb
You'll need the following:
Add spring-data-mongodb JAR to your project (available in maven
central).
Add mongo-java-driver JAR to your project (available in
maven central).
Use the provided MongoTemplate class in a similar
manner to HibernateTemplate. E.g.:
mongoTemplate.findById(id, MyClass.class);
mongoTemplate.insert(myObject);
Here's a concrete example with code: use-spring-and-hibernate-with-mongodb
If you are using Java then you can use Hibernate OGM it provides Java Persistence support for NoSQL databases.
For more details visit http://hibernate.org/ogm/
There is nice work done earlier as:
http://pragmaticintegrator.wordpress.com/2011/07/14/use-spring-and-hibernate-with-mongodb/
http://pragmaticintegrator.wordpress.com/2011/07/27/unit-test-your-springhibernate-and-mongodb-setup/#comments
refer to these links. it will be helpful to you.
There is also kundera, which uses JPA-annotations to read/write your object from/to a mongodb. If you ara familiar with hibernate, it should be quite straightformard to use.
I recently tried Morphia, which takes the same approach, but with its own annotations.
It works fine
May this blog helps: http://drorbr.blogspot.com/2010/02/migrating-springhibernate-application.html
Here Dror Bereznitsky describes nicely how to integrate a sping/hibernate based solution with mongodb.
For the sake of completeness, PlayORM also supports MongoDB now. PlayORM is an object NoSQL mapping solution so you can write POJO’s and let it deal with all the details of marshalling/unmarshalling to MongoDB. Visit its documentation here
I think Hibernate provides desired functionality. Take a look at this, found on their official website:
Mixing several NoSQL datastores in one application, e.g. use Neo4j for your friendship graph and MongoDB for your blog posts. Or mix NoSQL and relational databases.
reference
Well just to give you an example, I am doing somehting simmilar. In ColdFusion, Hibernate is integrated and in order to save your Hibernate Object, you hvae to do EntitySave(Obj). However what we have done is build the Orm object, and then use a mongoDB Coldfusion component and just save the object by going mongo.Save(obj,collectionName).

Resources