ES索引模板

在Elasticsearch中,索引模板(Index Templates)是用來預定義新創建索引的設置和映射的一種機制。當你創建了一個索引模板,它會包含一系列的默認設置和映射規則,這些規則會在滿足一定條件的新索引被創建時自動應用。

索引模板通過index_patterns字段來指定模板適用的索引名稱模式。當一個新的索引被創建,Elasticsearch會查找是否有任何模板的index_patterns與該索引名稱匹配。如果有匹配的模板,那么該模板的設置和映射將被應用到新創建的索引上。

因此,如果你創建了一個名為content_erp_nlp_help_online的索引模板,并且在其中定義了index_patterns["content_erp_nlp_help_online"],那么當你嘗試創建一個確切名稱為content_erp_nlp_help_online的索引時,該模板將會被應用,從而自動配置索引的設置和映射。

但是,需要注意的是,如果在創建索引時顯式指定了某些設置或映射,那么這些顯式指定的值將優先于模板中的值。此外,一旦索引已經被創建,索引模板的更改將不會影響到已經存在的索引。

索引模板還可以通過通配符模式來匹配多個索引。例如,如果模板的index_patterns["content_*"],那么所有以content_開頭的索引都會應用該模板。

總結來說,索引模板是一種策略,它允許你預設一組設置和映射,以便在創建符合特定命名模式的新索引時自動應用這些預設。這極大地簡化了管理大量索引的過程,尤其是當這些索引具有相似的特性時。

ES 8.14 新的創建模板的方法:

PUT /_index_template/content_erp_nlp_help
{"index_patterns": ["content_erp*"],"priority": 100,"template": {"settings": {"analysis": {"analyzer": {"my_ik_analyzer": {"type": "ik_smart"}}},"number_of_shards": 1},"mappings": {"properties": {"id": {"type": "long"},"content": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart"},"content_vector": {"type": "dense_vector","similarity": "cosine","index": true,"dims": 768,"element_type": "float","index_options": {"type": "hnsw","m": 16,"ef_construction": 128}},"content_answer": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart"},"title": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart"},"param": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart"},"type": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart"},"questionId": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart"},"createTime": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart"},"updateTime": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart"},"hitCount": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart"},"answerPattern": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart"},"nearQuestionVOList": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart"},"questionEnclosureVOList": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart"},"questionRelationVOList": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart"},"rmsRoutingAnswerVos": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart"}}}}
}

查詢模板:

GET /_index_template/*

GET /_index_template/content_erp_nlp_help

Java實現的代碼:

public int createIndexTemp(String indexTempName) throws Exception {// 創建RestClient實例RestClientBuilder builder = RestClient.builder(new HttpHost("127.0.0.1", 9200, "http"));RestClient restClient = builder.build();// 定義請求體String requestBody = "{\n" +"  \"index_patterns\": [\"content_erp*\"],\n" +"  \"priority\": 100,\n" +"  \"template\": {\n" +"    \"settings\": {\n" +"      \"analysis\": {\n" +"        \"analyzer\": {\n" +"          \"my_ik_analyzer\": {\n" +"            \"type\": \"ik_smart\"\n" +"          }\n" +"        }\n" +"      },\n" +"      \"number_of_shards\": 1\n" +"    },\n" +"    \"mappings\": {\n" +"      \"properties\": {\n" +"        \"id\": {\"type\": \"long\"},\n" +"        \"content\": {\"type\": \"text\",\"analyzer\": \"ik_max_word\",\"search_analyzer\": \"ik_smart\"},\n" +"        \"content_vector\": {\"type\": \"dense_vector\",\"similarity\": \"cosine\",\"index\": true,\"dims\": 768,\"element_type\": \"float\",\"index_options\": {\"type\": \"hnsw\",\"m\": 16,\"ef_construction\": 128}},\n" +"        \"content_answer\": {\"type\": \"text\",\"analyzer\": \"ik_max_word\",\"search_analyzer\": \"ik_smart\"},\n" +"        \"title\": {\"type\": \"text\",\"analyzer\": \"ik_max_word\",\"search_analyzer\": \"ik_smart\"},\n" +"        \"param\": {\"type\": \"text\",\"analyzer\": \"ik_max_word\",\"search_analyzer\": \"ik_smart\"},\n" +"        \"type\": {\"type\": \"text\",\"analyzer\": \"ik_max_word\",\"search_analyzer\": \"ik_smart\"},\n" +"        \"questionId\": {\"type\": \"text\",\"analyzer\": \"ik_max_word\",\"search_analyzer\": \"ik_smart\"},\n" +"        \"createTime\": {\"type\": \"text\",\"analyzer\": \"ik_max_word\",\"search_analyzer\": \"ik_smart\"},\n" +"        \"updateTime\": {\"type\": \"text\",\"analyzer\": \"ik_max_word\",\"search_analyzer\": \"ik_smart\"},\n" +"        \"hitCount\": {\"type\": \"text\",\"analyzer\": \"ik_max_word\",\"search_analyzer\": \"ik_smart\"},\n" +"        \"answerPattern\": {\"type\": \"text\",\"analyzer\": \"ik_max_word\",\"search_analyzer\": \"ik_smart\"},\n" +"        \"nearQuestionVOList\": {\"type\": \"text\",\"analyzer\": \"ik_max_word\",\"search_analyzer\": \"ik_smart\"},\n" +"        \"questionEnclosureVOList\": {\"type\": \"text\",\"analyzer\": \"ik_max_word\",\"search_analyzer\": \"ik_smart\"},\n" +"        \"questionRelationVOList\": {\"type\": \"text\",\"analyzer\": \"ik_max_word\",\"search_analyzer\": \"ik_smart\"},\n" +"        \"rmsRoutingAnswerVos\": {\"type\": \"text\",\"analyzer\": \"ik_max_word\",\"search_analyzer\": \"ik_smart\"}\n" +"      }\n" +"    }\n" +"  }\n" +"}";// 構建請求Request request = new Request("PUT", "/_index_template/" + indexTempName);request.setJsonEntity(requestBody);// 發送請求并獲取響應Response response = restClient.performRequest(request);// 處理響應int statusCode = response.getStatusLine().getStatusCode();System.out.println("Response status: " + statusCode);// 關閉RestClientrestClient.close();return statusCode;}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/45148.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/45148.shtml
英文地址,請注明出處:http://en.pswp.cn/web/45148.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

UOS查看系統信息命令行

UOS查看系統信息命令行 *** Rz整理 僅供參考 *** dmidecode查看System Boot信息 midecode -t 32 dmidecode查看System Reset信息 midecode -t 23 dmidecode查看機箱信息 midecode -t chassis dmidecode查看BIOS信息 midecode -t bios dmidecode查看CPU信息 dmidecode …

leetcode 404. 左葉子之和

給定二叉樹的根節點 root ,返回所有左葉子之和。 示例 1: 輸入: root [3,9,20,null,null,15,7] 輸出: 24 解釋: 在這個二叉樹中,有兩個左葉子,分別是 9 和 15,所以返回 24示例 2: 輸入: root [1] 輸出: 0提示: 節點…

Linux 下使用Docker安裝redis

redis: 是一個高性能的,鍵值對的,將數據存儲到內存中的非關系型數據庫(nosql數據庫 not only sql) 高性能:數據存在內存中,直接訪問內存 鍵值對:新聞id(鍵&#xff09…

c++數據結構--構造無向圖(算法6.1),深度和廣度遍歷

實驗內容: 實現教材算法6.2利用鄰接矩陣構造無向圖的算法,提供從鄰接矩陣獲得鄰接表的功能,在此基礎上進行深度優先遍歷和廣度優先遍歷。 實驗步驟: (1)按照實驗要求編寫代碼,構造無向圖。 ?…

淺談數學模型在UGC/AIGC游戲數值調參中的應用(AI智能體)

淺談數學模型在UGC/AIGC游戲數值調參中的應用 ygluu 盧益貴 關鍵詞:UGC、AIGC、AI智能體、大模型、數學模型、游戲數值調參、游戲策劃 一、前言 在策劃大大群提出《游戲工廠:AI(AIGC/ChatGPT)與流程式游戲開發》討論之后就已完…

Hi3861 OpenHarmony嵌入式應用入門--HTTPD

httpd 是 Apache HTTP Server 的守護進程名稱,Apache HTTP Server 是一種廣泛使用的開源網頁服務器軟件。 本項目是從LwIP中抽取的HTTP服務器代碼; Hi3861 SDK中已經包含了一份預編譯的lwip,但沒有開啟HTTP服務器功能(靜態庫無法…

NiFi1.25版本HTTPS模式下RestAPI使用入門

Apache NiFi 是一個強大的數據流處理工具,通過其 REST API,用戶可以遠程管理和控制數據流處理器。本文將介紹如何使用 NiFi 1.25 版本HTTPS 模式下Rest API,包括獲取 token、獲取組件信息、啟動和停止組件、以及更改組件的調度頻率等操作。 …

Linux vim文本編輯器

Vim(Vi IMproved)是一個高度可配置的文本編輯器,它是Vi編輯器的增強版本,廣泛用于程序開發和系統管理。Vim不僅保留了Vi的所有功能,還增加了許多新特性,使其更加強大和靈活。 Vim操作模式 普通模式&#xf…

科普文:微服務之Apollo配置中心

1. 基本概念 由于Apollo 概念比較多,剛開始使用比較復雜,最好先過一遍概念再動手實踐嘗試使用。 1.1、背景 隨著程序功能的日益復雜,程序的配置日益增多,各種功能的開關、參數的配置、服務器的地址……對程序配置的期望值也越來…

在 C++中,如何使用智能指針來有效地管理動態分配的內存,并避免內存泄漏的問題?

在C中,可以使用智能指針來有效地管理動態分配的內存,避免內存泄漏的問題。下面是一些常用的智能指針類型和操作: std::unique_ptr: std::unique_ptr是C11引入的一種獨占式智能指針,它擁有對分配的內存的唯一所有權。當…

026-GeoGebra中級篇-曲線(2)_極坐標曲線、參數化曲面、分段函數曲線、分形曲線、復數平面上的曲線、隨機曲線、非線性動力系統的軌跡

除了參數曲線、隱式曲線和顯式曲線之外,還有其他類型的曲線表示方法。本篇主要概述一下極坐標曲線、參數化曲面、分段函數曲線、分形曲線、復數平面上的曲線、隨機曲線、和非線性動力系統的軌跡,可能沒有那么深,可以先了解下。 目錄 1. 極坐…

「網絡通信」HTTP 協議

HTTP 🍉簡介🍉抓包工具🍉報文結構🍌請求🍌響應🍌URL🥝URL encode 🍌方法🍌報文字段🥝Host🥝Content-Length & Content-Type🥝User…

運動控制問題

第一類運動控制問題是指被控制對象的空間位置或軌跡運動發生改變的運動控制系統的控制問題。這類運動控制問題在理論上完全遵循牛頓力學定律和運動學原則。 1、運動控制問題 第1類運動控制的核心是研究被控對象的運動軌跡 、分析運動路徑、運動速度、加速度與時間的關系,常用…

深入解析PHP框架:Symfony框架詳解與應用

文章目錄 深入解析PHP框架:Symfony框架詳解與應用一、什么是Symfony?Symfony的優勢 二、Symfony的核心概念1. 控制器2. 路由3. 模板4. 服務容器5. 事件調度器 三、Symfony的主要功能1. 表單處理2. 數據庫集成3. 安全性4. 國際化5. 調試與日志 四、開發流…

記一次docker容器安裝MySQL,navicat無法連接報錯(10060錯誤)

今天在云服務器上使用docker部署mysql 8.0.11時,遇到了一個詭異的問題,在云服務器的docker容器內可以連接上mysql,然而在自己電腦上連接mysql時報錯:Can‘t connect to MySQL server on localhost (10060) 下面是網上搜尋的幾種可…

SpringMVC框架--個人筆記步驟總結

一、步驟 1.創建工程 2.加入springmvc依賴--pom.xml <!--springmvc依賴--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.2.10.RELEASE</version> </depend…

Camunda如何通過外部任務與其他系統自動交互

文章目錄 簡介流程圖外部系統pom.xmllogback.xml監聽類 啟動流程實例常見問題Public Key Retrieval is not allowed的解決方法java.lang.reflect.InaccessibleObjectException 流程圖xml 簡介 前面我們已經介紹了Camunda的基本操作、任務、表&#xff1a; Camunda組件與服務與…

Linux命令更新-Vim 編輯器

簡介 Vim 是 Linux 系統中常用的文本編輯器&#xff0c;功能強大、可擴展性強&#xff0c;支持多種編輯模式和操作命令&#xff0c;被廣泛應用于程序開發、系統管理等領域。 1. Vim 命令模式 Vim 啟動后默認進入命令模式&#xff0c;此時鍵盤輸入的命令將用于控制編輯器本身&…

Android ImageDecoder把瘦高/扁平大圖相當于fitCenter模式decode成目標小尺寸Bitmap,Kotlin

Android ImageDecoder把瘦高/扁平大圖相當于fitCenter模式decode成目標小尺寸Bitmap&#xff0c;Kotlin val sz Size(MainActivity.SIZE, MainActivity.SIZE)val src ImageDecoder.createSource(mContext?.contentResolver!!, uri)val bitmap ImageDecoder.decodeBitmap(sr…

【Playwright+Python】系列 Pytest 插件在Playwright中的使用

一、命令行使用詳解 使用 Pytest 插件在Playwright 中來編寫端到端的測試。 1、命令行執行測試 pytest --browser webkit --headed 2、使用 pytest.ini 文件配置 內容如下&#xff1a; [pytest] # Run firefox with UIaddopts --headed --browser firefox效果&#xff1…