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.mzph.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…