如何阻止Elastic Search返回_ignored字段以缩减响应体积?
移除Elastic App Search响应中的_ignored字段
有两种可行的方法可以阻止_ignored区域出现在搜索响应中:
方法一:通过response_fields指定返回字段
在搜索请求的请求体中,使用response_fields参数明确列出你需要返回的字段(包括业务字段和必要的元字段,比如id),这样App Search只会返回你指定的内容,_ignored这类未被指定的元字段会被自动排除。
示例请求体:
{ "query": "搜索关键词", "response_fields": ["title", "content", "id"] }
方法二:使用filter_path过滤响应字段
在搜索请求的URL中添加filter_path参数,直接排除_ignored字段。你可以用-前缀来指定要排除的字段,同时保留其他默认返回内容:
示例请求URL:POST /api/as/v1/engines/your-engine-name/search?filter_path=-hits.hits._ignored
如果需要同时排除多个字段,用逗号分隔即可:POST /api/as/v1/engines/your-engine-name/search?filter_path=-hits.hits._ignored,-hits.hits.some-other-unwanted-field
内容的提问来源于stack exchange,提问作者Luke
相关产品推荐
相关产品推荐

