在 Elasticsearch 中,'type' 和 'mapping' 定义了索引中数据的结构和类型。每个索引可以包含一个或多个 'type',每个 'type' 都有自己的 'mapping'。'Mapping' 定义了每个字段的数据类型、分析器、索引方式等信息。当我们往索引中添加文档时,文档的字段必须符合对应 'type' 的 'mapping' 定义,否则会被拒绝并返回错误信息。

例如,我们创建了一个名为 'blog' 的索引,包含两个 'type':'article' 和 'comment'。我们为 'article' 和 'comment' 分别定义了对应的 'mapping'。当我们往 'article' 'type' 中添加一篇文章时,该文档的每个字段都必须符合 'article' 'type' 的 'mapping' 定义,否则会被拒绝。同理,当我们往 'comment' 'type' 中添加一条评论时,该文档的每个字段都必须符合 'comment' 'type' 的 'mapping' 定义。

因此,'type' 和 'mapping' 定义了索引中数据的结构和类型,而文档则必须符合对应 'type' 的 'mapping' 定义。

Elasticsearch 中 Type、Mapping 和 Document 的关系

原文地址: https://www.cveoy.top/t/topic/mX9o 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录