如何将自定义分析器应用于弹性搜索索引?

问题描述 投票:0回答:1

我正在尝试为索引创建自定义分析器,以便使用此自定义索引生成令牌。

我尝试执行以下操作

PUT /index_name/_settings
{
  "analysis" : {
    "analyzer":{
      "custom_analyzer_name": {
          "type": "custom", 
          "tokenizer": "standard",
          "char_filter": [
            "html_strip"
          ],
          "filter": [
            "lowercase",
            "stop"
          ]
        }
    }
  }
}

这给了我这个错误

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Can't update non dynamic settings [[index.analysis.analyzer.custom_analyzer_name.char_filter, index.analysis.analyzer.custom_analyzer_name.filter, index.analysis.analyzer.custom_analyzer_name.type, index.analysis.analyzer.custom_analyzer_name.tokenizer]] for open indices [[index_name/Zd4fisCyR6alpkzj-6uSgQ]]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Can't update non dynamic settings [[index.analysis.analyzer.custom_analyzer_name.char_filter, index.analysis.analyzer.custom_analyzer_name.filter, index.analysis.analyzer.custom_analyzer_name.type, index.analysis.analyzer.custom_analyzer_name.tokenizer]] for open indices [[index_name/Zd4fisCyR6alpkzj-6uSgQ]]"
  },
  "status": 400
}

我也试过这样创建分析器


PUT /index_name
{
  "settings": {
    "analysis": {
      "analyzer": {
        "custom_analyzer_name": {
          "type": "custom", 
          "tokenizer": "standard",
          "char_filter": [
            "html_strip"
          ],
          "filter": [
            "lowercase",
            "stop"
          ]
        }
      }
    }
  }
}

但这给了我以下错误

{
  "error": {
    "root_cause": [
      {
        "type": "resource_already_exists_exception",
        "reason": "index [index_name/Zd4fisCyR6alpkzj-6uSgQ] already exists",
        "index_uuid": "Zd4fisCyR6alpkzj-6uSgQ",
        "index": "index_name"
      }
    ],
    "type": "resource_already_exists_exception",
    "reason": "index [index_name/Zd4fisCyR6alpkzj-6uSgQ] already exists",
    "index_uuid": "Zd4fisCyR6alpkzj-6uSgQ",
    "index": "index_name"
  },
  "status": 400
}

如何在 Elasticsearch 索引中正确创建和分配自定义分析器?

elasticsearch elastic-stack
1个回答
0
投票

从你得到的错误来看,

index_name
已经存在,所以你不能重新创建它,除非你先删除它。

如果你不能删除它,而只想修改分析器,你可以先关闭索引然后重新打开它:

POST index_name/_close

PUT /index_name/_settings
{
  "analysis" : {
    "analyzer":{
      "custom_analyzer_name": {
          "type": "custom", 
          "tokenizer": "standard",
          "char_filter": [
            "html_strip"
          ],
          "filter": [
            "lowercase",
            "stop"
          ]
        }
    }
  }
}

POST index_name/_open

您可能需要在关闭索引之前运行它

PUT _cluster/settings
{
  "persistent": {
    "cluster.indices.close.enable": true
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.