java 操作 ES 的方式 整理总结
一、操作ES 的方式大題有這么三種
1. TransportClinet客戶端 2. REST Client 3. SpringDateES二、第一種 TransportClinet客戶端
首先要講一下,如果是新打的ES 集群的話,ES版本在7.0以上,或者以后有可能升級版本的話,這個方式已經不被推薦了。這個是官方文檔上顯示的。并且到ES8的版本,直接廢除。
來看下原文: 原文鏈接 https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-api.html#java-api
Deprecated in 7.0.0.
The TransportClient is deprecated in favour of the Java High Level REST Clientand will be removed in Elasticsearch 8.0. The migration guide describes all the steps needed to migrate.
This section describes the Java API that Elasticsearch provides. All Elasticsearch operations are executed using a Client object. All operations are completely asynchronous in nature (either accepts a listener, or returns a future).
Additionally, operations on a client may be accumulated and executed in Bulk.
Note, all the APIs are exposed through the Java API (actually, the Java API is used internally to execute them).
如果ES 使用的7.0之前的版本的話,并且不會輕易升ES版本,那么就可以使用。
這里我貼一個案例(不自己手敲了,直接鏈接別人的案例):案例
三、REST Client
這個是ES 官方推薦的一種方式。下邊是官方文檔、
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.6/java-rest-high.html
REST Client 有一個高版本,和一個低版本。主要是用來適應不同的 ES版本的。
- Java Low Level REST Client - Java High Level REST Client這里主要介紹高版本的客戶端,看官方文檔的介紹:https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.6/java-rest-high-compatibility.html
Java高級REST客戶端需要Java 1.8,并依賴于Elasticsearch核心項目。客戶端版本與為其開發客戶端的Elasticsearch版本相同。它接受與相同的請求參數,TransportClient 并返回相同的響應對象。 如果需要將應用程序從其遷移到新的REST客戶端,請參閱《遷移指南》TransportClient。確保高級客戶端能夠與在相同主要版本和較大或相等的次要版本上運行的任何Elasticsearch節點進行通信。它不需要與與其通信的Elasticsearch節點處于相同的次要版本,因為它是前向兼容的,這意味著它支持與比其開發的版本更高的Elasticsearch通信。6.0客戶端可以與任何6.x Elasticsearch節點進行通信,而6.1客戶端可以與6.1、6.2和任何更高版本的6.x版本進行通信,但是與先前的Elasticsearch節點進行通信時可能會出現不兼容問題如果6.1客戶端支持6.0節點不知道的某些API的新請求正文字段,則版本介于6.1和6.0之間。 對這個感興趣的,就看官方文檔吧,我上邊已經都貼出來了。我最最推薦的還是下邊的方式。
四、SpringDateES
這種方式,是我認為最簡單方便操作的方式。可能有我個人的情感在里邊,我之前持久層經常使用SpringDateJPA,在我看到SpringDateEs 的時候,一下子就被深深的吸引了。從入門的案例來講,相比較其它的方式,這個非常簡單,從入門案例就可以看出來。
下邊我貼一個我找到的最好的案例:https://www.cnblogs.com/sxdcgaq8080/p/10411423.html
另外,對SpringDateES 做入門的學習,我推薦這篇文章:https://www.jianshu.com/p/930c803a4ebd
最后,對SpringDateES 做全面的學習,請看官方文檔:官方文檔
五、這里在提一下 使用 ES 的一些坑
https://www.cnblogs.com/guozp/p/8686904.html
文章轉自
總結
以上是生活随笔為你收集整理的java 操作 ES 的方式 整理总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2020年抖音创作者生态报告
- 下一篇: 互联网早报 | 10月3日 星期六 |