【问题标题】:ElasticSearchRepository null query ot workingElasticSearchRepository 空查询不起作用
【发布时间】:2020-08-24 14:08:35
【问题描述】:

我有审核文件

@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 统计所有 cmets 不为空的评论

在我的存储库中,我这样做了:

int countByApkIdAndCommentIsNotNull(Long apkId);

我收到了这个错误:

{"status":"ERROR","httpCode":500,"message":"发现非法条件 'IS_NOT_NULL (0): [IsNotNull, NotNull]'.","stackTrace":null}

请问为什么这段代码不起作用?

【问题讨论】:

    标签: spring-boot elasticsearch spring-data-elasticsearch


    【解决方案1】:

    目前 Spring Data Elasticsearch 不支持 IsNotNull(或 Exists)。您可以查看支持的关键字in the documentation

    请随意创建 an issue in Jira 以添加此内容。

    【讨论】:

    • 感谢您的回答。我决定做这样的事情int countByApkIdAndCommentNot(Long apkId, String comment); 并用注释字段值 = null 来调用它,但仍然无法得到正确的结果。我尝试使用comment =“”,同样的事情。 Kibana中没有评论时,kibana显示为null,但是为什么我不能使用comment = null?
    【解决方案2】:

    我终于做到了:

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

    【讨论】:

      猜你喜欢
      • 2020-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-20
      • 1970-01-01
      • 1970-01-01
      • 2015-04-18
      相关资源
      最近更新 更多