You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 12:36:17