searchEntity: query

命名空间:microsoft.graph

重要

Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。

运行指定的搜索查询。 响应中提供了搜索结果。

注意

Microsoft Search API 请求和响应中使用的资源已重命名或删除了属性或者已被弃用。 查找有关过时的更多详细信息。 相应更新任何早期应用中的搜索 API 查询。

权限

要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限

权限类型 权限(从最低特权到最高特权)
委派(工作或学校帐户) Mail.Read、Calendars.Read、Files.Read.All、Sites.Read.All、ExternalItem.Read.All
委派(个人 Microsoft 帐户) 不支持。
应用程序 不支持。

HTTP 请求

POST /search/query

请求标头

名称 说明
Authorization Bearer {token}。必需。
Content-type application/json. Required.

请求正文

在请求正文中,提供具有以下参数的 JSON 对象。

参数 类型 说明
requests searchRequest 集合 一个或多个搜索请求的集合,每个搜索请求的格式都为 JSON blob。 每个 JSON blob 都包含响应中预期的资源类型、基础源、分页参数、请求的字段和实际搜索查询。
请注意搜索 实体 类型的特定组合以及排序或聚合搜索结果的已知限制。

响应

如果成功,此方法在响应 HTTP 200 OK 正文中返回 响应代码和 searchResponse 对象集合。

示例

请求

下面展示了示例请求。

POST https://graph.microsoft.com/beta/search/query
Content-type: application/json

{
  "requests": [
    {
      "entityTypes": [
        "externalItem"
      ],
      "contentSources": [
        "/external/connections/connectionfriendlyname"
      ],
      "query": {
        "queryString": "contoso product"
      },
      "from": 0,
      "size": 25,
      "fields": [
        "title",
        "description"
      ]
    }
  ]
}

响应

下面展示了示例响应。

注意: 为了提高可读性,可能缩短了此处显示的响应对象。

HTTP/1.1 200 OK
Content-type: application/json

{
  "value": [
    {
      "searchTerms": [
        "searchTerms-value"
      ],
      "hitsContainers": [
        {
          "hits": [
            {
              "hitId": "1",
              "rank": 1,
              "summary": "_summary-value",
              "resource": "The source field will contain the underlying graph entity part of the response"
            }
          ],
          "total": 47,
          "moreResultsAvailable": true
        }
      ]
    }
  ]
}

另请参阅