I have a @Document "Project" class with the following variables:
@Document(indexName = "project-index")
public class Project {
...
@JsonProperty("import_id")
private Long importId;
private String title;
...
//getters and setters
}
My JSON is like the following
{
"_id" : ObjectId("5269fd92e4b0c74e42976c91"),
...
"import_id" : NumberLong(1),
"title" : "Something",
...
}
And my @Repository class is like:
@Repository
public interface ProjectRepository extends ElasticsearchCrudRepository<Project, String>{
Page<Project> findByImportId(Long importId, Pageable page);
Page<Project> findByTitleLike(String title, Pageable page);
}
The problem is that findByImportId is not getting any data, while findByTitleLike is working fine and letting me fetch data, I tried with different configurations, but seems that SpringData is not resolving that the field that has to search by import_id, even when it has @JsonProperty configured. Moreover, I tried to change the variable name to import_id (also the getter and setter) but in such case, when I tried to use findByImport_Id, findByImport_id, findByImport__Id or findByImport__id get an error at runtime.
Any idea how can I map a db variable with an underscore with a java variable that later could be recognized by ElasticsearchCrudRepository?
Thanks
from the Spring Docs:
If your property names contain underscores (e.g. first_name) you can escape the underscore in the method name with a second underscore. For a first_name property the query method would have to be named findByFirst__name(…).
So it seems the correct would be findByImport__id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With