弹性搜索错误:自定义分析器[custom_analyzer]找不到名称为[my_tokenizer]的令牌生成器

时间:2018-06-23 02:54:03

标签: java elasticsearch elastic-stack

我正在尝试与我的custom_analyzertokenizer一起进行字段映射,但是遇到了一些错误。

请在映射字段时找到以下来自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"
            }
          }
        }
      }
    }

1 个答案:

答案 0 :(得分:1)

正确缩进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"
        }
      }
    }
  }
}