在知识图谱中搜索符合限制条件的实体。
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 关键字
对于 @context、@vocab、@type 或 @id 等 JSON-LD 关键字,请参阅 JSON-LD 规范。
Schema.org 兼容性
响应使用托管在 schema.org 的词汇,并包含与 schema.org 词汇兼容的有限扩展(例如 resultScore)。如需详细了解这些扩展,请参阅架构扩展列表。
对于每种 Schema.org 类型(例如 Person)和属性(例如 name),都有一个对应的完整 URI,如以下示例所示:
- Person -> http://schema.org/Person
Thing -> http://schema.org/Thing
name -> http://schema.org/name
description -> http://schema.org/description
定义为 Google 架构扩展的类型和属性可以使用 http://schema.googleapis.com 进行扩展。例如,
- EntitySearchResult -> http://schema.googleapis.com/EntitySearchResult
- detailedDescription -> http://schema.googleapis.com/detailedDescription
每种类型和属性的文档都可在相应的 URI 中找到。
架构扩展列表
此 API 中使用的架构扩展位于 http://schema.googleapis.com,属于外部扩展。
Schema.org 的类型扩展是:
Schema.org 的属性扩展如下: