具有当前Elasticsearch版本的Spring Boot应用程序

具有当前Elasticsearch版本的Spring Boot应用程序

问题描述:

我最近尝试将Elasticsearch纳入我的一个项目。因此,我寻找了这样做的不同可能性。使用a)传输客户端(内部协议群集节点也用于通信=我的理解)或b)将其全部实现为我自己的REST HTTP调用,基本上可以归结为。

I've recently tried to include elasticsearch into one of my projects. Therefore I looked up the different possibilities to do so. It basically came down to use either a) the transport client (internal protocol cluster nodes too use to communicate = my understanding) or b) implement it all as REST HTTP calls on my own.

因为b)看起来不是一个不错的选择,而且我还是习惯于使用spring-data-elasticsearch来弹簧化数据,该弹簧最近已更新至3.0.0版本以支持es 5.5.0。

As b) doesn't look like a good option, and I'm used to spring data anyways I tried using spring-data-elasticsearch which was updated recently to version 3.0.0 to support es 5.5.0 which is great as the last version was very old.

好吧,我尝试了所有操作,但没有设法使其与我的项目一起使用,因为这似乎确实有些您会遇到某种依赖。我的项目太大,我无法将其升级到Spring Boot 2.0.0M4,我认为它需要支持新的spring-data-elasticsearch版本-是吗?

Well, I tried everything but didn't manage to get it to work with my project, as this really seems to be some kind of dependency hell you get into. My project is too big, I just can't upgrade it to spring boot 2.0.0M4 which I believe would be required to support the new spring-data-elasticsearch version - right?

那么,有人可以就当前和未来的最佳方式提出建议吗,那就是如何处理spring项目中的elasticsearch?我们真的必须自己实现整个REST API吗?我想念什么吗?

So, could somebody please advice on the current and preferred way for now and the future is on how to deal with elasticsearch in spring projects? Do we really have to implement the whole REST API ourselves? Am I missing something?

这里是应该使用的REST客户端,如果使用过的话,对吗?

Here is the REST client which should be used, if there is one used, right?

是兼容性图表,我知道哪个较旧。

This is the compatibility chart I know which is old.

谢谢!

不幸的是,那里有很多选择:

Unfortunately there are quite a few options out there:


  • 您提到的有运输客户。尽管还没有被弃用,但这不是前进的路,我也不会用它开始新项目(如果可能的话)。

  • 有一个低级别的REST客户端(博客中提到了)您已链接的帖子),该功能已在5.0中添加,但也与旧版本兼容。虽然它有效,但是您真的不想使用它,因为它的级别很低(顾名思义)。

  • 高级REST客户端具有刚刚与5.6一起发布这是继续使用(它将使您与特定的Spring Boot / Data版本脱钩)。目前,它仅支持索引,删除,聚合,搜索和批量API,但是对于常规操作而言,这已经足够了。将来会添加更多的API,如果您需要执行其他任务(例如为集成测试设置特定的映射),则始终可以使用低级客户端。

  • 随着Spring Data Kay的发布,它还支持Elasticsearch5.x。如果您需要使用Spring Data,这就是您要使用的东西,但是请记住,这是一个社区项目,开发速度可能比每个人都要慢(尽管他们确实接受拉取请求;-))。正如您所发现的,您将需要使用Spring Boot 2来内置Spring Data Kay。这可能是升级的好理由,或者可能对您来说是一个障碍。

  • There's the transport client you have mentioned. While not (yet) deprecated, it's not the way forward and I would not start a new project with it (if possible).
  • There is the low level REST client (mentioned in the blog post you've linked), which was added in 5.0, but is compatible with older versions as well. While it works, you don't really want to use it, since it's pretty low level (as the name suggests).
  • The high level REST client has just been released with 5.6 — this is what you want to use going forward (and it will decouple you from a specific Spring Boot / Data version). Right now it only supports the index, delete, aggregate, search, and bulk APIs, but for regular operations this should be enough. More APIs will be added in the future and you can always fall back to the low level client if you need to do other tasks (like setting up a specific mapping for an integration test).
  • With the release of Spring Data Kay, it also supports Elasticsearch 5.x. If you need to use Spring Data, this is what you'll want to use, but keep in mind that it's a community project and development can be slower than everybody wants (though they do accept pull requests ;-) ). As you've discovered, you'll need to use Spring Boot 2 to have Spring Data Kay built in. This might be a good reason to upgrade or it might be a blocker for you.