--- title: "Slice 仅可用于 scroll 或 point-in-time 请求 – 如何解决此 Elasticsearch 异常" date: 2026-01-21 lastmod: 2026-01-21 description: "当在 Elasticsearch 中使用 'slice' 参数但没有配合 'scroll' 或 'point-in-time' 请求时会出现此错误。本文介绍如何解决该异常。" tags: ["Elasticsearch异常", "slice参数", "scroll请求", "point-in-time", "搜索错误"] summary: "版本: 7.15-8.9 简而言之,当在 Elasticsearch 中使用了 ‘slice’ 参数但没有配合 ‘scroll’ 或 ‘point-in-time’ 请求时,就会发生此错误。‘slice’ 参数用于将搜索请求的结果拆分为多个切片或部分。然而,它只能与 ‘scroll’ 或 ‘point-in-time’ 请求一起使用。要解决此问题,你应该从请求中删除 ‘slice’ 参数,或者在搜索查询中包含 ‘scroll’ 或 ‘point-in-time’ 请求。 日志上下文 # 日志 “[slice] can only be used with [scroll] or [point-in-time] requests” 的类名是 SearchService.java. 我们从 Elasticsearch 源代码中提取了以下内容,供那些需要深入理解上下文的人参考: context.searchAfter(fieldDoc); } if (source.slice() != null) { if (source.pointInTimeBuilder() == null && context.scrollContext() == null) { throw new SearchException(shardTarget; "[slice] can only be used with [scroll] or [point-in-time] requests"); } context." --- > **版本:** 7.15-8.9 简而言之,当在 Elasticsearch 中使用了 'slice' 参数但没有配合 'scroll' 或 'point-in-time' 请求时,就会发生此错误。'slice' 参数用于将搜索请求的结果拆分为多个切片或部分。然而,它只能与 'scroll' 或 'point-in-time' 请求一起使用。要解决此问题,你应该从请求中删除 'slice' 参数,或者在搜索查询中包含 'scroll' 或 'point-in-time' 请求。 日志上下文 ----------- 日志 "[slice] can only be used with [scroll] or [point-in-time] requests" 的类名是 [SearchService.java.](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从 Elasticsearch 源代码中提取了以下内容,供那些需要深入理解上下文的人参考: ```java context.searchAfter(fieldDoc); } if (source.slice() != null) { if (source.pointInTimeBuilder() == null && context.scrollContext() == null) { throw new SearchException(shardTarget; "[slice] can only be used with [scroll] or [point-in-time] requests"); } context.sliceBuilder(source.slice()); } if (source.storedFields() != null) { ```