下面是一個示例的 Easy-ES 的 YAML 配置文件:
easy-es:
enable: true
address: 192.168.1.145:9200
username: your_username
password: your_password
connectionTimeout: 5000
socketTimeout: 60000
maxRetryTimeout: 30000
maxConnTotal: 30
maxConnPerRoute: 10
requestConfig:
connectTimeout: 5000
socketTimeout: 60000
connectionRequestTimeout: 5000
解釋一下各個配置項的含義:
enable: 是否啟用 Easy-ES,設置為 true 表示啟用。
address: Elasticsearch 服務器的地址和端口。
username: Elasticsearch 服務器的用戶名(可選)。
password: Elasticsearch 服務器的密碼(可選)。
connectionTimeout: 連接 Elasticsearch 的超時時間,單位為毫秒。
socketTimeout: 與 Elasticsearch 進行通信的套接字的超時時間,單位為毫秒。
maxRetryTimeout: 最大的重試超時時間,即在重試期間最多等待的時間,單位為毫秒。
maxConnTotal: 允許的最大連接數(shù)。
maxConnPerRoute: 每個目標主機允許的最大連接數(shù)。
requestConfig: 請求配置相關的參數(shù)。
connectTimeout: 請求連接的超時時間,單位為毫秒。
socketTimeout: 等待響應的超時時間,單位為毫秒。
connectionRequestTimeout: 從連接管理器獲取連接的超時時間,單位為毫秒。
根據(jù)實際情況,你可以根據(jù)上述示例進行相應的配置,確保 Easy-ES 能夠正確連接到你的 Elasticsearch 服務器。
當 Easy-ES 配置完畢后,createIndex() 方法將會自動連接 Elasticsearch。
Easy-ES 通過在 Spring Boot 啟動類中自動配置 RestHighLevelClient 對象來連接 Elasticsearch。而在 RestHighLevelClient 對象的創(chuàng)建過程中,就已經(jīng)將 address 參數(shù)傳入其中,這樣就實現(xiàn)了自動連接 Elasticsearch 的功能。
至于 UmsSmsClientEsMapper 接口中的方法,它們操作的是 Elasticsearch 中的索引,與數(shù)據(jù)庫表無關。在 Easy-ES 中,我們可以通過繼承 BaseEsMapper 接口來實現(xiàn)對 Elasticsearch 索引的增刪改查操作,這些操作都是基于 Elasticsearch 的 API 實現(xiàn)的。
9200端口和5601端口區(qū)別:
http://192.168.1.145:9200/ 是Elasticsearch的API端點。Elasticsearch是一個分布式搜索和分析引擎,用于存儲和檢索大量數(shù)據(jù)。這個URL地址可以用于與Elasticsearch進行交互,執(zhí)行各種搜索、索引和管理操作。
http://192.168.1.145:5601/ 是Kibana的Web界面。Kibana是一個開源的數(shù)據(jù)可視化工具,用于在Elasticsearch上分析和可視化數(shù)據(jù)。通過這個URL地址,您可以訪問Kibana的儀表板、圖表和查詢工具,以便更好地理解和呈現(xiàn)存儲在Elasticsearch中的數(shù)據(jù)。
因此,兩個URL地址提供了不同的功能和用途,分別用于與Elasticsearch和Kibana進行交互。
<dependency>
<groupId>org.dromara.easy-es</groupId>
<artifactId>easy-es-boot-starter</artifactId>
<version>2.0.0-beta3</version>
</dependency>
org.dromara.easy-es:easy-es-boot-starter:2.0.0-beta3 是 Easy-ES 的 Spring Boot Starter 依賴,它是一個用于簡化 Elasticsearch 操作的框架。在這個依賴中,BaseEsMapper 是其中一個重要的類。
BaseEsMapper 是 Easy-ES 框架中的一個基礎接口,用于定義 Elasticsearch 操作的基本方法。它提供了一系列的增刪改查方法,用于操作 Elasticsearch 中的文檔。具體而言,BaseEsMapper 包含以下方法:
getEntityClass(): 返回當前泛型實體類的類型。
existsIndex(String indexName): 檢查給定名稱的索引是否存在。
getIndex(): 獲取默認索引的信息。
getIndex(String indexName): 獲取給定名稱的索引的信息。
createIndex(): 創(chuàng)建默認索引。
createIndex(String indexName): 創(chuàng)建給定名稱的索引。
createIndex(Wrapper<T> wrapper): 根據(jù)給定的索引配置信息創(chuàng)建索引。
updateIndex(Wrapper<T> wrapper): 更新指定索引的配置信息。
deleteIndex(String... indexNames): 刪除指定名稱的索引。
refresh(): 刷新所有索引。
refresh(String... indexNames): 刷新指定名稱的索引。
executeSQL(String sql): 執(zhí)行 SQL 語句。
executeDSL(String dsl): 執(zhí)行 DSL 語句。
executeDSL(String dsl, String indexName): 在指定索引上執(zhí)行 DSL 語句。
search(Wrapper<T> wrapper): 根據(jù)給定的查詢條件進行搜索。
getSearchSourceBuilder(Wrapper<T> wrapper): 獲取用于查詢的 SearchSourceBuilder 對象。
search(SearchRequest request, RequestOptions options) throws IOException: 根據(jù)給定的 SearchRequest 和 RequestOptions 進行搜索。
scroll(SearchScrollRequest request, RequestOptions options) throws IOException: 根據(jù)給定的 SearchScrollRequest 和 RequestOptions 進行滾動查詢。
getSource(Wrapper<T> wrapper): 獲取查詢條件對應的 JSON 字符串。
pageQuery(Wrapper<T> wrapper, Integer pageNum, Integer pageSize): 分頁查詢。
searchAfterPage(Wrapper<T> wrapper, List<Object> searchAfter, Integer pageSize): 使用 search_after 方式進行分頁查詢。
selectCount(Wrapper<T> wrapper): 統(tǒng)計符合條件的數(shù)據(jù)條數(shù)。
selectCount(Wrapper<T> wrapper, boolean useAggregation): 統(tǒng)計符合條件的數(shù)據(jù)條數(shù),可指定是否使用聚合查詢。
insert(T entity): 插入一條數(shù)據(jù)。
insert(T entity, String... indexNames): 在指定索引上插入一條數(shù)據(jù)。
insertBatch(Collection<T> entities): 批量插入數(shù)據(jù)。
insertBatch(Collection<T> entities, String... indexNames): 在指定索引上批量插入數(shù)據(jù)。
deleteById(Serializable id): 根據(jù) ID 刪除一條數(shù)據(jù)。
deleteById(Serializable id, String... indexNames): 在指定索引上根據(jù) ID 刪除一條數(shù)據(jù)。
deleteBatchIds(Collection<? extends Serializable> ids): 根據(jù) ID 批量刪除數(shù)據(jù)。
deleteBatchIds(Collection<? extends Serializable> ids, String... indexNames): 在指定索引上根據(jù) ID 批量刪除數(shù)據(jù)。
delete(Wrapper<T> wrapper): 根據(jù)條件刪除數(shù)據(jù)。
updateById(T entity): 根據(jù) ID 更新一條數(shù)據(jù)。
updateById(T entity, String... indexNames): 在指定索引上根據(jù) ID 更新一條數(shù)據(jù)。
updateBatchByIds(Collection<T> entities): 根據(jù) ID 批量更新數(shù)據(jù)。
updateBatchByIds(Collection<T> entities, String... indexNames): 在指定索引上根據(jù) ID 批量更新數(shù)據(jù)。
update(T entity, Wrapper<T> wrapper): 根據(jù)條件更新數(shù)據(jù)。
selectById(Serializable id): 根據(jù) ID 查詢一條數(shù)據(jù)。
selectById(Serializable id, String... indexNames): 在指定索引上根據(jù) ID 查詢一條數(shù)據(jù)。
selectBatchIds(Collection<? extends Serializable> ids): 根據(jù) ID 批量查詢數(shù)據(jù)。
selectBatchIds(Collection<? extends Serializable> ids, String... indexNames): 在指定索引上根據(jù) ID 批量查詢數(shù)據(jù)。
selectOne(Wrapper<T> wrapper): 根據(jù)條件查詢一條數(shù)據(jù)。
selectList(Wrapper<T> wrapper): 根據(jù)條件查詢數(shù)據(jù)列表。
setCurrentActiveIndex(String indexName): 設置當前活躍的索引名稱。
BaseEsMapper 還可以通過編寫自定義接口繼承它,實現(xiàn)更加靈活和具體的 Elasticsearch 操作。
通過使用 BaseEsMapper,你可以方便地進行 Elasticsearch 的增刪改查操作,并且 Easy-ES 還提供了更多的功能和擴展點,幫助你更好地處理 Elasticsearch 相關的業(yè)務需求。文章來源:http://www.zghlxwxcb.cn/news/detail-820555.html
使用代碼示例:文章來源地址http://www.zghlxwxcb.cn/news/detail-820555.html
@Mapper
public interface UmsSmsClientEsMapper extends BaseEsMapper<UmsSmsEsClient> {
}
到了這里,關于es相關介紹:yml配置、基礎接口及方法介紹的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!