如何在 Spring data cloud 数据存储中将引用标记为未索引

发布于 2025-01-10 08:59:12 字数 763 浏览 2 评论 0原文

我们有 @Unindexed 注释来将字段标记为未索引。但它不适用于引用类型字段。 来源:- https://cloud.spring.io /spring-cloud-static/Greenwich.RC1/multi/multi__spring_data_cloud_datastore.html

@Entity(name = "kind_one")
class Test {
   @Unindexed
   private String someFieldOne; //works - property is unindexed

   @Unindexed
   private List<TestTwo> someFieldTwo; //doesn't work - property is still indexed
}

@Entity(name = "kind_two") 
class TestTwo{
   @Unindexed 
   private String someFieldThree;
}

Test 对象存储在数据存储中时,“someFieldOne”被标记为未索引,但“someFieldTwo”被标记为已索引。

任何线索将不胜感激。

谢谢!

We have @Unindexed annotation to mark a field as unindexed. But it doesn't work with a reference type field.
Source:- https://cloud.spring.io/spring-cloud-static/Greenwich.RC1/multi/multi__spring_data_cloud_datastore.html

@Entity(name = "kind_one")
class Test {
   @Unindexed
   private String someFieldOne; //works - property is unindexed

   @Unindexed
   private List<TestTwo> someFieldTwo; //doesn't work - property is still indexed
}

@Entity(name = "kind_two") 
class TestTwo{
   @Unindexed 
   private String someFieldThree;
}

When storing the Test object in datastore, "someFieldOne" is marked as unindexed, but "someFieldTwo" is marked as indexed.

Any lead will be appreciated.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

面如桃花 2025-01-17 08:59:12

对于列表,不得将整个列表排除在索引之外,而是必须将其值单独排除在索引之外,如注释 此处。否则会抛出异常。

我相信这就是为什么 someFieldTwo 在您的情况下被索引的原因,因为它是一个列表,除非它应该根据注释抛出异常。

因此,我建议您按照此示例 而不是用 @unindexed 注释整个列表。

For Lists the entire list must not be excluded from being indexed instead its values must be individually excluded from being indexed as mentioned in the comments here. Otherwise it will throw an exception.

I believe this is the reason why someFieldTwo is getting indexed in your case as it is a List barring the fact that it should throw an exception as per the comment.

So I would suggest you exclude the list elements individually as mentioned in this example instead of annotating the whole list with @unindexed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文