Skip to content

Commit

Permalink
Clean up adjustSearchType method (elastic#96334)
Browse files Browse the repository at this point in the history
This moves the knn check for adjusting search type to the top of the method instead of possibly 
adjusting the search type multiple times. Purely mechanical change for readability.
  • Loading branch information
jdconrad authored May 25, 2023
1 parent 2a49ad9 commit 8b83636
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,21 +403,23 @@ void executeRequest(
}

static void adjustSearchType(SearchRequest searchRequest, boolean singleShard) {
// optimize search type for cases where there is only one shard group to search on
if (singleShard) {
// if we only have one group, then we always want Q_T_F, no need for DFS, and no need to do THEN since we hit one shard
searchRequest.searchType(QUERY_THEN_FETCH);
// if there's a kNN search, always use DFS_QUERY_THEN_FETCH
if (searchRequest.hasKnnSearch()) {
searchRequest.searchType(DFS_QUERY_THEN_FETCH);
return;
}

// if there's only suggest, disable request cache and always use QUERY_THEN_FETCH
if (searchRequest.isSuggestOnly()) {
searchRequest.requestCache(false);
searchRequest.searchType(QUERY_THEN_FETCH);
return;
}

// if there's a kNN search, always use DFS_QUERY_THEN_FETCH
if (searchRequest.hasKnnSearch()) {
searchRequest.searchType(DFS_QUERY_THEN_FETCH);
// optimize search type for cases where there is only one shard group to search on
if (singleShard) {
// if we only have one group, then we always want Q_T_F, no need for DFS, and no need to do THEN since we hit one shard
searchRequest.searchType(QUERY_THEN_FETCH);
}
}

Expand Down

0 comments on commit 8b83636

Please sign in to comment.