Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination in Hybrid query #1048

Merged
merged 19 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private static void validatePaginationDepth(final int paginationDepth, final Que
int maxResultWindowIndexSetting = queryShardContext.getIndexSettings().getMaxResultWindow();
if (paginationDepth > maxResultWindowIndexSetting) {
throw new IllegalArgumentException(
String.format(Locale.ROOT, "pagination_depth should be less than index.max_result_window setting")
String.format(Locale.ROOT, "pagination_depth should be less than or equal to index.max_result_window setting")
vibrantvarun marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class HybridQueryUtil {

/**
* This method validates whether the query object is an instance of hybrid query
*/
public static boolean isHybridQuery(final Query query, final SearchContext searchContext) {
if (query instanceof HybridQuery) {
return true;
Expand Down Expand Up @@ -52,19 +55,22 @@ public static boolean isHybridQuery(final Query query, final SearchContext searc
return false;
}

public static boolean hasNestedFieldOrNestedDocs(final Query query, final SearchContext searchContext) {
private static boolean hasNestedFieldOrNestedDocs(final Query query, final SearchContext searchContext) {
return searchContext.mapperService().hasNested() && new NestedHelper(searchContext.mapperService()).mightMatchNestedDocs(query);
}

public static boolean isWrappedHybridQuery(final Query query) {
private static boolean isWrappedHybridQuery(final Query query) {
return query instanceof BooleanQuery
&& ((BooleanQuery) query).clauses().stream().anyMatch(clauseQuery -> clauseQuery.getQuery() instanceof HybridQuery);
}

public static boolean hasAliasFilter(final Query query, final SearchContext searchContext) {
private static boolean hasAliasFilter(final Query query, final SearchContext searchContext) {
return Objects.nonNull(searchContext.aliasFilter());
}

/**
* This method checks whether hybrid query is wrapped under boolean query object
*/
public static boolean isHybridQueryWrappedInBooleanQuery(final SearchContext searchContext, final Query query) {
martin-gaievski marked this conversation as resolved.
Show resolved Hide resolved
return ((hasAliasFilter(query, searchContext) || hasNestedFieldOrNestedDocs(query, searchContext))
&& isWrappedHybridQuery(query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ public void testDoToQuery_whenPaginationDepthIsGreaterThan10000_thenBuildSuccess
IllegalArgumentException.class,
() -> queryBuilder.doToQuery(mockQueryShardContext)
);
assertThat(exception.getMessage(), containsString("pagination_depth should be less than index.max_result_window setting"));
assertThat(
exception.getMessage(),
containsString("pagination_depth should be less than or equal to index.max_result_window setting")
);
}

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ public void testHybridQuery_whenPaginationDepthIsOutOfRange_thenFail() {

org.hamcrest.MatcherAssert.assertThat(
responseException.getMessage(),
allOf(containsString("pagination_depth should be less than index.max_result_window setting"))
allOf(containsString("pagination_depth should be less than or equal to index.max_result_window setting"))
);
} finally {
wipeOfTestResources(TEST_MULTI_DOC_INDEX_NAME_ONE_SHARD, null, null, SEARCH_PIPELINE);
Expand Down
Loading