Reputation: 31
I have a interface which has function used to query ElasticSearch. It extends the ElasticsearchRepository for doing it.
public interface HouseholdRepository extends ElasticsearchRepository<SearchHouseholdESBean, String> {
List<SearchHouseholdESBean> findByPhoneNumberAndActiveInd(String phoneNumber, String activeInd);
The problem is how do i call this in my business class where i need to get the results. This being an interface , i can't create an object of this to call the methods. Also, the implementation is implicit to the jars in the Elastic Search.
Upvotes: 0
Views: 229
Reputation: 2109
To use elastichsearch repositories you must follow the next steps:
1. add annotation @EnableElasticsearchRepositories
on your SpringBootApplication
@SpringBootApplication
@EnableElasticsearchRepositories
public class Application {
//...
2. Make sure that the interface HouseholdRepository
is scanned by the spring-boot application. You can simple achieve this by placing it under the same root package as your Application
class.
3.You will just @Autowire HouseholdRepository
in your service without further changes. The idea behind spring boot data is that the code will be generated based on that interface.
OBS: make sure that you have the proper project dependencies. You should depend on spring-boot-starter-data-elasticsearch
to avoid extra configuration effort.
Upvotes: 1