# 本地連接 Elasticsearch docker 透過 Spring 實做本地連接功能 --- ## 一、依賴項 ```xml= <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-client</artifactId> <version>7.12.0</version> </dependency> ``` ## 二、寫入資料 ```java= // 建立連線端 RestClient restClient = RestClient.builder( new HttpHost("localhost", 9200, "http")).build(); // 設定路徑 Request request = new Request( "post", "/hktv/product"); // 組資料 request.setJsonEntity("{\"invisible\":true}"); // 送出 Response response = restClient.performRequest(request); ``` :::info [參考資料](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.12/index.html) :::
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up