你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。

Documents - Index

向索引发送一批文档写入作。

POST {endpoint}/indexes('{indexName}')/docs/search.index?api-version=2026-04-01

URI 参数

名称 在 必需 类型 说明
endpoint
path True

string (uri)

搜索服务的终结点 URL。

indexName
path True

string

索引的名称。

api-version
query True

string

minLength: 1

用于此操作的 API 版本。

请求头

名称 必需 类型 说明
Accept

Accept

接受(Accept)首部。

x-ms-client-request-id

string (uuid)

请求的不透明、全局唯一的客户端生成的字符串标识符。

请求正文

名称 必需 类型 说明
value True

IndexAction[]

批处理中的作。

响应

名称 类型 说明
200 OK

IndexDocumentsResult

包含索引请求中所有文档的操作状态的响应。

Other Status Codes

IndexDocumentsResult

包含索引请求中所有文档的操作状态的响应。

Other Status Codes

ErrorResponse

意外的错误响应。

安全性

api-key

类型: apiKey
在: header

OAuth2Auth

类型: oauth2
流向: implicit
授权 URL: https://login.microsoftonline.com/common/oauth2/v2.0/authorize

作用域

名称 说明
https://search.azure.com/.default

示例

SearchIndexIndexDocuments

示例请求

POST https://exampleservice.search.windows.net/indexes('example-index')/docs/search.index?api-version=2026-04-01


{
  "value": [
    {
      "@search.action": "mergeOrUpload",
      "id": "0",
      "name": "test",
      "description": "test0 hello",
      "vector1": [
        0,
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
        11,
        12,
        13,
        14,
        15,
        16,
        17,
        18,
        19
      ],
      "vector1b": [
        10,
        11,
        12,
        13,
        14,
        15,
        16,
        17,
        18,
        19
      ],
      "vector2": [
        0,
        1,
        2,
        3,
        4
      ],
      "vector3": [
        0,
        1,
        2,
        3,
        4
      ],
      "vector22": [
        20,
        21,
        22,
        23,
        24,
        25,
        26,
        27,
        28,
        29
      ],
      "ownerId": "benny",
      "category": "purple",
      "price": 0
    },
    {
      "@search.action": "mergeOrUpload",
      "id": "1",
      "name": "test",
      "description": "test1 hello",
      "vector1": [
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
        11,
        12,
        13,
        14,
        15,
        16,
        17,
        18,
        19,
        20
      ],
      "vector1b": [
        11,
        12,
        13,
        14,
        15,
        16,
        17,
        18,
        19,
        20
      ],
      "vector2": [
        1,
        2,
        3,
        4,
        5
      ],
      "vector3": [
        1,
        2,
        3,
        4,
        5
      ],
      "vector22": [
        21,
        22,
        23,
        24,
        25,
        26,
        27,
        28,
        29,
        30
      ],
      "ownerId": "sam",
      "category": "purple",
      "price": 1
    },
    {
      "@search.action": "mergeOrUpload",
      "id": "2",
      "name": "test",
      "description": "test2 hello",
      "vector1": [
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
        11,
        12,
        13,
        14,
        15,
        16,
        17,
        18,
        19,
        20,
        21
      ],
      "vector1b": [
        12,
        13,
        14,
        15,
        16,
        17,
        18,
        19,
        20,
        21
      ],
      "vector2": [
        2,
        3,
        4,
        5,
        6
      ],
      "vector3": [
        2,
        3,
        4,
        5,
        6
      ],
      "vector22": [
        22,
        23,
        24,
        25,
        26,
        27,
        28,
        29,
        30,
        31
      ],
      "ownerId": "sam",
      "category": "purple",
      "price": 2
    }
  ]
}

示例响应

{
  "value": [
    {
      "key": "0",
      "status": true,
      "statusCode": 201
    },
    {
      "key": "1",
      "status": true,
      "statusCode": 201
    },
    {
      "key": "2",
      "status": true,
      "statusCode": 201
    }
  ]
}
{
  "value": [
    {
      "key": "0",
      "status": true,
      "statusCode": 201
    },
    {
      "key": "1",
      "status": true,
      "statusCode": 201
    },
    {
      "key": "2",
      "status": true,
      "statusCode": 201
    }
  ]
}

定义

名称 说明
Accept

接受(Accept)首部。

ErrorAdditionalInfo

资源管理错误附加信息。

ErrorDetail

错误详细信息。

ErrorResponse

所有 Azure 资源管理器 API 的通用错误响应,用于返回失败操作的错误细节。 (这也遵循 OData 错误响应格式)。

IndexAction

表示对文档进行操作的索引操作。

IndexActionType

要对索引批处理中的文档执行的作。

IndexBatch

包含要发送到索引的一批文档写入作。

IndexDocumentsResult

包含索引请求中所有文档的操作状态的响应。

IndexingResult

单个文档的索引操作的状态。

Accept

接受(Accept)首部。

值 说明
application/json;odata.metadata=none

ErrorAdditionalInfo

资源管理错误附加信息。

名称 类型 说明
info

附加信息。

type

string

附加信息类型。

ErrorDetail

错误详细信息。

名称 类型 说明
additionalInfo

ErrorAdditionalInfo[]

错误附加信息。

code

string

错误代码。

details

ErrorDetail[]

错误详细信息。

message

string

错误消息。

target

string

错误目标。

ErrorResponse

所有 Azure 资源管理器 API 的通用错误响应,用于返回失败操作的错误细节。 (这也遵循 OData 错误响应格式)。

名称 类型 说明
error

ErrorDetail

错误对象。

IndexAction

表示对文档进行操作的索引操作。

名称 类型 说明
@search.action

IndexActionType

要对索引批处理中的文档执行的作。

IndexActionType

要对索引批处理中的文档执行的作。

值 说明
upload

将文档插入到索引中(如果文档是新的),如果文档存在,则对其进行更新。 在更新案例中,所有字段都将被替换。

merge

将指定的字段值与现有文档合并。 如果文档不存在,则合并将失败。 您在合并中指定的任何字段都将替换文档中的现有字段。 这也适用于原始类型和复杂类型的集合。

mergeOrUpload

如果索引中已存在具有给定键的文档,则其行为类似于 merge。 如果文档不存在,则其行为类似于与新文档一起上传。

delete

从索引中删除指定的文档。 在删除作中指定的除键字段之外的任何字段都将被忽略。 如果要从文档中移除单个字段,请改用 merge 并将该字段显式设置为 null。

IndexBatch

包含要发送到索引的一批文档写入作。

名称 类型 说明
value

IndexAction[]

批处理中的作。

IndexDocumentsResult

包含索引请求中所有文档的操作状态的响应。

名称 类型 说明
value

IndexingResult[]

索引请求中每个文档的状态信息列表。

IndexingResult

单个文档的索引操作的状态。

名称 类型 说明
errorMessage

string

错误消息,说明键标识的文档索引作为何失败;如果索引成功,则为 null。

key

string

索引请求中文档的键。

status

boolean

一个值,该值指示键标识的文档的索引作是否成功。

statusCode

integer (int32)

索引作的状态代码。 可能的值包括:200 用于成功更新或删除,201 用于成功创建文档,400 表示格式不正确的输入文档,404 表示找不到文档,版本冲突为 409;索引暂时不可用时为 422;如果服务太忙,则为 503。