elasticsearchrepository空查询不起作用

sauutmhj  于 2021-06-15  发布在  ElasticSearch
关注(0)|答案(2)|浏览(549)

我有审查文件

@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;
}

我想按apkid计算评论不为空的所有评论
在我的存储库中,我这样做了:

int countByApkIdAndCommentIsNotNull(Long apkId);

我有个错误:
{“status”:“error”,“httpcode”:500,“message”:“找到的非法条件'is\u not\u null(0):[isnotnull,notnull]'”,“stacktrace”:null}
请问为什么这个代码不起作用?

dw1jzc5e

dw1jzc5e1#

我终于这样做了:

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();
qlvxas9a

qlvxas9a2#

目前,spring data elasticsearch不支持isnotnull(或exists)。您可以检查文档中支持的关键字。
请随意在jira中创建一个问题来添加这个。

相关问题