更改 Elasticsearch 索引的分析器?

Chr*_*vey 3 elasticsearch

我想更改 ElasticSearch 中现有索引的分析器,但我无法弄清楚语法(而且我没有理解错误消息)。

GET /ccc_test/_mapping

{
  "ccc_test": {
    "mappings": {
      "test_article": {
        "properties": {
          "id": {
            "type": "text"
          },
          "language": {
            "type": "text"
          },
          "text": {
            "type": "text"
          },
          "title": {
            "type": "text"
          },
          "url": {
            "type": "keyword"
          }
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

然后我用以下命令关闭索引:

POST /ccc_test/_close
Run Code Online (Sandbox Code Playgroud)

然后我尝试将“标题”字段的分析器更新为葡萄牙语:

PUT /ccc_test/_mapping/test_article
{
  "properties" : {
    "title" : {
      "type" : "text",
      "analyzer" : "portuguese"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但我收到这个错误:

{
  "error": {
    "root_cause": [
      {
        "type": "remote_transport_exception",
        "reason": "[instance-0000000004][172.17.0.8:19760][indices:admin/mapping/put]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Mapper for [title] conflicts with existing mapping in other types:\n[mapper [title] has different [analyzer]]"
  },
  "status": 400
}
Run Code Online (Sandbox Code Playgroud)

所以我不清楚什么有不同的分析仪。ccc_test 索引仅包含一种类型(test_article)。我使用的是 ElasticSearch 5.6

Chr*_*vey 6

事实证明,你做不到我想做的事。正确答案是:

  1. 使用所需的映射创建新索引
  2. 使用“reindex”将数据从旧索引复制到新索引
  3. 删除旧索引,但使用旧索引的名称创建一个指向新索引的别名(因为 ElasticSearch 不允许您重命名索引。)

那么详细

  1. 使用所需的映射创建新索引

POST /ccc_test_new { "mappings": { "test_article": { "properties": { "id": { "type": "text" }, "language": { "type": "text" }, "text": { "type": "text" }, "title": { "type": "text" }, "url": { "type": "keyword" } } } } }

  1. 使用“reindex”将数据从旧索引复制到新索引

POST /_reindex """{ "source" : { "index" : "ccc_test" }, "dest" : { "index" : "ccc_test_new", "version_type" : "external" } }

  1. 删除旧索引,但使用旧索引的名称创建指向新索引的别名

POST /_aliases { "actions" : [ { "add" : { "index" : "ccc_test_new", "alias" : "ccc_test" } }, { "remove_index" : { "index": "ccc_test" } } ] }