> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 获取文档详情

> 获取指定文档的详细信息，包括索引状态、元数据和处理统计信息。



## OpenAPI

````yaml /zh/api-reference/openapi_service.json get /datasets/{dataset_id}/documents/{document_id}
openapi: 3.0.1
info:
  title: Dify 服务 API
  description: 用于 Dify 应用与知识库的 REST API。应用类接口使用应用 API 密钥认证，知识库类接口使用知识库 API 密钥认证。
  version: 1.0.0
servers:
  - url: https://{api_base_url}
    description: Dify 服务 API 的基础 URL。自部署时，替换为你的 API 基础 URL。
    variables:
      api_base_url:
        default: api.dify.ai/v1
        description: API 基础 URL 的主机与路径，不含 `https://` 前缀。
security:
  - ApiKeyAuth: []
tags:
  - name: 对话消息
    description: 与聊天消息和交互相关的操作。
  - name: 文件操作
    description: 文件上传和预览操作。
  - name: 终端用户
    description: 终端用户信息相关操作。
  - name: 消息反馈
    description: 用户反馈操作。
  - name: 会话管理
    description: 与管理会话相关的操作。
  - name: 语音与文字转换
    description: 文字转语音和语音转文字操作。
  - name: 应用配置
    description: 获取应用设置和信息的操作。
  - name: 标注管理
    description: 与管理标注直接回复相关的操作。
  - name: 人工介入
    description: 暂停等待人工输入的工作流恢复操作。
  - name: 工作流运行
    description: 用于执行和管理工作流的操作。
  - name: 文本生成消息
    description: 文本生成相关操作。
  - name: 知识库
    description: 用于管理知识库的操作，包括创建、配置和检索。
  - name: 文档
    description: 用于在知识库中创建、更新和管理文档的操作。
  - name: 分段
    description: 用于管理分段和子分段的操作。
  - name: 元数据
    description: 用于管理知识库元数据字段和文档元数据值的操作。
  - name: 标签
    description: 用于管理知识库标签和标签绑定的操作。
  - name: 模型
    description: 用于获取可用模型的操作。
  - name: 知识流水线
    description: 用于管理和运行知识流水线的操作，包括数据源插件和流水线执行。
paths:
  /datasets/{dataset_id}/documents/{document_id}:
    get:
      tags:
        - 文档
      summary: 获取文档详情
      description: 获取指定文档的详细信息，包括索引状态、元数据和处理统计信息。
      operationId: getDocumentDetail
      parameters:
        - name: dataset_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: 知识库 ID。
        - name: document_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: 文档 ID.
        - name: metadata
          in: query
          schema:
            type: string
            enum:
              - all
              - only
              - without
            default: all
          description: >-
            `all` 返回所有字段（包括元数据）。`only` 仅返回 `id`、`doc_type` 和
            `doc_metadata`。`without` 返回除 `doc_metadata` 外的所有字段。
      responses:
        '200':
          description: >-
            文档详情。响应结构根据 `metadata` 查询参数的不同而变化。当 `metadata` 为 `only` 时，仅返回
            `id`、`doc_type` 和 `doc_metadata`。当 `metadata` 为 `without` 时，省略
            `doc_type` 和 `doc_metadata`。
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: 文档标识符。
                  position:
                    type: integer
                    description: 在知识库中的位置索引。
                  data_source_type:
                    type: string
                    description: 文档的上传方式。文件上传为 `upload_file`，Notion 导入为 `notion_import`。
                  data_source_info:
                    type: object
                    description: >-
                      数据源详情。文件上传时，此详情接口在 `upload_file` 下返回完整的文件对象，而列表接口仅返回
                      `upload_file_id`。
                    properties:
                      upload_file:
                        type: object
                        description: 上传文件的详情。当 `data_source_type` 为 `upload_file` 时返回。
                        properties:
                          id:
                            type: string
                            description: 文件标识符。
                          name:
                            type: string
                            description: 原始文件名。
                          size:
                            type: integer
                            description: 文件大小（字节）。
                          extension:
                            type: string
                            description: 文件扩展名。
                          mime_type:
                            type: string
                            description: 文件的 MIME 类型。
                          created_by:
                            type: string
                            description: 上传该文件的用户 ID。
                          created_at:
                            type: integer
                            description: 文件上传的 Unix 时间戳。
                  dataset_process_rule_id:
                    type: string
                    description: 应用于该文档的处理规则 ID。
                  dataset_process_rule:
                    type: object
                    description: 知识库级别的处理规则配置。
                  document_process_rule:
                    type: object
                    description: 文档级别的处理规则配置。
                  name:
                    type: string
                    description: 文档名称。
                  created_from:
                    type: string
                    description: 文档来源。通过 API 创建时为 `api`，通过 UI 创建时为 `web`。
                  created_by:
                    type: string
                    description: 创建该文档的用户 ID。
                  created_at:
                    type: number
                    description: 文档创建的 Unix 时间戳。
                  tokens:
                    type: integer
                    description: 文档中的令牌数。
                  indexing_status:
                    type: string
                    description: >-
                      当前索引状态，例如
                      `waiting`、`parsing`、`cleaning`、`splitting`、`indexing`、`completed`、`error`、`paused`。
                  error:
                    type: string
                    nullable: true
                    description: 索引失败时的错误消息，否则为 `null`。
                  enabled:
                    type: boolean
                    description: 该文档是否启用检索。
                  disabled_at:
                    type: number
                    nullable: true
                    description: 文档被禁用的 Unix 时间戳，启用时为 `null`。
                  disabled_by:
                    type: string
                    nullable: true
                    description: 禁用该文档的用户 ID，启用时为 `null`。
                  archived:
                    type: boolean
                    description: 文档是否已归档。
                  display_status:
                    type: string
                    description: 适合 UI 显示的索引状态。
                  hit_count:
                    type: integer
                    description: 该文档被检索的次数。
                  doc_form:
                    type: string
                    description: >-
                      文档分块模式。`text_model` 表示标准文本，`hierarchical_model`
                      表示父子结构，`qa_model` 表示问答对。
                  doc_language:
                    type: string
                    description: 文档内容的语言。
                  doc_type:
                    type: string
                    nullable: true
                    description: 文档类型分类，未设置时为 `null`。
                  doc_metadata:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          description: 元数据字段标识符。
                        name:
                          type: string
                          description: 元数据字段名称。
                        type:
                          type: string
                          description: 元数据字段类型。
                        value:
                          type: string
                          description: 此文档的元数据字段值。
                    description: 此文档的自定义元数据键值对。
                  completed_at:
                    type: number
                    nullable: true
                    description: 处理完成的 Unix 时间戳，尚未完成时为 `null`。
                  updated_at:
                    type: number
                    nullable: true
                    description: 最后更新的 Unix 时间戳，从未更新时为 `null`。
                  indexing_latency:
                    type: number
                    nullable: true
                    description: 索引耗时（秒），未完成时为 `null`。
                  segment_count:
                    type: integer
                    description: 文档中的分段数。
                  average_segment_length:
                    type: number
                    description: 分段的平均字符长度。
                  summary_index_status:
                    type: string
                    nullable: true
                    description: 摘要索引的状态，未启用摘要索引时为 `null`。
                  need_summary:
                    type: boolean
                    description: 该文档是否需要生成摘要。
              examples:
                success:
                  summary: 响应示例
                  value:
                    id: a8e0e5b5-78c6-4130-a5ce-25feb0e0b4ac
                    position: 1
                    data_source_type: upload_file
                    data_source_info:
                      upload_file:
                        id: a1b2c3d4-e5f6-7890-abcd-ef1234567890
                        name: guide.txt
                        size: 2048
                        extension: txt
                        mime_type: text/plain
                        created_by: ad313dd6-ef04-4dd1-a5b0-c0f0b9e2e7e4
                        created_at: 1741267200
                    dataset_process_rule_id: e1f2a3b4-c5d6-7890-ef12-345678901234
                    dataset_process_rule:
                      id: e1f2a3b4-c5d6-7890-ef12-345678901234
                      mode: custom
                    document_process_rule:
                      mode: custom
                      rules:
                        pre_processing_rules: []
                        segmentation:
                          separator: '###'
                          max_tokens: 500
                          chunk_overlap: 50
                    name: guide.txt
                    created_from: api
                    created_by: ad313dd6-ef04-4dd1-a5b0-c0f0b9e2e7e4
                    created_at: 1741267200
                    tokens: 512
                    indexing_status: completed
                    error: null
                    enabled: true
                    disabled_at: null
                    disabled_by: null
                    archived: false
                    display_status: available
                    hit_count: 0
                    doc_form: text_model
                    doc_language: English
                    doc_type: null
                    doc_metadata: []
                    completed_at: 1741267260
                    updated_at: 1741267260
                    indexing_latency: 60
                    segment_count: 5
                    average_segment_length: 70
                    summary_index_status: null
                    need_summary: false
        '400':
          description: >-
            `invalid_metadata` : `metadata` 查询参数的值无效（必须为 `all`、`only` 或
            `without`）。
          content:
            application/json:
              examples:
                invalid_metadata:
                  summary: invalid_metadata
                  value:
                    status: 400
                    code: invalid_metadata
                    message: 'Invalid metadata value: only'
        '403':
          description: |-
            - `forbidden` : 无权限。
            - `forbidden` : 该知识库未启用 API 访问。
          content:
            application/json:
              examples:
                forbidden_1:
                  summary: forbidden (no permission)
                  value:
                    status: 403
                    code: forbidden
                    message: No permission.
                forbidden_2:
                  summary: forbidden (api access)
                  value:
                    status: 403
                    code: forbidden
                    message: Dataset api access is not enabled.
        '404':
          description: '`not_found` : 未找到文档。'
          content:
            application/json:
              examples:
                not_found:
                  summary: not_found
                  value:
                    status: 404
                    code: not_found
                    message: Document not found.
components:
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API_KEY
      description: >-
        API Key 认证。对于所有 API 请求，请在 `Authorization` HTTP 头中包含您的 API Key，并加上
        `Bearer ` 前缀。示例：`Authorization: Bearer {API_KEY}`。**强烈建议将 API Key
        存储在服务端，不要在客户端共享或存储，以避免 API Key 泄漏导致严重后果。**缺少或无效的 API Key 会返回 HTTP
        `401`，错误码为 `unauthorized`。

````