Skip to content

Enhance refresh policy handling #2725

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 11, 2023
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 @@ -12,6 +12,7 @@
* Enable MultiField annotation on property getter
* Support nested sort option
* Improved scripted und runtime field support
* Improved refresh policy support

[[new-features.5-1-0]]
== New in Spring Data Elasticsearch 5.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ public SearchScrollHits<T> doWith(SearchDocumentResponse response) {
}
// endregion

// region routing
// region customization
private void setRoutingResolver(RoutingResolver routingResolver) {

Assert.notNull(routingResolver, "routingResolver must not be null");
Expand All @@ -873,5 +873,13 @@ public ElasticsearchOperations withRouting(RoutingResolver routingResolver) {
return copy;
}

@Override
public ElasticsearchOperations withRefreshPolicy(@Nullable RefreshPolicy refreshPolicy) {

var copy = copy();
copy.setRefreshPolicy(refreshPolicy);
return copy;
}

// endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public Mono<Void> logVersions() {

// endregion

// region routing
// region customizations
private void setRoutingResolver(RoutingResolver routingResolver) {

Assert.notNull(routingResolver, "routingResolver must not be null");
Expand All @@ -203,6 +203,14 @@ public ReactiveElasticsearchOperations withRouting(RoutingResolver routingResolv
copy.setRoutingResolver(routingResolver);
return copy;
}

@Override
public ReactiveElasticsearchOperations withRefreshPolicy(@Nullable RefreshPolicy refreshPolicy) {
AbstractReactiveElasticsearchTemplate copy = copy();
copy.setRefreshPolicy(refreshPolicy);
return copy;
}

// endregion

// region DocumentOperations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.springframework.data.elasticsearch.core;

import java.util.Objects;

import org.springframework.data.elasticsearch.core.cluster.ClusterOperations;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
Expand Down Expand Up @@ -91,15 +89,24 @@ default String convertId(@Nullable Object idValue) {
}
// endregion

// region routing
// region customizations
/**
* Returns a copy of this instance with the same configuration, but that uses a different {@link RoutingResolver} to
* obtain routing information.
*
* @param routingResolver the {@link RoutingResolver} value, must not be {@literal null}.
* @return DocumentOperations instance
* @return {@link ElasticsearchOperations} instance
* @since 4.2
*/
ElasticsearchOperations withRouting(RoutingResolver routingResolver);

/**
* Returns a copy of this instance with the same configuration, but that uses a different {@link RefreshPolicy}.
*
* @param refreshPolicy the {@link RefreshPolicy} value.
* @return {@link ElasticsearchOperations} instance.
* @since 5.2
*/
ElasticsearchOperations withRefreshPolicy(@Nullable RefreshPolicy refreshPolicy);
// endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public interface ReactiveElasticsearchOperations
*/
ReactiveClusterOperations cluster();

// region routing
// region customizations
/**
* Returns a copy of this instance with the same configuration, but that uses a different {@link RoutingResolver} to
* obtain routing information.
Expand All @@ -86,5 +86,14 @@ public interface ReactiveElasticsearchOperations
* @return DocumentOperations instance
*/
ReactiveElasticsearchOperations withRouting(RoutingResolver routingResolver);

/**
* Returns a copy of this instance with the same configuration, but that uses a different {@link RefreshPolicy}.
*
* @param refreshPolicy the {@link RefreshPolicy} value.
* @return {@link ReactiveElasticsearchOperations} instance.
* @since 5.2
*/
ReactiveElasticsearchOperations withRefreshPolicy(@Nullable RefreshPolicy refreshPolicy);
// endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.RefreshPolicy;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.PagingAndSortingRepository;
Expand All @@ -31,6 +32,7 @@
* @author Murali Chevuri
* @author Peter-Josef Meisch
*/
@SuppressWarnings("unused")
@NoRepositoryBean
public interface ElasticsearchRepository<T, ID> extends PagingAndSortingRepository<T, ID>, CrudRepository<T, ID> {

Expand All @@ -43,4 +45,39 @@ public interface ElasticsearchRepository<T, ID> extends PagingAndSortingReposito
* @return
*/
Page<T> searchSimilar(T entity, @Nullable String[] fields, Pageable pageable);

/**
* @since 5.2
*/
<S extends T> S save(S entity, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
<S extends T> Iterable<S> saveAll(Iterable<S> entities, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
void deleteById(ID id, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
void delete(T entity, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
void deleteAllById(Iterable<? extends ID> ids, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
void deleteAll(Iterable<? extends T> entities, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
void deleteAll(@Nullable RefreshPolicy refreshPolicy);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License", @Nullable RefreshPolicy refreshPolicy);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
Expand All @@ -15,16 +15,73 @@
*/
package org.springframework.data.elasticsearch.repository;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import org.reactivestreams.Publisher;
import org.springframework.data.elasticsearch.core.RefreshPolicy;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.data.repository.reactive.ReactiveSortingRepository;
import org.springframework.lang.Nullable;

/**
* Elasticsearch specific {@link org.springframework.data.repository.Repository} interface with reactive support.
*
* @author Christoph Strobl
* @since 3.2
*/
@SuppressWarnings("unused")
@NoRepositoryBean
public interface ReactiveElasticsearchRepository<T, ID>
extends ReactiveSortingRepository<T, ID>, ReactiveCrudRepository<T, ID> {}
extends ReactiveSortingRepository<T, ID>, ReactiveCrudRepository<T, ID> {
/**
* @since 5.2
*/
<S extends T> Mono<S> save(S entity, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
<S extends T> Flux<S> saveAll(Iterable<S> entities, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
<S extends T> Flux<S> saveAll(Publisher<S> entityStream, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
Mono<Void> deleteById(ID id, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
Mono<Void> deleteById(Publisher<ID> id, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
Mono<Void> delete(T entity, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
Mono<Void> deleteAllById(Iterable<? extends ID> ids, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
Mono<Void> deleteAll(Iterable<? extends T> entities, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
Mono<Void> deleteAll(Publisher<? extends T> entityStream, @Nullable RefreshPolicy refreshPolicy);

/**
* @since 5.2
*/
Mono<Void> deleteAll(@Nullable RefreshPolicy refreshPolicy);
}
Loading