如何冲洗数据到弹簧数据弹性搜索

发布于 2025-01-31 07:25:43 字数 622 浏览 3 评论 0原文

我运行此测试箱

Envelope envelope = new Envelope();
envelope.setId("1");
Envelope saved = envelopeRepository.save(envelope);
assertThat(saved.getId()).isEqualTo("1");

保存,并且信封是同一对象/参考!因此,即使索引不正确,测试仍然通过!如何解决此问题?

org.elasticsearch.client.RestClient - request [HEAD http://localhost:9200/null?ignore_throttled=false&ignore_unavailable=false&expand_wildcards=open%2Cclosed&allow_no_indices=false]

I run this testcase

Envelope envelope = new Envelope();
envelope.setId("1");
Envelope saved = envelopeRepository.save(envelope);
assertThat(saved.getId()).isEqualTo("1");

saved and envelope are the same object/reference! So even when the index is incorrect, the test still passes! How to fix this issue?

enter image description here

org.elasticsearch.client.RestClient - request [HEAD http://localhost:9200/null?ignore_throttled=false&ignore_unavailable=false&expand_wildcards=open%2Cclosed&allow_no_indices=false]

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

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

发布评论

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

评论(1

烟柳画桥 2025-02-07 07:25:43

为什么保存的实体应该是一个新对象?保存时,Elasticsearch不会返回文档,因此无需在此处创建一个新对象。

Spring Data Elasticsearch的操作是用索引操作返回的信息更新此对象:

  • id如果该对象尚未在对象上设置,但
  • 如果实体具有版本属性
  • <代码> seq_no 和primary_term如果实体具有此类属性,

如果索引失败,则会引发异常。

你是什​​么意思

索引不正确

head 请求对此有何处理?

Why should the saved entity be a new object? Elasticsearch does not return a document when saving, so there is no need to create a new object here.

What Spring Data Elasticsearch does is update this object with the information returned from the index operation:

  • the id if it was not already set on the object but was created by Elasticsearch
  • version if the entity has a version property
  • seq_no and primary_term if the entity has such a property

If the indexing fails, an exception is thrown.

What do you mean with

when the index is incorrect

And what has the HEAD request do do with this?

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