【问题标题】:Elasticsearch: Issues reindexing - ending up with more than one typeElasticsearch:重新索引问题 - 以不止一种类型结束
【发布时间】:2020-08-08 02:58:15
【问题描述】:

ES 6.8.6 我正在尝试重新索引一些索引以减少分片数量。

原始索引的类型为“auth”,但最近我添加了一个使用 _doc 的模板。当我尝试时:

curl -X POST "localhost:9200/_reindex?pretty" -H 'Content-Type: application/json' -d'
{
  "source": {
      "index": "auth_2019.03.02"
  },
  "dest": {
      "index": "auth_ri_2019.03.02",
      "type": "_doc"

  }
}
'

我收到此错误:

"Rejecting mapping update to [auth_ri_2019.03.02] as the final mapping would have more than 1 type: [_doc, auth]"

我了解我不能拥有多个类型,并且类型在 7.x 中已被贬值。我的问题是我可以在重新索引操作期间更改类型。

我正在努力整理一切,为迁移到 7.x 做准备。

【问题讨论】:

  • 尝试将type 内的dest 设置为per documentation
  • 谢谢!,实际上我试过了,重新阅读文档,我发现源索引的类型应该被忽略了。现在的问题变成了它在哪里可以获取源索引中的类型“auth”类型。将更新问题...
  • Hmmm... 添加 "type": "auth" 到源使错误消失,现在我创建了一个空索引,但设置正确。进展。
  • 噢! dest 索引为空是有充分理由的。来源也是如此!问题解决了。我要做的是为源和目标添加显式类型条目。

标签: elasticsearch reindex


【解决方案1】:

首先感谢leandrojmp 提示我重新阅读文档并注意到他们为源和目标指定类型的示例。

我不明白为什么,但是在源规范中添加一个类型解决了这个问题。

这行得通:

curl -X POST "localhost:9200/_reindex?pretty" -H 'Content-Type: application/json' -d'
{
  "source": {
      "index": "auth_2019.03.02",
      "type": "auth"
  },
  "dest": {
      "index": "auth_ri_2019.03.02",
      "type": "_doc"

  }
}
'

【讨论】:

    【解决方案2】:

    看起来您必须编写一个脚本来在重新索引过程中更改文档。

    来自docs

    与 _update_by_query 一样,_reindex 支持修改文档的脚本。

    您确实可以更改type

    想想可能性!小心点;你可以改变: _ID, _类型, _指数, _版本, _路由

    根据您的情况添加

    
      "script": {
        "source": "ctx._type = '_doc'",
        "lang": "painless"
      }
    
    

    完整示例

    {
      "source": {
          "index": "auth_2019.03.02"
      },
      "dest": {
          "index": "auth_ri_2019.03.02",
      },
      "script": {
        "source": "ctx._type = '_doc'",
        "lang": "painless"
      },
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-12
      • 1970-01-01
      • 1970-01-01
      • 2011-09-28
      • 1970-01-01
      相关资源
      最近更新 更多