最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

使用 Java 客戶端通過 HTTPS 連接到 Easysearch

2023-11-26 21:28 作者:INFINI-Labs  | 我要投稿


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

這一里程碑式的更新為開發(fā)人員帶來了前所未有的便利性,使得與 Easysearch 集群的交互變得更加簡潔和直觀。通過 Easysearch-client,開發(fā)者可以直接使用 Java 方法和數(shù)據(jù)結(jié)構(gòu)來進行交互,而不再需要依賴于傳統(tǒng)的 HTTP 方法和 JSON。
這一變化大大簡化了操作流程,使得數(shù)據(jù)管理和索引更加高效。Java 客戶端的功能范圍包括處理數(shù)據(jù)操作,管理集群,包括查看和維護集群的健康狀態(tài),并對 Security 模塊全面兼容。它提供了一系列 API,用于管理角色、用戶、權(quán)限、角色映射和賬戶。
這意味著安全性和訪問控制現(xiàn)在可以更加細(xì)粒度地管理,確保了數(shù)據(jù)的安全性和合規(guī)性。

在這篇博客中,你將學(xué)習(xí)如何配置 Easysearch-client 客戶端以通過 HTTPS 連接到 Easysearch。為了演示目的,我將首先設(shè)置一個帶有 SSL 證書的 Easysearch 服務(wù)器。如果你已經(jīng)有一個在運行,你可以跳過這一步。
接下來,我將引導(dǎo)你完成在 Java 應(yīng)用程序中配置和使用 Java 客戶端的步驟。

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

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

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í)行后會自動輸出隨機生成的 admin 用戶密碼。

啟動 Easysearch

bin/easysearch

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

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/ 上獲得。將其作為依賴項添加到你的 Java 應(yīng)用程序中。
對于 Gradle 構(gòu)建系統(tǒng),在項目的 build.gradle 文件中包含以下依賴項:

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),在項目的 pom.xml 文件中包含以下依賴項:

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

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

使用 Java keytool 創(chuàng)建一個自定義信任庫并導(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 通信時使用的信任庫:

?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 編碼文件的形式可用時:

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 客戶端還具備強大的權(quán)限控制管理 API,具體請參考我們的官網(wǎng)文檔:https://www.infinilabs.com/docs/latest/easysearch/references/client/security/

關(guān)于 Easysearch

about easysearch
about easysearch

INFINI Easysearch 是一個分布式的近實時搜索與分析引擎,核心引擎基于開源的 Apache Lucene。Easysearch 的目標(biāo)是提供一個輕量級的 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的評論 (共 條)

分享到微博請遵守國家法律
揭东县| 临夏县| 浮山县| 图们市| 彭阳县| 荔波县| 巴塘县| 天柱县| 潜山县| 农安县| 东山县| 银川市| 辽宁省| 尉氏县| 惠水县| 璧山县| 清原| 泰兴市| 株洲县| 腾冲县| 定南县| 吉安县| 台东市| 临夏市| 大竹县| 莎车县| 高平市| 通榆县| 鄄城县| 哈巴河县| 上林县| 潞西市| 明光市| 伊通| 新巴尔虎右旗| 德庆县| 高阳县| 随州市| 米泉市| 布尔津县| 松桃|