使用 Microsoft Graph 中的Microsoft搜索 API 在以前Microsoft Graph 连接器 智能 Microsoft 365 Copilot 副驾驶®) (引入和索引的外部内容之间进行搜索。 通过 Microsoft 提供的 内置连接器 或通过使用 Copilot 连接器引入 API 实现的自定义连接器导入内容。
警告
测试版中的搜索 API 架构已更改。 搜索请求和响应中的某些属性已重命名或删除。 有关详细信息,请参阅 架构更改弃用警告。 本主题中的示例显示了最新的架构。
导入内容并编制索引后,可以使用搜索 API 查询内容。
若要搜索自定义类型,请在 查询 方法的请求正文中指定以下属性:
- contentSources 属性,包括连接器设置期间分配的连接 ID。 可以传递多个连接 ID 以跨多个连接进行搜索。 结果在单个列表中返回,在多个连接中排名。
entityTypes 属性作为
externalItem
。要包括外部项中要检索的字段的 fields 属性。 请注意,如果请求中不包含任何字段,响应将包含所有标记为可在 contentSources 属性中为指定连接的数据架构中可检索的字段。
此外,可以根据 externalItem 中的属性聚合搜索结果,这些属性属于数字或字符串类型,并且设置为在 架构中可细化。 有关详细信息,请参阅 使用聚合优化搜索结果。
示例 1:使用Azure SQL内置连接器检索项
在此示例中,AdventureWorks 数据库的内容已使用 Azure SQL 内置连接器引入。
请求
POST https://graph.microsoft.com/v1.0/search/query
Content-Type: application/json
{
"requests": [
{
"entityTypes": [
"externalItem"
],
"contentSources": [
"/external/connections/azuresqlconnector",
"/external/connections/azuresqlconnector2"
],
"query": {
"queryString": "yang"
},
"from": 0,
"size": 25,
"fields": [
"BusinessEntityID",
"firstName",
"lastName"
]
}
]
}
响应
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)",
"value": [
{
"searchTerms": ["yang"],
"hitsContainers": [
{
"total": 2,
"moreResultsAvailable": false,
"hits": [
{
"hitId": "AAMkADc0NDNlNTE0",
"rank": 1,
"summary": "<ddd/>",
"contentSource": "/external/connections/azuresqlconnector",
"resource": {
"@odata.type": "#microsoft.graph.externalConnectors.externalItem",
"properties": {
"businessEntityID": 20704,
"firstName": "Amy",
"lastName": "Yang"
}
}
},
{
"hitId": "AQMkADg3M2I3YWMyLTEwZ",
"rank": 2,
"summary": "<ddd/>",
"contentSource": "/external/connections/azuresqlconnector2",
"resource": {
"@odata.type": "#microsoft.graph.externalConnectors.externalItem",
"properties": {
"businessEntityID": 20704,
"shortDescription": "Contoso maintenance guidelines",
"firstName": "Amy",
"lastName": "Yang"
}
}
},
]
}
]
}
]
}
示例 2:使用语义标签检索项
请求
POST https://graph.microsoft.com/v1.0/search/query
Content-Type: application/json
{
"requests": [
{
"entityTypes": [
"microsoft.graph.externalItem"
],
"contentSources": [
"/external/connections/FileAsUdt"
],
"query": {
"query_string": {
"query": "test"
}
},
"stored_fields": [
"label_Title",
"label_URL",
"label_LastModifiedBy",
"label_LastModifiedDateTime"
],
"from": 0,
"size": 25
}
]
}
响应
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)",
"value": [
{
"searchTerms": [
"test"
],
"hitsContainers": [
{
"hits": [
{
"_id": "AQMkAGRjZWJjZTFkLTkzYWItNDhlOC1iODA2LTgwMTNjNjEzYzI2YwBGAAADOx0/YV2JckefuDmJtUO7mwcAHNjGq33S50uXSFeU/U9mogAAAgEWAAAAHNjGq33S50uXSFeU/U9mogAAAgleAAAA",
"_contentSource": "FileAsUdt",
"_score": 1,
"_summary": "<c0>Test</c0> component to move data files and messages between the gateway and internal <ddd/>",
"_source": {
"@odata.type": "#microsoft.graph.externalConnectors.externalItem",
"properties": {
"label_Title": "SONIC Operations support and test Guide for the month of March",
"label_URL": "D:\\\\ConnectorsEcho\\\\New\\\\MSW06SecondSet\\\\teams\\\\Enterprise_Platforms\\\\CCO\\\\Projects\\\\BTSi Modernization\\\\SONIC Retirement\\\\SONIC_Operations_Support_Guide.docx",
"label_LastModifiedBy": [
"Bob",
"Scott"
],
"label_LastModifiedDateTime": "2020-01-30T12:44:19Z"
}
}
},
{
"_id": "AQMkAGRjZWJjZTFkLTkzYWItNDhlOC1iODA2LTgwMTNjNjEzYzI2YwBGAAADOx0/YV2JckefuDmJtUO7mwcAHNjGq33S50uXSFeU/U9mogAAAgEWAAAAHNjGq33S50uXSFeU/U9mogAAAgldAAAA",
"_contentSource": "FileAsUdt",
"_score": 2,
"_summary": "File Transfer Workbench A <c0>test</c0> File transfer Management Solution File Transfer the number <ddd/>",
"_source": {
"@odata.type": "#microsoft.graph.externalConnectors.externalItem",
"properties": {
"label_Title": "Test File Transfer Workbench for the month of January",
"label_URL": "D:\\\\ConnectorsEcho\\\\New\\\\MSW06SecondSet\\\\teams\\\\IssueLog\\\\FCAGA Organisation\\\\NSN CO CCA Infra YBCFTPAR entry\\\\File Transfer Workbench.ppt",
"label_LastModifiedBy": [
"Alice",
"Scott"
],
"label_LastModifiedDateTime": "2020-01-31T11:44:19Z"
}
}
},
{
"_id": "AQMkAGRjZWJjZTFkLTkzYWItNDhlOC1iODA2LTgwMTNjNjEzYzI2YwBGAAADOx0/YV2JckefuDmJtUO7mwcAHNjGq33S50uXSFeU/U9mogAAAgEWAAAAHNjGq33S50uXSFeU/U9mogAAAglgAAAA",
"_contentSource": "FileAsUdt",
"_score": 3,
"_summary": "document and the associated <c0>test</c0> software are the sole property of Express Logic.<ddd/>",
"_source": {
"@odata.type": "#microsoft.graph.externalConnectors.externalItem",
"properties": {
"label_Title": "System User Guide Express Logic 858.613.6640",
"label_URL": "D:\\\\ConnectorsEcho\\\\New\\\\MSW06FirstSet\\\\teams\\\\AzureIoTMarketing\\\\Shared Documents\\\\Whitepapers\\\\RTOS Whitepapers\\\\User Guides\\\\Azure_RTOS_FileX_User_Guide.pdf",
"label_LastModifiedBy": [
"Alice",
"Bob"
],
"label_LastModifiedDateTime": "2020-05-25T10:20:19Z"
}
}
}
],
"total": 3,
"moreResultsAvailable": false
}
]
}
]
}
有关详细信息,请参阅 分配属性标签。