嵌套对象映射 | Elasticsearch: 权威指南 | Elastic
2025-10-25
设置一个字段为 nested 很简单 —
你只需要将字段类型 object 替换为 nested 即可:
PUT /my_index
{
"mappings": {
"blogpost": {
"properties": {
"comments": {
"type": "nested",
"properties": {
"name": { "type": "string" },
"comment": { "type": "string" },
"age": { "type": "short" },
"stars": { "type": "short" },
"date": { "type": "date" }
}
}
}
}
}
}这就是需要设置的一切。至此,所有 comments 对象会被索引在独立的嵌套文档中。可以查看 nested 类型参考文档 获取更多详细信息。
官方地址:https://www.elastic.co/guide/cn/elasticsearch/guide/current/nested-mapping.html