使用Monstache集成MongoDB与Elasticsearch时遇400错误求解决
解决Monstache同步MongoDB到Elasticsearch时的"type is missing"错误
问题原因
你遇到的elastic: Error 400 (Bad Request): Validation Failed: 1: type is missing错误,是因为Elasticsearch的批量API仍需指定文档类型(尽管Elasticsearch 7+已废弃类型概念,但默认需使用_doc作为类型值),而你的Monstache配置未明确设置该字段。
解决方案
在[[mapping]]配置块中添加type = "_doc"字段,明确指定Elasticsearch的文档类型为_doc。
修改后的完整配置
mongo-url = "mongodb+srv://prince:mypassword@cluster0.mp297.mongodb.net/?retryWrites=true&w=majority" elasticsearch-urls = ["http://127.0.0.1:9200"] elasticsearch-max-conns = 10 replay = false resume = true enable-oplog = true resume-name = "default" namespace-regex = '^Satellite\.posts$' direct-read-namespaces = ["Satellite.posts"] change-stream-namespaces = ["Satellite."] index-as-update = true verbose = true exit-after-direct-reads = false [[mapping]] namespace = "Satellite.posts" index = "satellite" type = "_doc" # 新增该行配置
额外说明
- Elasticsearch 7.x及以上版本中,文档类型已被废弃,统一使用
_doc作为默认类型标识。 - Monstache需要明确配置
type字段,才能生成符合Elasticsearch要求的批量请求。
内容的提问来源于stack exchange,提问作者Prince
相关产品推荐
相关产品推荐

