I have made an application using Springboot and running Elasticsearch in the background, everything works fine and when I am saving data by passing some json data it returns the right result(the number of inserted data) but when I am trying to fetch the datas it is returning empty array symbols.
Not getting what's happening can anybody please help.
And I have attached the screenshots of my postman requests.
For Saving data

For Fetching data

My api class:-
@SpringBootApplication
@RestController
public class SpringBootElasticserachExampleApplication {
@Autowired
private HeroRepository repository;
@PostMapping("/saveHero")
public int saveCustomer(@RequestBody List<Hero> heros) {
repository.saveAll(heros);
return heros.size();
}
@GetMapping("/findAll")
public Iterable<Hero> findAllHeros() {
return repository.findAll();
}
}
Model class:
@Document(indexName="movie",type="hero",shards=2)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Hero {
@Id
private String id;
private String firstname;
private String lastname;
private int age;
}
Repository:
public interface HeroRepository extends ElasticsearchRepository<Hero, String>{
List<Hero> findByFirstname(String firstName);
}