Java Spring Boot ElasticSearch存储库-@Id带类,而不是@Id带字符串
应该很简单,但我找不到解决这个问题的方法。我有一个配置文件存储库,其中有一个class@Id用户界面:Java Spring Boot ElasticSearch存储库-@Id带类,而不是@Id带字符串,java,spring-boot,
elasticsearch,spring-repositories,Java,Spring Boot,
elasticsearch,Spring Repositories,应该很简单,但我找不到解决这个问题的方法。我有一个配置文件存储库,其中有一个class@Id用户界面: public interface ProfileRepository extends ElasticsearchRepository<Profile, User> { 用户是: public class User { private String id; private String role; [... plus getters, setters, co
public interface ProfileRepository extends ElasticsearchRepository<Profile, User> {
用户是:
public class User {
private String id;
private String role;
[... plus getters, setters, constructors]
保存配置文件没有问题,因为您可以看到ElasticSearch放置用户的字符串表示:
"_id": "User(id=TestID, role=TestRole)",
"_score": 1.0,
"_source": {
"_class": "com.example.model.Profile",
"user": {
"id": "TestID",
"role": "TestRole"
},
但在那之后,我无法检索任何配置文件。
如果我做了以下任何一项:
profileRepository.findAll();
profileRepository.customFindByIdRole("TestID", "TestRole");
profileRepository.findById(new User("TestID", "TestRole"));
我总是得到:
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [com.example.model.User]
注意:customFindByIdRole的实现方式如下:
@Query("{\"query\": { \"bool\": { \"must\": [ { \"match\": { \"user.id\": \"?0\" } }, { \"match\": { \"user.role\": \"?1\" } } ] } }}")
Profile customFindByIdRole(String id, String role);
另外请注意,如果我添加任何Spring JPA依赖项,很多依赖项都会被破坏,所以我不确定是否可以依赖@Embedded@IdClass等
@Query("{\"query\": { \"bool\": { \"must\": [ { \"match\": { \"user.id\": \"?0\" } }, { \"match\": { \"user.role\": \"?1\" } } ] } }}")
Profile customFindByIdRole(String id, String role);