Set refresh on DeleteByQueryRequest by DeleteQuery.

Original Pull Request #2976
Closes #2973

(cherry picked from commit b1b232d354374d4003a1d640e1aec96bf0a6d687)
This commit is contained in:
HAN SEUNGWOO 2024-09-04 03:09:26 +09:00 committed by Peter-Josef Meisch
parent a179dd0643
commit 3a9a959918
No known key found for this signature in database
GPG Key ID: DE108246970C7708
2 changed files with 20 additions and 0 deletions

View File

@ -1021,6 +1021,9 @@ class RequestConverter extends AbstractQueryProcessor {
.collect(Collectors.toList()));
}
}
if (query.getRefresh() != null) {
dqb.refresh(query.getRefresh());
}
dqb.allowNoIndices(query.getAllowNoIndices())
.conflicts(conflicts(query.getConflicts()))
.ignoreUnavailable(query.getIgnoreUnavailable())

View File

@ -30,12 +30,16 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
import org.springframework.data.elasticsearch.core.query.Criteria;
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
import org.springframework.data.elasticsearch.core.query.DocValueField;
import org.springframework.data.elasticsearch.core.query.StringQuery;
import org.springframework.lang.Nullable;
/**
* @author Peter-Josef Meisch
* @author Han Seungwoo
*/
class RequestConverterTest {
@ -72,6 +76,19 @@ class RequestConverterTest {
assertThat(fieldAndFormats.get(1).format()).isEqualTo("format2");
}
@Test // #2973
@DisplayName("should set refresh based on deleteRequest")
void refreshSetByDeleteRequest() {
var query = new CriteriaQuery(new Criteria("text").contains("test"));
var deleteQuery = DeleteQuery.builder(query).withRefresh(true).build();
var deleteByQueryRequest = requestConverter.documentDeleteByQueryRequest(deleteQuery, null, SampleEntity.class,
IndexCoordinates.of("foo"),
null);
assertThat(deleteByQueryRequest.refresh()).isTrue();
}
@Document(indexName = "does-not-matter")
static class SampleEntity {
@Nullable