新维度说明.md 3.19 KB

国家与客户类型组合维度

interest_aggregation.py 为 essa、essaone 生成两类地域画像索引:

interest:{list_type}:platform:{platform};country_code:{country_code}
interest:{list_type}:platform:{platform};country_code:{country_code};customer_type:{customer_type}

list_type 可以是 hot、cart、new、global。essabuy 当前不会生成这两类组合维度。

当前数据来源

权威来源是 scripts/interest_aggregation.py 中的 SQL 和聚合逻辑:

sensors_events.login_id
  -> buy_account.id
  -> buy_buyer.id
  -> buy_buyer_extend.buyer_id
  -> buy_buyer_extend_option.buyer_extend_id

字段映射:

维度 当前字段 适用平台
country_code buy_buyer.countries essa、essaone
customer_type buy_buyer.sell_channel essa
customer_type buy_buyer_extend_option.code essaone

旧文档曾描述为通过 pub_dict_item 取得国家和客户类型名称,但当前 SQL 没有这些字典关联。调用方必须传索引中真实存在的内部值,不能根据展示名称自行猜测。

尤其要注意:essaone 的 customer_type 当前是扩展字段的 code,它描述的可能是画像属性名,不一定是“普通客户/VIP 客户”这样的业务枚举值。上线使用三维组合前应抽样检查 key 分布和业务含义;如果需要属性值维度,应先明确 buy_buyer_extend_option 的值字段并修改离线 SQL,不能只改在线 key。

产出示例

platform:essa;country_code:US   1001:150.5000,1002:145.2000
platform:essa;country_code:US;customer_type:retail  1001:85.3000,1006:72.1000
platform:essaone;country_code:344;customer_type:is_ka_buyer 2001:123.4000,2002:118.7000

加载后:

interest:hot:platform:essa;country_code:US
interest:hot:platform:essa;country_code:US;customer_type:retail
interest:hot:platform:essaone;country_code:344;customer_type:is_ka_buyer

value 仍是 item_id:score,... 文本,不是 JSON。

查询与回退

三维 key 未命中时依次回退到平台加国家、平台单维度;这些 key 可以独立查询和融合:

interest:hot:platform:essaone;country_code:344;customer_type:is_ka_buyer
interest:hot:platform:essaone;country_code:344
interest:hot:platform:essaone

不要把 essabuy 拼入国家组合,也不要构造单独的 country_code:{value} 或 customer_type:{value},当前生产器不生成这些 key。

数据质量检查

运行离线任务后,至少检查:

cut -f1 output/interest_aggregation_hot_YYYYMMDD.txt \
  | rg '^platform:(essa|essaone);country_code:' \
  | head

cut -f1 output/interest_aggregation_hot_YYYYMMDD.txt \
  | rg ';customer_type:' \
  | sed 's/.*;customer_type://' \
  | sort | uniq -c | sort -nr | head

需要查询线上 Redis 时使用 SCAN,认证信息通过安全环境变量注入:

redis-cli --scan \
  --pattern 'interest:hot:platform:*;country_code:*' \
  | head

监控项包括:有 login ID 的行为占比、国家非空率、平台对应客户字段非空率、每个组合 key 的商品数、异常 customer type 数量、候选实时可售率。

更新日期:2026-08-23。