元数据属性

Meta 元数据属性 #

_meta 字段是一个映射属性,允许您为索引映射附加自定义元数据。您的应用程序可以使用这些元数据来存储与您的用例相关的信息,如版本控制、所有权、分类或审计。

用法 #

您可以在创建新索引或更新现有索引的映射时定义 _meta 字段,如以下示例所示:

PUT my-index
{
  "mappings": {
    "_meta": {
      "application": "MyApp",
      "version": "1.2.3",
      "author": "John Doe"
    },
    "properties": {
      "title": {
        "type": "text"
      },
      "description": {
        "type": "text"
      }
    }
  }
}

在此示例中,添加了三个自定义元数据字段:applicationversionauthor。您的应用程序可以使用这些字段来存储有关索引的任何相关信息,例如它所属的应用程序、应用程序版本或索引的作者。

您可以使用 Put Mapping API 操作更新 _meta 字段,如以下示例所示:

PUT my-index/_mapping
{
  "_meta": {
    "application": "MyApp",
    "version": "1.3.0",
    "author": "Jane Smith"
  }
}

检索元数据信息 #

您可以使用 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"
        }
      }
    }
  }
}
Edit 编辑本页