ramanareddy438
ramanareddy438

Reputation: 145

findBy query method not woking in spring data elasticsearch

I am using Spring-data-elasticsearch plugin for retrieving information from elasticsearch server. Below is the repository class:

public interface ActorRepository extends ElasticsearchRepository<Actor, Integer> {
    public Actor findByActorId(Integer actorId);
    public Iterable<Actor> findByFirstName(String firstName);
    public Page<Actor> findByLastName(String lastName, Pageable pageable);
    //public Iterable<Actor> findByLastName(String lastName);
}

Usage of ActorRepository:

@Resource
ActorRepository actorRepository;
Actor actor1 = this.actorRepository.findOne(actorId); // Working perfectly
System.out.println("findOne Method :" + actor1);
Iterable<Actor> actors = this.actorRepository.findAll(); // Works perfectly
for(Actor actor : actors) {
    System.out.println("Each Actor :" + actor);
}

Actor actor214 = this.actorRepository.findByActorId(214); // Not working. Reurning null
System.out.println("findByActorId214 :" + actor214);    

I am getting null response from the above method invocation. I don't know what I am missing here.

FYI:

I have specified which method is working and which method is not working beside the method call as comment.

Please let me know if you needed any more information. thanks in advance for the help.

Upvotes: 4

Views: 1907

Answers (1)

ramanareddy438
ramanareddy438

Reputation: 145

The problem I noticed is due to improper mapping of the POJO with respect to elasticsearch data. I was using nested objects in the POJO. So I should specify that nested field types as FieldType.Nested using @Field spring annotation. After specifying all those mappings it worked good.

Upvotes: 1

Related Questions