Reputation: 1322
I have Review document
@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;
}
I want to count all reviews by apkId where comments are not null
In my repository i did this:
int countByApkIdAndCommentIsNotNull(Long apkId);
I got this error :
{"status":"ERROR","httpCode":500,"message":"Illegal criteria found 'IS_NOT_NULL (0): [IsNotNull, NotNull]'.","stackTrace":null}
Please why this code is not working ?
Upvotes: 0
Views: 1072
Reputation: 1322
I finally did it like this:
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();
Upvotes: 0
Reputation: 19431
Currently IsNotNull (or Exists) are not supported by Spring Data Elasticsearch. You can check the supported keywords in the documentation.
Feel free to create an issue in Jira to have this added.
Upvotes: 1