Migrating from the Java High Level REST Client

Preface

Deprecated in 7.0.0.

The TransportClient is deprecated in favour of the Java High Level REST Client and will be removed in Elasticsearch 8.0. The migration guide describes all the steps needed to migrate.

This section describes the Java Transport Client 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).

Migrating from the High Level Rest Client

The Elasticsearch Java API Client is an entirely new client library that has no relation to the older High Level Rest Client (HLRC). This was a deliberate choice to provide a library that is independent from the Elasticsearch server code and that provides a very consistent and easier to use API for all Elasticsearch features.

Migrating from the HLRC therefore requires some code rewrite in your application. This transition can however happen progressively as the two client libraries can coexist in a single application with no operational overhead.

Transition strategies

There are different ways you can start transitioning away from the HLRC in your application code.

For example:

  • keep the existing code as-is and use the new Java API Client for new features in your application, then later migrate the existing code,
  • rewrite the parts of your application where the new Java API Client is much easier to use than that of the HLRC, like everything related to search,
  • rewrite those parts where you need to map application objects to/from JSON, by leveraging the tight integration of the new Java API Client with JSON object mappers.

Using the same transport with the HLRC and the Java API Client

To avoid any operational overhead during the transition phase where an application would use both the HLRC and the new Java API Client, both clients can share the same Low Level Rest Client, which is the network layer that manages all connections, round-robin strategies, node sniffing, and so on.

The code below shows how to initialize both clients with the same HTTP client:

// Create the low-level client
RestClientBuilder httpClientBuilder = RestClient.builder(
   new HttpHost("localhost", 9200)
);

// Create the HLRC
RestHighLevelClient hlrc = new RestHighLevelClient(httpClientBuilder);

// Create the new Java Client with the same low level client
Transport transport = new RestClientTransport(
   hlrc.getLowLevelClient(),
   new JacksonJsonpMapper()
);

ElasticsearchClient esClient = new ElasticsearchClient(transport);

// hlrc and esClient share the same httpClient

Javadoc

The javadoc for the transport client can be found at https://artifacts.elastic.co/javadoc/org/elasticsearch/client/transport/7.15.2/index.html.

Maven Repository

Elasticsearch is hosted on Maven Central.

For example, you can define the latest version in your pom.xml file:

<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
    <version>7.15.2</version>
</dependency>

Jave Api Detail Can Refer : Java-Api

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末获询,一起剝皮案震驚了整個(gè)濱河市硬鞍,隨后出現(xiàn)的幾起案子痪宰,更是在濱河造成了極大的恐慌侧巨,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,372評(píng)論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件门烂,死亡現(xiàn)場(chǎng)離奇詭異聪建,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)蕴忆,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)悲幅,“玉大人套鹅,你說(shuō)我怎么就攤上這事√撸” “怎么了卓鹿?”我有些...
    開(kāi)封第一講書(shū)人閱讀 162,415評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)留荔。 經(jīng)常有香客問(wèn)我减牺,道長(zhǎng),這世上最難降的妖魔是什么存谎? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,157評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮肥隆,結(jié)果婚禮上既荚,老公的妹妹穿的比我還像新娘。我一直安慰自己栋艳,他們只是感情好恰聘,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,171評(píng)論 6 388
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著吸占,像睡著了一般晴叨。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上矾屯,一...
    開(kāi)封第一講書(shū)人閱讀 51,125評(píng)論 1 297
  • 那天兼蕊,我揣著相機(jī)與錄音,去河邊找鬼件蚕。 笑死孙技,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的排作。 我是一名探鬼主播牵啦,決...
    沈念sama閱讀 40,028評(píng)論 3 417
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼妄痪!你這毒婦竟也來(lái)了哈雏?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 38,887評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎裳瘪,沒(méi)想到半個(gè)月后土浸,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,310評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡盹愚,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,533評(píng)論 2 332
  • 正文 我和宋清朗相戀三年栅迄,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片皆怕。...
    茶點(diǎn)故事閱讀 39,690評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡毅舆,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出愈腾,到底是詐尸還是另有隱情憋活,我是刑警寧澤,帶...
    沈念sama閱讀 35,411評(píng)論 5 343
  • 正文 年R本政府宣布虱黄,位于F島的核電站悦即,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏橱乱。R本人自食惡果不足惜辜梳,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,004評(píng)論 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望泳叠。 院中可真熱鬧作瞄,春花似錦、人聲如沸危纫。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,659評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)种蝶。三九已至契耿,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間螃征,已是汗流浹背搪桂。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,812評(píng)論 1 268
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留会傲,地道東北人锅棕。 一個(gè)月前我還...
    沈念sama閱讀 47,693評(píng)論 2 368
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像淌山,于是被迫代替她去往敵國(guó)和親裸燎。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,577評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容