使用Google的数据目录进行搜索时,需要scope
参数,其中一个字段为includeProjectIds
。根据文件,该参数表示:
要在其中搜索的项目ID的列表。
但是,返回的结果并不局限于该项目ID。我对参数的理解有误吗?我可以在查询中使用projectid=myproject
来限制结果,但我正在尝试理解includeProjectIds
字段。
示例请求主体:
{
"scope": {
"includeProjectIds": [
"MY-PROJECT"
]
},
"query": "type=dataset"
}
示例响应:
{
"results": [
# I expect this result:
{
"searchResultType": "ENTRY",
"searchResultSubtype": "entry.dataset",
"relativeResourceName": "projects/MY-PROJECT/locations/us/entryGroups/@bigquery/entries/....",
"linkedResource": "//bigquery.googleapis.com/projects/MY-PROJECT/datasets/dataset_name",
"modifyTime": "2000-01-01T00:00:00Z",
"integratedSystem": "BIGQUERY",
"description": "My description"
},
# But I don't expect this:
{
"searchResultType": "ENTRY",
"searchResultSubtype": "entry.dataset",
"relativeResourceName": "projects/NOT-MY-PROJECT/locations/us/entryGroups/@bigquery/entries/....",
"linkedResource": "//bigquery.googleapis.com/projects/NOT-MY-PROJECT/datasets/dataset_name",
"modifyTime": "2000-01-01T00:00:00Z",
"integratedSystem": "BIGQUERY",
"description": "My description"
},
...
]
}
您可以尝试使用curl方法,因为它使用服务帐户的服务帐户密钥。有关服务帐户和密钥的创建,您可以参考此文档。我尝试了一下,结果中只显示了我的项目数据集,结果是正确的。
命令:
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token)
-H "Content-Type: application/json; charset=utf-8"
-d @request.json
"https://datacatalog.googleapis.com/v1/catalog:search"
内部请求.json:
{
"scope": {
"includeProjectIds": [
"my-project"
]
},
"query": "type=dataset"
}
输出:
a@cloudshell:~ (a)$ curl -X POST
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token)
-H "Content-Type: application/json; charset=utf-8"
-d @request.json
"https://datacatalog.googleapis.com/v1/catalog:search"
{
"results": [
{
"searchResultType": "ENTRY",
"searchResultSubtype": "entry.dataset",
"relativeResourceName": "projects/my-project/locations/us/entryGroups/@bigquery/entries/cHJvamVjdHMvdGlwaC1hbmplbGFiL2RhdGFzZXRzLzIwMjIwMTEx",
"linkedResource": "//bigquery.googleapis.com/projects/my-project/datasets/2",
"modifyTime": "2022-01-11T01:15:11Z",
"integratedSystem": "BIGQUERY"
},
{
"searchResultType": "ENTRY",
"searchResultSubtype": "entry.dataset",
"relativeResourceName": "projects/my-project/locations/us/entryGroups/@bigquery/entries/cHJvamVjdHMvdGlwaC1hbmplbGFiL2RhdGFzZXRzL0dDUFF1aWNrU3RhcnQ",
"linkedResource": "//bigquery.googleapis.com/projects/my-project/datasets/G",
"modifyTime": "2022-01-07T07:54:58Z",
"integratedSystem": "BIGQUERY"
},
{
"searchResultType": "ENTRY",
"searchResultSubtype": "entry.dataset",
"relativeResourceName": "projects/my-project/locations/us-east1/entryGroups/@bigquery/entries/cHJvamVjdHMvdGlwaC1hbmplbGFiL2RhdGFzZXRzLzIwMjExMjI4",
"linkedResource": "//bigquery.googleapis.com/projects/my-project/datasets/20",
"modifyTime": "2021-12-28T02:00:47Z",
"integratedSystem": "BIGQUERY"
},
{
"searchResultType": "ENTRY",
"searchResultSubtype": "entry.dataset",
"relativeResourceName": "projects/my-project/locations/us-central1/entryGroups/@bigquery/entries/cHJvamVjdHMvdGlwaC1hbmplbGFiL2RhdGFzZXRzL2JxbWxfdHV0b3JpYWw",
"linkedResource": "//bigquery.googleapis.com/projects/my-project/datasets/b",
"modifyTime": "2021-12-14T14:58:09Z",
"integratedSystem": "BIGQUERY"
},
{
"searchResultType": "ENTRY",
"searchResultSubtype": "entry.dataset",
"relativeResourceName": "projects/my-project/locations/us-central1/entryGroups/@bigquery/entries/cHJvamVjdHMvdGlwaC1hbmplbGFiL2RhdGFzZXRzL2JhYnluYW1lcw",
"linkedResource": "//bigquery.googleapis.com/projects/my-project/datasets/ba",
"modifyTime": "2021-12-14T14:01:46Z",
"integratedSystem": "BIGQUERY"
}
]
}