Vespa中导入字段作为文档摘要不生效问题排查
Vespa父子文档导入字段无法在搜索结果中显示的解决方案
问题描述
测试Vespa父子文档特性时,子Schema item 通过reference字段关联父Schema campaign,并导入父字段campaign_ref.cpc为campaign_cpc、campaign_ref.syndicator_id为syndicator_id。过滤查询(syndicator_id = 1)能正常匹配到子文档,但搜索响应的fields中没有syndicator_id字段——即便已经在子Schema的document-summary中添加了该字段作为摘要。
子Schema代码:
schema item { document item { field id type long { indexing : attribute } field campaign_ref type reference<campaign> { indexing: attribute } } import field campaign_ref.cpc as campaign_cpc {} import field campaign_ref.syndicator_id as syndicator_id {} document-summary item_summary { summary syndicator_id type long {} } }
父Schema代码:
schema campaign { document campaign { field id type long { indexing : attribute } field cpc type float { indexing : attribute } field syndicator_id type long { indexing : attribute } } }
搜索响应片段:
"children": [ { "id": "id:candidation:item::2", "relevance": 0.0017429193899782135, "source": "vespa2", "fields": { "sddocname": "item", "documentid": "id:candidation:item::2" } } ]
解决方案
问题核心是导入字段的摘要属性未正确配置,可通过以下步骤修复:
1. 给导入字段添加摘要索引配置
导入父字段时,需显式指定该字段同时作为属性和摘要字段,否则Vespa不会自动将父字段数据填充到子文档的摘要中。修改子Schema的导入字段部分:
import field campaign_ref.cpc as campaign_cpc { indexing: attribute | summary } import field campaign_ref.syndicator_id as syndicator_id { indexing: attribute | summary }
2. 确保查询触发摘要字段返回
有两种方式确保字段被返回:
- 方式一:在YQL中明确指定返回字段
修改查询语句,直接列出需要返回的字段:{"yql" : "select syndicator_id, campaign_cpc, id from item where syndicator_id = 1 limit 3" } - 方式二:设置自定义摘要模板为默认
在子Schema的document-summary中添加default关键字,让Vespa默认使用该模板返回字段:document-summary item_summary { default summary syndicator_id type long {} summary campaign_cpc type float {} summary id type long {} }
3. 验证父字段索引配置
确认父Schema中被导入的字段(cpc、syndicator_id)已配置为attribute类型(你的代码中已满足此要求,无需修改)——只有父字段是attribute类型,子Schema才能通过reference导入并使用。
原理说明
Vespa中通过reference导入的父字段,默认仅配置为attribute(用于过滤、排序场景),不会自动加入摘要数据集。必须在导入时显式声明indexing: attribute | summary,同时确保查询时正确触发摘要字段的返回逻辑,才能在搜索结果中看到导入的字段。
内容的提问来源于stack exchange,提问作者S.Glick
相关产品推荐
相关产品推荐

