首页 > 解决方案 > 弹性搜索错误:自定义分析器 [custom_analyzer] 未能在名称 [my_tokenizer] 下找到标记器

问题描述

我正在尝试与我的custom_analyzer&进行字段映射,tokenizer但遇到了一些错误。

请在下面找到映射字段时从 kibana 得到的错误

Custom Analyzer [custom_analyzer] failed to find tokenizer under name [my_tokenizer]

请找到我的映射详细信息。

PUT attach_local
    {
        "settings": {
        "analysis": {
          "analyzer": {
            "custom_analyzer": {
              "type": "custom",
              "tokenizer": "my_tokenizer",
              "char_filter": [
                "html_strip"
              ],
              "filter": [
                "lowercase",
                "asciifolding"
              ]
            }
           }
          }
        },
        "tokenizer": {
        "my_tokenizer": {
          "type": "ngram",
          "min_gram": 3,    
          "max_gram": 3,
          "token_chars": [
            "letter",
            "digit"
          ]
        }
      },

      "mappings" : {
        "doc" : {
          "properties" : {
            "attachment" : {
              "properties" : {
                "content" : {
                  "type" : "text",
                  "analyzer": "custom_analyzer"
                },
                "content_length" : {
                  "type" : "long"
                },
                "content_type" : {
                  "type" : "text"
                },
                "language" : {
                  "type" : "text"
                }
              }
            },
            "resume" : {
              "type" : "text"
            }
          }
        }
      }
    }

标签: javaelasticsearchelastic-stack

解决方案


正确缩进 JSON 非常重要。您会看到您的标记器未正确位于该analysis部分内。这是正确的定义:

{
  "settings": {
    "analysis": {
      "analyzer": {
        "custom_analyzer": {
          "type": "custom",
          "tokenizer": "my_tokenizer",
          "char_filter": [
            "html_strip"
          ],
          "filter": [
            "lowercase",
            "asciifolding"
          ]
        }
      },
      "tokenizer": {
        "my_tokenizer": {
          "type": "ngram",
          "min_gram": 3,
          "max_gram": 3,
          "token_chars": [
            "letter",
            "digit"
          ]
        }
      }
    }
  },
  "mappings": {
    "doc": {
      "properties": {
        "attachment": {
          "properties": {
            "content": {
              "type": "text",
              "analyzer": "custom_analyzer"
            },
            "content_length": {
              "type": "long"
            },
            "content_type": {
              "type": "text"
            },
            "language": {
              "type": "text"
            }
          }
        },
        "resume": {
          "type": "text"
        }
      }
    }
  }
}

推荐阅读