Elasticsearch 的`nested`字段是一种强大的数据类型,用于处理嵌套对象数组,允许将每个对象独立索引和查询。以下是关于`nested`字段的详细说明:
1.`nested`字段的定义
`nested`字段是`object`数据类型的特殊版本,允许将对象数组索引为独立的隐藏文档。这使得每个嵌套对象可以独立于其他对象进行查询。例如:
```json
PUT /blog-posts
{
"mappings": {
"properties": {
"title": { "type": "text" },
"content": { "type": "text" },
"comments": {
"type": "nested",
"properties": {
"username": { "type": "keyword" },
"comment": { "type": "text" },
"created_at": { "type": "date" }
}
}
}
}
}