批量 Feed 中的 v1 版本控制

在批量 Feed 中,实体的版本通过 Feed 信封中的 dateModified 字段确定:

{
  "@context": "http://schema.googleapis.com",
  "dateModified": "2018-12-28T06:30:00:123-07:00",
  "@type": "DataFeed",
  "dataFeedElement": [
    /* All the items that are part of this feed go here */
  ]
}

dataFeedElement 字段中列出的所有实体都将与信封中列出的时间戳相同。

例如,您可以将以下 Feed 与两个实体相关联:

{
  "@context": "http://schema.googleapis.com",
  "@type": "DataFeed",
  "dateModified": "2018-12-28T06:30:00:123-07:00",
  "dataFeedElement": [
    {
      "@type": "Restaurant",
      "@id": "http://www.provider.com/somerestaurant",
      ...
    },
    {
      "@type": "Menu",
      "@id": "http://www.provider.com/somerestaurant/menu/1"
      ...
    }
  ]
}

在接收和处理后,菜单实体和餐馆实体都会分别的版本为“2018-12-28T06:30:00:123-07:00”。

通过增量更新进行版本控制

使用商品目录更新发送实体时,版本通过 update_time 字段(如果是添加/更新调用)或 delete_time 字段(如果是删除调用)进行设置。由于这些字段是可选的,因此默认时间戳设置为 Google 收到调用的时间。

示例 1:明确设置 update_time

假设在 2018-12-28T06:30:10:123-07:00,一家全新的餐厅收到以下增量调用。ID 为“http://www.provider.com/somerestaurant”的实体的 HTTP POST 请求(假设数据 Feed 使用 v1 商品目录架构):

POST v2/apps/provider-project/entities/http%3A%2F%2Fwww.provider.com%2Fnewrestaurant:push
Host: actions.googleapis.com
Content-Type: application/ld+json

下面的 JSON 载荷正文包含 update_time 字段。如果实体 ID 为“http://www.provider.com/somerestaurant”,则会导致此实体的版本号被更新为 6:30:00,而不是其被收到的时间(十秒后 6:30:10):

{
// This envelope is to be used for incremental.
  "entity": {
    // Note: "data" is not serialized as a string in our example for readability.
    "data": "[entity in JSON format serialized as a string]",
    "vertical": "FOODORDERING"
  },
  "update_time":"2018-12-28T06:30:00:123-07:00"
}

示例 2:隐式设置 update_time

假设在 2018-12-28T06:30:10:123-07:00,一家全新的餐厅收到以下增量调用。该 ID 为“http://www.provider.com/somerestaurant”的实体的 HTTP POST 请求(假设 Feed 使用 v1 广告资源架构):

POST v2/apps/provider-project/entities/http%3A%2F%2Fwww.provider.com%2Fnewrestaurant:push
Host: actions.googleapis.com
Content-Type: application/ld+json

下方,JSON 载荷正文包含字段 update_time。因此,ID 为“http://www.provider.com/somerestaurant”的实体会导致版本为 6:30:10:

{
// This envelope is to be used for incremental.
  "entity": {
    //Note: "data" is not serialized as a string in our example for readability.
    "data": "[entity in JSON format serialized as a string]",
    "vertical": "FOODORDERING"
  }
}

批量和增量之间的版本控制

发送到 Google 的实体仅在具有最新版本时才会进行处理和提供。请注意,通过批量发送的实体通常需要几天时间进行处理,而通过增量 API 发送的实体会立即得到处理。

最佳做法

  • 分别根据您在系统中修改实体的时间,以增量方式和批量方式设置 update_timedateModified 字段。
  • 如果批量 Feed(文件)列出多个顶级实体(例如,将餐馆与服务和菜单配对),则随着实体的数据更新,更新时间戳。
  • 在增量调用中,我们强烈建议您明确设置 update_time 字段。
  • 进行增量调用后,还必须在 Google 再次提取相应 Feed 时间戳 (dateModified) 之前进行更新。

示例

Google 于 2018 年 12 月 28 日上午 11 点提取了以下文件,以为某家餐馆开设了全新的餐厅:

{
  "@context": "http://schema.googleapis.com",
  "@type": "DataFeed",
  "dateModified": "2018-12-28T06:30:00-07:00",
  "dataFeedElement": [
    {
      "@type": "Restaurant",
      "@id": "http://www.provider.com/newrestaurant",
      ...
    },
    {
      "@type": "Menu",
      "@id": "http://www.provider.com/newrestaurant/menu/1"
      ...
    }
    {
      "@type": "Service",
      "@id": "http://www.provider.com/newrestaurant/service/1"
      ...
    }
  ]
}

这些实体会得到成功处理,版本为“2018-12-28T06:30:00-07:00”。由于批量 Feed 需要一些时间进行处理,因此这些 Feed 通常会在 2 天后投放。

但是,在下午 1 点,合作伙伴更新了餐厅的电话号码,导致以下增量调用,Google 会在 13:05(5 秒后)收到该调用:

POST v2/apps/provider-project/entities/http%3A%2F%2Fwww.provider.com%2Fnewrestaurant:push
Host: actions.googleapis.com
Content-Type: application/ld+json
{
// This envelope is to be used for incremental.
  "entity": {
    //Note: "data" is not serialized as a string in our example for readability.
    "data": "[entity in JSON format serialized as a string]",
    "vertical": "FOODORDERING"
  },
  "update_time":"2018-12-28T13:00:00-07:00"
}

update_time 是显式提供的,并且比上一个版本更大(同一天早上 6:30),因此该餐馆实体现在的版本为“2018-12-28T13:00:00-07:00”。不过,菜单和服务实体版本仍为“2018-12-28T06:30:00-07:00”。

由于存在增量调用,因此批量 Feed 会使用新的相应时间戳进行更新。此外,相应更改会应用到相关实体(餐馆实体的电话号码已更新)。

{
  "@context": "http://schema.googleapis.com",
  "@type": "DataFeed",
  "dateModified": "2018-12-28T13:00:00-07:00",
  "dataFeedElement": [
    {
      "@type": "Restaurant",
      "@id": "http://www.provider.com/newrestaurant",
      ...
    },
    {
      "@type": "Menu",
      "@id": "http://www.provider.com/newrestaurant/menu/1"
      ...
    }
    {
      "@type": "Service",
      "@id": "http://www.provider.com/newrestaurant/service/1"
      ...
    }
  ]
}

第二天(2018 年 12 月 29 日)晚上 11 点,系统会再次提取 Feed。餐馆仍然具有相同的版本(12 月 28 日下午 1 点),因此该实体将被丢弃,而当前版本保持不变。不过,Menu 和 Service 实体会更新为新版本。

站点地图时间戳

站点地图中的 last-modified 响应标头不会影响实体版本。它会影响 Google 提取 Feed 的时间。

最佳做法

  • 仅在所有文件均为最新且已准备好提取时更新响应标头。
  • 以显式方式使用 update_timedelete_time
  • update_timedelete_timedateModified 设置为数据端的更改。