元数据
_meta
字段是一个映射属性,允许您将自定义元数据附加到索引映射。应用程序可以使用此元数据来存储与您的用例相关的信息,例如版本控制、所有权、分类或审计。
用法
您可以在创建新索引或更新现有索引的映射时定义 _meta
字段,如以下示例请求所示
PUT my-index
{
"mappings": {
"_meta": {
"application": "MyApp",
"version": "1.2.3",
"author": "John Doe"
},
"properties": {
"title": {
"type": "text"
},
"description": {
"type": "text"
}
}
}
}
在此示例中,添加了三个自定义元数据字段:application
、version
和 author
。您的应用程序可以使用这些字段来存储有关索引的任何相关信息,例如索引所属的应用程序、应用程序版本或索引作者。
您可以使用 Put Mapping API 操作更新 _meta
字段,如以下示例请求所示
PUT my-index/_mapping
{
"_meta": {
"application": "MyApp",
"version": "1.3.0",
"author": "Jane Smith"
}
}
检索 meta
信息
您可以使用 Get Mapping API 操作检索索引的 _meta
信息,如以下示例请求所示
GET my-index/_mapping
响应返回完整的索引映射,包括 _meta
字段
{
"my-index": {
"mappings": {
"_meta": {
"application": "MyApp",
"version": "1.3.0",
"author": "Jane Smith"
},
"properties": {
"description": {
"type": "text"
},
"title": {
"type": "text"
}
}
}
}
}