You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Elasticsearch动态模板match属性失效,无法匹配_analyze结尾字段

解决Elasticsearch动态模板match属性不生效问题

问题根源

动态模板是按定义顺序优先匹配的,你当前的配置里,strings模板(匹配所有字符串类型字段)排在strings_analz模板前面,导致所有字符串字段(包括keywords_analyze)先被strings模板处理,后面的strings_analz模板完全没机会触发。另外,strings_analz的映射配置也和你期望的std_analyzer子字段不符。

修正后的配置

调整模板顺序,把strings_analz移到strings模板之前,同时修正映射内容以满足需求:

{
   "mappings": {
      "dynamic_templates": [
         {
            "integers": {
               "match_mapping_type": "long",
               "mapping": {
                  "type": "integer"
               }
            }
         },
         {
            "strings_analz": {
               "match": "*_analyze",
               "mapping": {
                  "type": "text",
                  "fields": {
                     "std_analyzer": {
                        "type": "text",
                        "term_vector": "yes",
                        "analyzer": "standard_analyzer"
                     }
                  }
               }
            }
         },
         {
            "strings": {
               "match_mapping_type": "string",
               "mapping": {
                  "type": "text"
               }
            }
         }
      ]
   }
}

验证结果

使用上述配置后,插入包含keywords_analyze的文档,生成的映射会和你期望的一致:

{
   "count": {
      "type": "integer"
   },
   "is_top": {
      "type": "boolean"
   },
   "keywords_analyze": {
      "type": "text",
      "fields": {
         "std_analyzer": {
            "type": "text",
            "term_vector": "yes",
            "analyzer": "standard_analyzer"
         }
      }
   }
}

内容的提问来源于stack exchange,提问作者yvario

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 10:10:23