问题描述
@Document(indexName = "apkreview")
public class ApkReview {
@Id //The unique id
private Long id;
private Long apkId;
private String comment;
private Date commentDate;
//each review is linked to one user
private String appUserId;
@Transient
@JsonProperty
private String username;
//app user stars
private int stars;
private String response;
private Date responseDate;
}
在我的存储库中,我这样做:
int countByApkIdAndCommentIsNotNull(Long apkId);
我收到此错误:
{“状态”:“错误”,“ httpCode”:500,“消息”:“发现非法条件 'IS_NOT_NULL(0):[IsNotNull,NotNull]'。”,“ stackTrace”:null}
请为什么该代码不起作用?
解决方法
Spring Data Elasticsearch目前不支持
IsNotNull (或 Exists )。您可以检查受支持的关键字in the documentation。
可以随意创建an issue in Jira来添加此内容。
,我终于做到了:
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(QueryBuilders.matchQuery("apkId",apkId)
.operator(Operator.AND))
.withQuery(QueryBuilders.existsQuery("comment"))
.build();
Page<ApkReview> apkList = apkReviewRepository.search(searchQuery);
// count apk review with comment
int reviewWithNoteNumber = (int) apkList.getTotalElements();