Skip to content

DATAES-671 - Missing indicesOptions support for scrolling queries #332

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
Oct 16, 2019
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 @@ -977,6 +977,10 @@ private SearchRequest prepareScroll(Query query, long scrollTimeInMillis,
prepareSort(query, searchSourceBuilder, entity);
}

if (query.getIndicesOptions() != null) {
request.indicesOptions(query.getIndicesOptions());
}

if (query instanceof SearchQuery) {
SearchQuery searchQuery = (SearchQuery) query;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,10 @@ private SearchRequestBuilder prepareScroll(Query query, long scrollTimeInMillis,
prepareSort(query, requestBuilder, entity);
}

if (query.getIndicesOptions() != null) {
requestBuilder.setIndicesOptions(query.getIndicesOptions());
}

if (query instanceof SearchQuery) {
SearchQuery searchQuery = (SearchQuery) query;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,44 @@ public <T> T mapSearchHit(SearchHit searchHit, Class<T> type) {
elasticsearchTemplate.clearScroll(scroll.getScrollId());
}

@Test // DATAES-671
public void shouldPassIndicesOptionsForGivenSearchScrollQuery() {

// given
long scrollTimeInMillis = 3000;
String documentId = randomNumeric(5);
SampleEntity sampleEntity = SampleEntity.builder().id(documentId).message("some message")
.version(System.currentTimeMillis()).build();

IndexQuery idxQuery = new IndexQueryBuilder().withIndexName(INDEX_1_NAME).withId(sampleEntity.getId())
.withObject(sampleEntity).build();

elasticsearchTemplate.index(idxQuery);
elasticsearchTemplate.refresh(INDEX_1_NAME);

// when
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
.withIndices(INDEX_1_NAME, INDEX_2_NAME).withIndicesOptions(IndicesOptions.lenientExpandOpen()).build();

List<SampleEntity> entities = new ArrayList<>();

ScrolledPage<SampleEntity> scroll = elasticsearchTemplate.startScroll(scrollTimeInMillis, searchQuery,
SampleEntity.class, searchResultMapper);

entities.addAll(scroll.getContent());

while (scroll.hasContent()) {
scroll = elasticsearchTemplate.continueScroll(scroll.getScrollId(), scrollTimeInMillis, SampleEntity.class,
searchResultMapper);

entities.addAll(scroll.getContent());
}

// then
assertThat(entities).isNotNull();
assertThat(entities.size()).isGreaterThanOrEqualTo(1);
}

@Test // DATAES-479
public void shouldHonorTheHighlightBuilderOptions() {

Expand Down