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": {
       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值