最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java客戶端通過HTTPS連接到Easysearch實(shí)現(xiàn)過程

 更新時(shí)間:2023年11月27日 11:41:05   作者:極限實(shí)驗(yàn)室  
這篇文章主要為大家介紹了Java客戶端通過HTTPS連接到Easysearch實(shí)現(xiàn)過程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

Easysearch 簡介

Easysearch 一直致力于提高易用性,這也是我們的核心宗旨,然而之前一直沒有官方的 Java 客戶端,也對用戶使用造成了一些困擾,現(xiàn)在,我們正式發(fā)布了第一個(gè) Java 客戶端 Easysearch-client:1.0.1。

這一里程碑式的更新為開發(fā)人員帶來了前所未有的便利性,使得與 Easysearch 集群的交互變得更加簡潔和直觀。通過 Easysearch-client,開發(fā)者可以直接使用 Java 方法和數(shù)據(jù)結(jié)構(gòu)來進(jìn)行交互,而不再需要依賴于傳統(tǒng)的 HTTP 方法和 JSON。

這一變化大大簡化了操作流程,使得數(shù)據(jù)管理和索引更加高效。Java 客戶端的功能范圍包括處理數(shù)據(jù)操作,管理集群,包括查看和維護(hù)集群的健康狀態(tài),并對 Security 模塊全面兼容。它提供了一系列 API,用于管理角色、用戶、權(quán)限、角色映射和賬戶。

這意味著安全性和訪問控制現(xiàn)在可以更加細(xì)粒度地管理,確保了數(shù)據(jù)的安全性和合規(guī)性。

在這篇博客中,你將學(xué)習(xí)如何配置 Easysearch-client 客戶端以通過 HTTPS 連接到 Easysearch。為了演示目的,我將首先設(shè)置一個(gè)帶有 SSL 證書的 Easysearch 服務(wù)器。如果你已經(jīng)有一個(gè)在運(yùn)行,你可以跳過這一步。

接下來,我將引導(dǎo)你完成在 Java 應(yīng)用程序中配置和使用 Java 客戶端的步驟。

設(shè)置 Easysearch 服務(wù)器

首先從極限科技官網(wǎng)下載最新的 Mac 版本。我使用的是 1.6.1 版本,這是我寫這篇文章時(shí)的最新版本。

wget https://dl-global.infinilabs.com/easysearch/stable/easysearch-1.6.1-214-mac-amd64.zip

確保您的系統(tǒng)已經(jīng)安裝并設(shè)置了 java 環(huán)境變量,版本在 11 以上。

解壓下載文件。

unzip easysearch-1.6.1-214-mac-amd64.zip -d easysearch-1.6.1

cd 到 easysearch-1.6.1 執(zhí)行初始化腳本來生成證書并自動下載插件。

bin/initialize.sh

腳本執(zhí)行后會自動輸出隨機(jī)生成的 admin 用戶密碼。

啟動 Easysearch

bin/easysearch

此時(shí),您的服務(wù)器已經(jīng)準(zhǔn)備就緒。您可以查看 logs/initialize.log 里顯示的 curl 命令來進(jìn)行驗(yàn)證。

curl -ku admin:xxxxxxxxx https://localhost:9200

顯示類似的輸出響應(yīng)

{
  "name" : "MacBook-Pro.local",
  "cluster_name" : "easysearch",
  "cluster_uuid" : "1gRYQ6ssTiKGqcyuEN0Dbg",
  "version" : {
    "distribution" : "easysearch",
    "number" : "1.6.1",
    "distributor" : "INFINI Labs",
    "build_hash" : "14846e460e9976ba6d68c80bb9eca52af1179dcf",
    "build_date" : "2023-10-19T14:43:02.636639Z",
    "build_snapshot" : false,
    "lucene_version" : "8.11.2",
    "minimum_wire_lucene_version" : "7.7.0",
    "minimum_lucene_index_compatibility_version" : "7.7.0"
  },
  "tagline" : "You Know, For Easy Search!"
}

下面我們來看如何設(shè)置和使用客戶端。

設(shè)置 Java 客戶端

Easysearch 的 Java 客戶端可在 中央倉庫:https://repo1.maven.org/maven2/ 上獲得。將其作為依賴項(xiàng)添加到你的 Java 應(yīng)用程序中。
對于 Gradle 構(gòu)建系統(tǒng),在項(xiàng)目的 build.gradle 文件中包含以下依賴項(xiàng):

dependencies {
    implementation 'com.infinilabs:easysearch-client:1.0.1'
    implementation "org.apache.logging.log4j:log4j-api:2.19.0"
    implementation "org.apache.logging.log4j:log4j-core:2.19.0"
    implementation 'org.apache.httpcomponents:httpclient:4.5.10'
    implementation 'org.apache.httpcomponents:httpcore-nio:4.4.12'
    implementation 'org.apache.httpcomponents:httpasyncclient:4.1.4'
    implementation 'joda-time:joda-time:2.10.4'
    implementation ('org.apache.lucene:lucene-core:8.11.2') {
        exclude group: '*', module: '*'
    }
    implementation ('org.apache.lucene:lucene-analyzers-common:8.11.2') {
        exclude group: '*', module: '*'
    }
    implementation ('org.apache.lucene:lucene-backward-codecs:8.11.2') {
        exclude group: '*', module: '*'
    }
    implementation ('org.apache.lucene:lucene-grouping:8.11.2') {
        exclude group: '*', module: '*'
    }
    implementation ('org.apache.lucene:lucene-highlighter:8.11.2') {
        exclude group: '*', module: '*'
    }
    implementation ('org.apache.lucene:lucene-join:8.11.2') {
        exclude group: '*', module: '*'
    }
    implementation ('org.apache.lucene:lucene-memory:8.11.2') {
        exclude group: '*', module: '*'
    }
    implementation ('org.apache.lucene:lucene-misc:8.11.2') {
        exclude group: '*', module: '*'
    }
    implementation ('org.apache.lucene:lucene-queries:8.11.2') {
        exclude group: '*', module: '*'
    }
    implementation ('org.apache.lucene:lucene-queryparser:8.11.2') {
        exclude group: '*', module: '*'
    }
    implementation ('org.apache.lucene:lucene-sandbox:8.11.2') {
        exclude group: '*', module: '*'
    }
    implementation ('org.apache.lucene:lucene-spatial3d:8.11.2') {
        exclude group: '*', module: '*'
    }
    implementation ('org.apache.lucene:lucene-suggest:8.11.2') {
        exclude group: '*', module: '*'
    }

  ......
}

對于 Maven 構(gòu)建系統(tǒng),在項(xiàng)目的 pom.xml 文件中包含以下依賴項(xiàng):

<dependencies>
    <dependency>
        <groupId>com.infinilabs</groupId>
        <artifactId>easysearch-client</artifactId>
        <version>1.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.10</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore-nio</artifactId>
        <version>4.4.12</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpasyncclient</artifactId>
        <version>4.1.4</version>
    </dependency>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.10.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-core</artifactId>
        <version>8.11.2</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>*</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-analyzers-common</artifactId>
        <version>8.11.2</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>*</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-backward-codecs</artifactId>
        <version>8.11.2</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>*</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-grouping</artifactId>
        <version>8.11.2</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>*</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-highlighter</artifactId>
        <version>8.11.2</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>*</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-join</artifactId>
        <version>8.11.2</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>*</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-memory</artifactId>
        <version>8.11.2</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>*</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-misc</artifactId>
        <version>8.11.2</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>*</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-queries</artifactId>
        <version>8.11.2</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>*</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-queryparser</artifactId>
        <version>8.11.2</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>*</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-sandbox</artifactId>
        <version>8.11.2</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>*</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-spatial3d</artifactId>
        <version>8.11.2</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>*</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-suggest</artifactId>
        <version>8.11.2</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>*</groupId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

接下來,在你的 Java 應(yīng)用程序中創(chuàng)建一個(gè) client 實(shí)例,并使用它在 Easysearch 中創(chuàng)建索引并插入一些數(shù)據(jù)。但在此之前,為了使其工作,你需要將簽署服務(wù)器證書的根機(jī)構(gòu)證書添加到你的應(yīng)用程序信任庫中。讓我們看看如何配置 Java 應(yīng)用程序的信任庫。

為了使用 java client,你需要將根 CA 證書 ca.crt 添加到應(yīng)用程序信任庫中。這告訴你的 Java 應(yīng)用程序信任由此根機(jī)構(gòu)簽署的任何證書。easysearch-1.6.1/config/ 目錄下已經(jīng)生成了 ca.crt 文件。你可以將其添加到自定義信任庫中,并在 Java 應(yīng)用程序中使用該自定義信任庫。

使用 Java keytool 創(chuàng)建一個(gè)自定義信任庫并導(dǎo)入證書。keytool 不理解 .pem 格式,所以你需要首先使用 openssl 加密庫將證書轉(zhuǎn)換為 .der 格式,然后使用 Java keytool 將其添加到自定義信任庫中。假設(shè)您的操作系統(tǒng)已經(jīng)預(yù)裝了 openssl。

第 1 步:將 CA 證書從 .pem 格式轉(zhuǎn)換為 .der 格式。

openssl x509 -in easysearch-1.6.1/config/ca.crt -inform pem -out ca.der --outform der

第 2 步:創(chuàng)建自定義信任庫并添加 ca.der 證書。將 ca 證書添加到應(yīng)用程序信任庫中,表示應(yīng)用程序信任由此 CA 簽署的任何證書。

keytool -import -file ca.der -alias easysearch -keystore myTrustStore

過程中會提示您輸入密鑰庫口令: 我為了測試用輸入的 123456。

通過列出信任庫中的證書來確認(rèn)操作成功,這里的 123456 是我上面設(shè)置的密碼,會顯示出 easysearch 證書。

keytool -keystore myTrustStore -storepass 123456 -list

第 3 步:在 Java 應(yīng)用程序代碼中設(shè)置指向自定義信任庫的系統(tǒng)屬性,并連接集群,創(chuàng)建索引,插入數(shù)據(jù)。可以通過設(shè)置系統(tǒng)屬性,以指定 SSL/TLS 通信時(shí)使用的信任庫:

System.setProperty("javax.net.ssl.trustStore", "/full/path/to/myTrustStore");
System.setProperty("javax.net.ssl.trustStorePassword", "123456");
HttpHost[] httpHostArray = new HttpHost[1];
// infini.cloud 和 CN=infini.cloud 保持一致
httpHostArray[0] = new HttpHost("infini.cloud", 9200, "https");
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "1933791fb2b9f6c6146d"));
RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(httpHostArray)
    .setHttpClientConfigCallback((HttpAsyncClientBuilder httpAsyncClientBuilder) -> {
      httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
      return httpAsyncClientBuilder;
    }));
CreateIndexRequest createIndexRequest = new CreateIndexRequest("test-index");
createIndexRequest.settings(Settings.builder()
    .put("index.number_of_shards", 1)
    .put("index.number_of_replicas", 1)
);
//Create index
client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
// Bulk
BulkRequest bulkRequest = new BulkRequest();
for (int i = 0; i < 10; i++) {
  IndexRequest indexRequest = new IndexRequest("test-index")
      .id(Integer.toString(i))
      .source("{\"field1\":\"value" + i + "\"}", XContentType.JSON);
  bulkRequest.add(indexRequest);
}
BulkResponse bulkResponse = client.bulk(bulkRequest, RequestOptions.DEFAULT);
System.out.println(Strings.toString(bulkResponse));

信任已簽署 Easysearch 正在使用的證書的 CA 的示例,當(dāng) CA 證書以 PEM 編碼文件的形式可用時(shí):

Path caCertificatePath = Paths.get("/easysearch-test/easysearch-1.6.1/config/ca.crt");
CertificateFactory factory = CertificateFactory.getInstance("X.509");
Certificate trustedCa;
try (InputStream is = Files.newInputStream(caCertificatePath)) {
  trustedCa = factory.generateCertificate(is);
}
KeyStore trustStore = KeyStore.getInstance("pkcs12");
trustStore.load(null, null);
trustStore.setCertificateEntry("ca", trustedCa);
SSLContextBuilder sslContextBuilder = SSLContexts.custom()
    .loadTrustMaterial(trustStore, null);
final SSLContext sslContext = sslContextBuilder.build();


HttpHost[] httpHostArray = new HttpHost[1];
httpHostArray[0] = new HttpHost("infini.cloud", 9200, "https");
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "1933791fb2b9f6c6146d"));

RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(httpHostArray)
    .setHttpClientConfigCallback((HttpAsyncClientBuilder httpAsyncClientBuilder) -> {
      httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
      httpAsyncClientBuilder.setSSLContext(sslContext);
      return httpAsyncClientBuilder;
    }));

現(xiàn)在,您已經(jīng)成功設(shè)置了 Java 客戶端,并以安全的 HTTPS 通道連接到了 Easysearch 集群。除此之外,Java 客戶端還具備強(qiáng)大的權(quán)限控制管理 API,具體請參考我們的官網(wǎng)文檔:https://www.infinilabs.com/docs/latest/easysearch/references/client/security/

關(guān)于 Easysearch

INFINI Easysearch 是一個(gè)分布式的近實(shí)時(shí)搜索與分析引擎,核心引擎基于開源的 Apache Lucene。Easysearch 的目標(biāo)是提供一個(gè)輕量級的 Elasticsearch 可替代版本,并繼續(xù)完善和支持更多的企業(yè)級功能。 與 Elasticsearch 相比,Easysearch 更關(guān)注在搜索業(yè)務(wù)場景的優(yōu)化和繼續(xù)保持其產(chǎn)品的簡潔與易用性。

官網(wǎng)文檔:https://www.infinilabs.com/docs/latest/easysearch

下載地址:https://www.infinilabs.com/download

以上就是Java客戶端通過HTTPS連接到Easysearch實(shí)現(xiàn)過程的詳細(xì)內(nèi)容,更多關(guān)于Java HTTPS連接Easysearch的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • maven的安裝配置使用詳解

    maven的安裝配置使用詳解

    這篇文章主要介紹了maven的安裝配置使用詳解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-01-01
  • 基于FeignClient調(diào)用超時(shí)的處理方案

    基于FeignClient調(diào)用超時(shí)的處理方案

    這篇文章主要介紹了基于FeignClient調(diào)用超時(shí)的處理方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • Java List簡介_動力節(jié)點(diǎn)Java學(xué)院整理

    Java List簡介_動力節(jié)點(diǎn)Java學(xué)院整理

    Java中可變數(shù)組的原理就是不斷的創(chuàng)建新的數(shù)組,將原數(shù)組加到新的數(shù)組中,下文對Java List用法做了詳解。需要的朋友參考下吧
    2017-05-05
  • Spring中IOC和AOP的核心組成架構(gòu)詳解

    Spring中IOC和AOP的核心組成架構(gòu)詳解

    這篇文章主要介紹了Spring中IOC和AOP的核心組成架構(gòu)詳解,本文是對Spring的2大核心功能——IoC和AOP 的總結(jié)提煉,并增加了環(huán)境profile和條件化bean的內(nèi)容,篇幅較短,更像是一個(gè)大綱,或者思維導(dǎo)圖,需要的朋友可以參考下
    2023-08-08
  • Java中斷言(assert)的使用場景與注意事項(xiàng)

    Java中斷言(assert)的使用場景與注意事項(xiàng)

    文章詳細(xì)介紹了Java斷言(assert)的使用方法、適用場景及注意事項(xiàng),斷言是一種調(diào)試工具,用于開發(fā)和測試階段快速定位代碼邏輯錯誤,但非業(yè)務(wù)級校驗(yàn),不應(yīng)用于對外接口、業(yè)務(wù)容錯等場景,應(yīng)嚴(yán)格區(qū)分?jǐn)嘌耘c常規(guī)異常,避免濫用,確保代碼質(zhì)量和生產(chǎn)環(huán)境穩(wěn)定性
    2026-05-05
  • 使用spring stream發(fā)送消息代碼實(shí)例

    使用spring stream發(fā)送消息代碼實(shí)例

    這篇文章主要介紹了使用spring stream發(fā)送消息代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-05-05
  • 深入理解Java中觀察者模式與委托的對比

    深入理解Java中觀察者模式與委托的對比

    這篇文章主要介紹了Java中觀察者模式與委托的對比,觀察者模式:定義了一種一對多的依賴關(guān)系,讓多個(gè)觀察者對象同時(shí)監(jiān)聽某一個(gè)主題對象,委托的實(shí)現(xiàn)簡單來講就是用反射來實(shí)現(xiàn)的,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-05-05
  • Java基于外觀模式實(shí)現(xiàn)美食天下食譜功能實(shí)例詳解

    Java基于外觀模式實(shí)現(xiàn)美食天下食譜功能實(shí)例詳解

    這篇文章主要介紹了Java基于外觀模式實(shí)現(xiàn)美食天下食譜功能,較為詳細(xì)的講述了外觀模式的概念、原理并結(jié)合實(shí)例形似詳細(xì)分析了Java基于外觀模式實(shí)現(xiàn)美食天下食譜功能的具體操作步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2018-05-05
  • java實(shí)現(xiàn)水仙花數(shù)的計(jì)算

    java實(shí)現(xiàn)水仙花數(shù)的計(jì)算

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)水仙花數(shù)的計(jì)算,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • Spring?Cloud?Ribbon?負(fù)載均衡使用策略示例詳解

    Spring?Cloud?Ribbon?負(fù)載均衡使用策略示例詳解

    Spring?Cloud?Ribbon?是基于Netflix?Ribbon?實(shí)現(xiàn)的一套客戶端負(fù)載均衡工具,Ribbon客戶端組件提供了一系列的完善的配置,如超時(shí),重試等,這篇文章主要介紹了Spring?Cloud?Ribbon?負(fù)載均衡使用策略示例詳解,需要的朋友可以參考下
    2023-03-03

最新評論

苗栗县| 库尔勒市| 康保县| 西宁市| 太原市| 深州市| 三亚市| 望奎县| 赤壁市| 大名县| 南安市| 盐亭县| 秦皇岛市| 永新县| 广元市| 卢龙县| 绍兴县| 朔州市| 温州市| 乌拉特后旗| 盖州市| 东乌珠穆沁旗| 平武县| 甘孜县| 浏阳市| 武陟县| 桦南县| 通化市| 克拉玛依市| 永嘉县| 图木舒克市| 都安| 芮城县| 宽城| 湄潭县| 防城港市| 峡江县| 阳原县| 衡山县| 和顺县| 永州市|