From c3cacd148c7d0b235c0ee17e826c29e272be2b0b Mon Sep 17 00:00:00 2001 From: Martin Gaievski Date: Thu, 19 Dec 2024 13:57:44 -0800 Subject: [PATCH] Use max_window_size as max for pagination depth Signed-off-by: Martin Gaievski --- .../neuralsearch/query/HybridQueryBuilder.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/opensearch/neuralsearch/query/HybridQueryBuilder.java b/src/main/java/org/opensearch/neuralsearch/query/HybridQueryBuilder.java index 0b52b90e6..c6123c8bf 100644 --- a/src/main/java/org/opensearch/neuralsearch/query/HybridQueryBuilder.java +++ b/src/main/java/org/opensearch/neuralsearch/query/HybridQueryBuilder.java @@ -59,7 +59,6 @@ public final class HybridQueryBuilder extends AbstractQueryBuilder toQueries(Collection queryBuilders, Quer return queries; } - private static void validatePaginationDepth(Integer paginationDepth) { - if (paginationDepth != null - && (paginationDepth < LOWER_BOUND_OF_PAGINATION_DEPTH || paginationDepth > UPPER_BOUND_OF_PAGINATION_DEPTH)) { + private static void validatePaginationDepth(Integer paginationDepth, QueryShardContext queryShardContext) { + if (Objects.isNull(paginationDepth)) { + return; + } + // compare pagination depth with OpenSearch setting index.max_result_window + // see https://opensearch.org/docs/latest/install-and-configure/configuring-opensearch/index-settings/ + int maxResultWindowIndexSetting = queryShardContext.getIndexSettings().getMaxResultWindow(); + if (paginationDepth < LOWER_BOUND_OF_PAGINATION_DEPTH || paginationDepth > maxResultWindowIndexSetting) { throw new IllegalArgumentException( String.format(Locale.ROOT, "Pagination depth should lie in the range of 1-1000. Received: %s", paginationDepth) );