【问题标题】:ElasticsearchRepository- findAllByPostId returning unexpected results. Possible issue with the IDElasticsearchRepository- findAllByPostId 返回意外结果。身份证可能有问题
【发布时间】:2020-11-02 07:42:59
【问题描述】:

我有模型 PostComment,它们的 ID 带有 @Id 注释。

保存评论时,我会同时保存他的 ID 和 PostId

@Document(indexName = "comments")
@Data
public class Comment {

@Id
private String commentId;

private String postId;

我的问题是,当使用 PostId“-z6OOHMBrExEkdIZ_aCH”搜索所有 cmets 时,这将返回数据库中的所有 cmets...

看起来最初的连字符/破折号有问题。

你知道如何避免吗?是否可以将@Id 定义为不包含此(可能还有其他)特殊字符。

提前谢谢你!

编辑:

Spring Data 方法:

List<Comment> findAllByPostIdOrderByCreationDateAsc(String postId, Pageable pageable);

【问题讨论】:

  • 你用的是什么spring data jpa方法?
  • List findAllByPostIdOrderByCreationDateAsc(String postId, Pageable pageable); @Santoshb
  • 您使用的是哪个版本的 Spring Data Elasticsearch?
  • 最新的一个:org.springframework.bootspring-boot-starter-data-elasticsearch
  • 你能更新你的 Pageable 类吗?

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


【解决方案1】:

你能试试这个查询吗

List<Comment> findByPostIdOrderByCreationDateAsc(String postId, Pageable pageable);

【讨论】:

  • 我试过了,我得到了同样的结果。我手动更改了 ID,删除了初始的“-”,现在一切正常。
  • 我需要为我的 Elasticsearch 模型找到一种方法来更改 @Id 的格式,例如,使用 UUID2,但我仍然没有找到任何东西
猜你喜欢
  • 2015-08-26
  • 2017-04-21
  • 2017-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多