在知识图谱中搜索符合限制条件的实体。
HTTP 请求
GET https://kgsearch.googleapis.com/v1/entities:search
查询参数
参数名称 | 类型 | 说明 |
---|---|---|
query |
string |
要在知识图谱中搜索的文字字符串。 |
ids |
string |
要在知识图谱中搜索的实体 ID 列表。如需在 HTTP 请求中指定多个 ID,请重复网址中的参数,例如 ...?ids=A&ids=B |
languages |
string |
运行查询时使用的语言代码(在 ISO 639 中定义)列表,例如“en”。 |
types |
string |
将返回的实体限制为指定类型的实体。例如,您可以指定“Person”(如 http://schema.org/Person 中所定义),将结果限制为代表人物的实体。如果指定了多种类型,返回的实体将包含一个或多个这些类型。 |
indent |
boolean |
启用 JSON 结果缩进。 |
prefix |
boolean |
启用针对实体的名称和别名的前缀(初始子字符串)匹配。例如,前缀“Jung”将匹配实体和别名,例如“Jung”“Jungle”和“Jung-ho Kang”。 |
limit |
number |
限制要返回的实体数量。最大值为 500。默认值为 20。 上限较高的请求出现超时的可能性较高。 |
请求正文
请求正文必须为空。
响应正文
响应消息包含实体列表,以 JSON-LD 格式呈现,且与 schema.org 架构兼容(具有有限的外部扩展)。
以下 JSON-LD 示例展示了响应正文的结构:
{
"@context": {
"@vocab": "http://schema.org/",
"goog": "http://schema.googleapis.com/",
"resultScore": "goog:resultScore",
"detailedDescription": "goog:detailedDescription",
"EntitySearchResult": "goog:EntitySearchResult",
"kg": "http://g.co/kg"
},
"@type": "ItemList",
"itemListElement": [
{
"@type": "EntitySearchResult",
"result": {
"@id": "kg:/m/0dl567",
"name": "Taylor Swift",
"@type": [
"Thing",
"Person"
],
"description": "Singer-songwriter",
"image": {
"contentUrl": "https://t1.gstatic.com/images?q=tbn:ANd9GcQmVDAhjhWnN2OWys2ZMO3PGAhupp5tN2LwF_BJmiHgi19hf8Ku",
"url": "https://en.wikipedia.org/wiki/Taylor_Swift",
"license": "http://creativecommons.org/licenses/by-sa/2.0"
},
"detailedDescription": {
"articleBody": "Taylor Alison Swift is an American singer-songwriter and actress. Raised in Wyomissing, Pennsylvania, she moved to Nashville, Tennessee, at the age of 14 to pursue a career in country music. ",
"url": "http://en.wikipedia.org/wiki/Taylor_Swift",
"license": "https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License"
},
"url": "http://taylorswift.com/"
},
"resultScore": 4850
}
]
}
响应字段
字段名称 | 类型 | 说明 |
---|---|---|
@id |
string |
实体的规范 URI。 |
name |
string |
实体的名称。 |
@type |
array |
与实体匹配的受支持 schema.org 类型的列表。 |
description |
string |
实体的简短说明。 |
image |
URL |
有助于识别实体的图片。 |
detailedDescription |
string |
实体的详细说明。 |
url |
URL |
实体的官方网站网址(如果有)。 |
resultScore |
number |
指示实体与请求限制条件的匹配程度。 |
JSON-LD 关键字
对于 JSON-LD 关键字(例如 @context、@vocab、@type 或 @id),请参阅 JSON-LD 规范。
Schema.org 兼容性
响应使用 schema.org 上托管的词汇,具有与 schema.org 词汇兼容的有限扩展(例如 resultScore
)。如需详细了解这些扩展,请参阅架构扩展列表。
对于每种 Schema.org 类型(例如 Person
)和属性(例如 name
),都有一个对应的完整 URI,如以下示例所示:
- 人员 -> http://schema.org/Person
事物 -> http://schema.org/Thing
name -> http://schema.org/name
说明 -> http://schema.org/description
定义为 Google 架构扩展的类型和属性可以使用 http://schema.googleapis.com 进行扩展。例如,
- EntitySearchResult -> http://schema.googleapis.com/EntitySearchResult
- detailsDescription -> http://schema.googleapis.com/detailedDescription
每种类型和属性的文档位于相应的 URI。
架构扩展列表
此 API 中使用的架构扩展项作为外部扩展托管在 http://schema.googleapis.com 上。
Schema.org 的 type 扩展项为:
Schema.org 的 property 扩展项: