我正在使用在带有 Spring boot 的 docker 容器上运行的 elasticSearch。
以下是问题的详细信息。
Caused by: org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract org.springframework.data.domain.Page org.springframework.data.elasticsearch.repository.ElasticsearchRepository.searchSimilar(java.lang.Object,java.lang.String[],org.springframework.data.domain.Pageable); Reason: Failed to create query for method public abstract org.springframework.data.domain.Page org.springframework.data.elasticsearch.repository.ElasticsearchRepository.searchSimilar(java.lang.Object,java.lang.String[],org.springframework.data.domain.Pageable); No property 'searchSimilar' found for type 'Items'
以下是物品表
@Document(indexName = "itemindex")
public class Items{
@Id
@UuidGenerator
private String id;
@PrePersist
public void onPrePersist() {
if (created == null) {
created = new Date(); // Set creation date
}
}
@Column
@Field(type=FieldType.Text,name="title")
private String title;
@Column
@Field(type=FieldType.Text,name="description")
private String description;
@Column
@Field(type=FieldType.Float,name="basePrice")
private BigDecimal basePrice;
@OneToMany(
fetch = FetchType.LAZY,
cascade = CascadeType.ALL)
private List<Bid> bids;
@Column
private String currency;
@ManyToOne
@Field(type=FieldType.Nested,name="creator")
private UserModel creator;
@ElementCollection
private List<String> pictures;
@ManyToOne
@Field(type=FieldType.Nested,name="organization")
private Organization organization;
@Column
private Date expiryTime;
@Column
private String category;
@Column
@Field(type=FieldType.Date,name="created")
private Date created;
@Column
private Date updated;
@Column
@Field(type=FieldType.Boolean,name="isDeleted")
private boolean isDeleted;
@PreUpdate
protected void onUpdate() {
updated = new Date();
}
public Boolean addBid(Bid bid) {
if (!this.bids.contains(bid)) {
this.bids.add(bid);
bid.setItem(this);
return Boolean.TRUE;
}
return Boolean.FALSE;
}
}
下方存储库界面
public interface ItemElasticSearchRepository extends ElasticsearchRepository<Items,String>{
}
怎么称呼
@Autowired
private ItemElasticSearchRepository itemElasticSearchRepository;
...
@CacheEvict(value = "items", allEntries = true)
private Items saveItem(Items item){
Items savedItem=itemRepository.save(item);
itemElasticSearchRepository.save(item);
return savedItem;
}
我没有直接调用属性 searchSimilar 。我最初的想法是因为我使用 @CacheEvict 并使用弹性存储库的 save 方法,它可能与 itemElasticSearchRepository 内部的方法和扩展 JPARepository 的 itemRepository 内部的方法冲突。