【问题标题】:Why isn't Elasticsearch detecting my custom made analyzer?为什么 Elasticsearch 没有检测到我的定制分析器?
【发布时间】:2016-11-04 17:24:25
【问题描述】:

我使用名为“自动完成”的定制分析器创建了一个索引“用户名”:

client.indices.create({
    index: 'user-name',
    type: 'text',
    settings: {
      analysis: {
        filter: {
          autocomplete_filter: {
            type: 'edge-ngram',
            min_gram: 1,
            max_gram: 20
          }
        },
        analyzer: {
          autocomplete: {
            type: 'custom',
            tokenizer: 'standard',
            filter: [
              'lowercase',
              'autocomplete_filter'
            ]
          }
        }
      }
    }
  }

然后我尝试通过在映射中使用这个定制分析器来引用它:

    client.indices.putMapping({
        index: 'user-name',
        type: 'text',
        body: {
          properties: {
            name: {
              type: 'string',
              analyzer: 'autocomplete',
              search_analyzer: 'standard'
            }
          }
        }
      })

但随后我收到此错误:“原因”:“未找到字段 [名称] 的分析器 [自动完成]”。为什么没有检测到我的自动完成分析器?谢谢。

【问题讨论】:

    标签: node.js elasticsearch indexing full-text-search analyzer


    【解决方案1】:

    你快到了。您只需将索引settings 放入body 参数中:

    client.indices.create({
        index: 'user-name',
        type: 'text',
        body: {
         settings: {
          analysis: {
            filter: {
              autocomplete_filter: {
                type: 'edge-ngram',
                min_gram: 1,
                max_gram: 20
              }
            },
            analyzer: {
              autocomplete: {
                type: 'custom',
                tokenizer: 'standard',
                filter: [
                  'lowercase',
                  'autocomplete_filter'
                ]
              }
            }
          }
        }
       }
    }
    

    【讨论】:

    • 酷,很高兴它有帮助!
    • type: 'text', 不再受支持,删除该行,并且从 2020 年 8 月起使用 type: 'edge_ngram' 代替 type: 'edge-ngram'
    • @AleksandarT 是的,显然自 2016 年以来事情已经发生了变化。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-12
    • 2021-05-26
    • 2017-11-05
    • 2011-06-26
    相关资源
    最近更新 更多