Skip to content

DATAES-988 Allow specifying max results in NativeSearchQueryBuilder #561

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

Merged
merged 1 commit into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -66,6 +66,7 @@ public class NativeSearchQueryBuilder {
@Nullable private SearchType searchType;
@Nullable private IndicesOptions indicesOptions;
@Nullable private String preference;
@Nullable private Integer maxResults;

public NativeSearchQueryBuilder withQuery(QueryBuilder queryBuilder) {
this.queryBuilder = queryBuilder;
Expand Down Expand Up @@ -167,6 +168,11 @@ public NativeSearchQueryBuilder withPreference(String preference) {
return this;
}

public NativeSearchQueryBuilder withMaxResults(Integer maxResults) {
this.maxResults = maxResults;
return this;
}

public NativeSearchQuery build() {

NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(queryBuilder, filterBuilder, sortBuilders,
Expand Down Expand Up @@ -218,10 +224,15 @@ public NativeSearchQuery build() {
if (indicesOptions != null) {
nativeSearchQuery.setIndicesOptions(indicesOptions);
}

if (preference != null) {
nativeSearchQuery.setPreference(preference);
}

if (maxResults != null) {
nativeSearchQuery.setMaxResults(maxResults);
}

return nativeSearchQuery;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public void shouldReturnAggregatedResponseForGivenSearchQuery() {
.withQuery(matchAllQuery()) //
.withSearchType(SearchType.DEFAULT) //
.addAggregation(terms("subjects").field("subject")) //
.withMaxResults(0) //
.build();
// when
SearchHits<ArticleEntity> searchHits = operations.search(searchQuery, ArticleEntity.class,
Expand All @@ -127,6 +128,7 @@ public void shouldReturnAggregatedResponseForGivenSearchQuery() {
// then
assertThat(aggregations).isNotNull();
assertThat(aggregations.asMap().get("subjects")).isNotNull();
assertThat(searchHits.hasSearchHits()).isFalse();
}

/**
Expand Down