mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-22 12:02:10 +00:00
Polishing
This commit is contained in:
parent
fbe54e485b
commit
161439ae22
@ -15,9 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.annotations;
|
||||
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Repeatable;
|
||||
@ -25,6 +22,8 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
* Identifies an alias for the index.
|
||||
*
|
||||
@ -33,48 +32,48 @@ import java.lang.annotation.Target;
|
||||
*/
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
@Target({ ElementType.TYPE })
|
||||
@Repeatable(Aliases.class)
|
||||
public @interface Alias {
|
||||
/**
|
||||
* @return Index alias name. Alias for {@link #alias}.
|
||||
*/
|
||||
@AliasFor("alias")
|
||||
String value() default "";
|
||||
/**
|
||||
* @return Index alias name. Alias for {@link #alias}.
|
||||
*/
|
||||
@AliasFor("alias")
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* @return Index alias name. Alias for {@link #value}.
|
||||
*/
|
||||
@AliasFor("value")
|
||||
String alias() default "";
|
||||
/**
|
||||
* @return Index alias name. Alias for {@link #value}.
|
||||
*/
|
||||
@AliasFor("value")
|
||||
String alias() default "";
|
||||
|
||||
/**
|
||||
* @return Query used to limit documents the alias can access.
|
||||
*/
|
||||
Filter filter() default @Filter;
|
||||
/**
|
||||
* @return Query used to limit documents the alias can access.
|
||||
*/
|
||||
Filter filter() default @Filter;
|
||||
|
||||
/**
|
||||
* @return Used to route indexing operations to a specific shard.
|
||||
*/
|
||||
String indexRouting() default "";
|
||||
/**
|
||||
* @return Used to route indexing operations to a specific shard.
|
||||
*/
|
||||
String indexRouting() default "";
|
||||
|
||||
/**
|
||||
* @return Used to route indexing and search operations to a specific shard.
|
||||
*/
|
||||
String routing() default "";
|
||||
/**
|
||||
* @return Used to route indexing and search operations to a specific shard.
|
||||
*/
|
||||
String routing() default "";
|
||||
|
||||
/**
|
||||
* @return Used to route search operations to a specific shard.
|
||||
*/
|
||||
String searchRouting() default "";
|
||||
/**
|
||||
* @return Used to route search operations to a specific shard.
|
||||
*/
|
||||
String searchRouting() default "";
|
||||
|
||||
/**
|
||||
* @return Is the alias hidden?
|
||||
*/
|
||||
boolean isHidden() default false;
|
||||
/**
|
||||
* @return Is the alias hidden?
|
||||
*/
|
||||
boolean isHidden() default false;
|
||||
|
||||
/**
|
||||
* @return Is it the 'write index' for the alias?
|
||||
*/
|
||||
boolean isWriteIndex() default false;
|
||||
/**
|
||||
* @return Is it the 'write index' for the alias?
|
||||
*/
|
||||
boolean isWriteIndex() default false;
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.annotations;
|
||||
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -31,7 +30,7 @@ import java.lang.annotation.Target;
|
||||
*/
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
@Target({ ElementType.TYPE })
|
||||
public @interface Aliases {
|
||||
Alias[] value();
|
||||
Alias[] value();
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.annotations;
|
||||
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
@ -25,15 +24,15 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* @since 5.4
|
||||
*/
|
||||
public @interface Filter {
|
||||
/**
|
||||
* @return Query used to limit documents. Alias for {@link #query}.
|
||||
*/
|
||||
@AliasFor("query")
|
||||
String value() default "";
|
||||
/**
|
||||
* @return Query used to limit documents. Alias for {@link #query}.
|
||||
*/
|
||||
@AliasFor("query")
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* @return Query used to limit documents. Alias for {@link #value}.
|
||||
*/
|
||||
@AliasFor("value")
|
||||
String query() default "";
|
||||
/**
|
||||
* @return Query used to limit documents. Alias for {@link #value}.
|
||||
*/
|
||||
@AliasFor("value")
|
||||
String query() default "";
|
||||
}
|
||||
|
@ -27,8 +27,6 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.elasticsearch.UncategorizedElasticsearchException;
|
||||
@ -63,8 +61,6 @@ import org.springframework.util.Assert;
|
||||
public class IndicesTemplate extends ChildTemplate<ElasticsearchTransport, ElasticsearchIndicesClient>
|
||||
implements IndexOperations {
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog(IndicesTemplate.class);
|
||||
|
||||
// we need a cluster client as well because ES has put some methods from the indices API into the cluster client
|
||||
// (component templates)
|
||||
private final ClusterTemplate clusterTemplate;
|
||||
@ -88,7 +84,7 @@ public class IndicesTemplate extends ChildTemplate<ElasticsearchTransport, Elast
|
||||
}
|
||||
|
||||
public IndicesTemplate(ElasticsearchIndicesClient client, ClusterTemplate clusterTemplate,
|
||||
ElasticsearchConverter elasticsearchConverter, IndexCoordinates boundIndex) {
|
||||
ElasticsearchConverter elasticsearchConverter, IndexCoordinates boundIndex) {
|
||||
super(client, elasticsearchConverter);
|
||||
|
||||
Assert.notNull(clusterTemplate, "cluster must not be null");
|
||||
@ -242,8 +238,7 @@ public class IndicesTemplate extends ChildTemplate<ElasticsearchTransport, Elast
|
||||
GetMappingRequest getMappingRequest = requestConverter.indicesGetMappingRequest(indexCoordinates);
|
||||
GetMappingResponse getMappingResponse = execute(client -> client.getMapping(getMappingRequest));
|
||||
|
||||
Document mappingResponse = responseConverter.indicesGetMapping(getMappingResponse, indexCoordinates);
|
||||
return mappingResponse;
|
||||
return responseConverter.indicesGetMapping(getMappingResponse, indexCoordinates);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,14 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.client.elc;
|
||||
|
||||
import static org.springframework.util.StringUtils.hasText;
|
||||
import static org.springframework.util.StringUtils.*;
|
||||
|
||||
import co.elastic.clients.elasticsearch._types.AcknowledgedResponseBase;
|
||||
import co.elastic.clients.elasticsearch.indices.*;
|
||||
import co.elastic.clients.transport.ElasticsearchTransport;
|
||||
import co.elastic.clients.transport.endpoints.BooleanResponse;
|
||||
import org.springframework.data.elasticsearch.core.mapping.Alias;
|
||||
import org.springframework.data.elasticsearch.core.mapping.CreateIndexSettings;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@ -49,6 +47,8 @@ import org.springframework.data.elasticsearch.core.index.GetIndexTemplateRequest
|
||||
import org.springframework.data.elasticsearch.core.index.GetTemplateRequest;
|
||||
import org.springframework.data.elasticsearch.core.index.PutIndexTemplateRequest;
|
||||
import org.springframework.data.elasticsearch.core.index.PutTemplateRequest;
|
||||
import org.springframework.data.elasticsearch.core.mapping.Alias;
|
||||
import org.springframework.data.elasticsearch.core.mapping.CreateIndexSettings;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
@ -113,7 +113,6 @@ import org.springframework.util.StringUtils;
|
||||
* @author Haibo Liu
|
||||
* @since 4.4
|
||||
*/
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
class RequestConverter extends AbstractQueryProcessor {
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog(RequestConverter.class);
|
||||
@ -172,7 +171,8 @@ class RequestConverter extends AbstractQueryProcessor {
|
||||
}));
|
||||
}
|
||||
|
||||
private co.elastic.clients.elasticsearch.indices.Alias.Builder buildAlias(AliasActionParameters parameters, co.elastic.clients.elasticsearch.indices.Alias.Builder aliasBuilder) {
|
||||
private co.elastic.clients.elasticsearch.indices.Alias.Builder buildAlias(AliasActionParameters parameters,
|
||||
co.elastic.clients.elasticsearch.indices.Alias.Builder aliasBuilder) {
|
||||
|
||||
if (parameters.getRouting() != null) {
|
||||
aliasBuilder.routing(parameters.getRouting());
|
||||
@ -239,13 +239,13 @@ class RequestConverter extends AbstractQueryProcessor {
|
||||
public CreateIndexRequest indicesCreateRequest(CreateIndexSettings indexSettings) {
|
||||
Map<String, co.elastic.clients.elasticsearch.indices.Alias> aliases = new HashMap<>();
|
||||
for (Alias alias : indexSettings.getAliases()) {
|
||||
co.elastic.clients.elasticsearch.indices.Alias esAlias = co.elastic.clients.elasticsearch.indices.Alias.of(ab -> ab.filter(getQuery(alias.getFilter(), null))
|
||||
.routing(alias.getRouting())
|
||||
.indexRouting(alias.getIndexRouting())
|
||||
.searchRouting(alias.getSearchRouting())
|
||||
.isHidden(alias.getHidden())
|
||||
.isWriteIndex(alias.getWriteIndex())
|
||||
);
|
||||
co.elastic.clients.elasticsearch.indices.Alias esAlias = co.elastic.clients.elasticsearch.indices.Alias
|
||||
.of(ab -> ab.filter(getQuery(alias.getFilter(), null))
|
||||
.routing(alias.getRouting())
|
||||
.indexRouting(alias.getIndexRouting())
|
||||
.searchRouting(alias.getSearchRouting())
|
||||
.isHidden(alias.getHidden())
|
||||
.isWriteIndex(alias.getWriteIndex()));
|
||||
aliases.put(alias.getAlias(), esAlias);
|
||||
}
|
||||
|
||||
@ -1026,7 +1026,7 @@ class RequestConverter extends AbstractQueryProcessor {
|
||||
order = sortField.order().jsonValue();
|
||||
}
|
||||
|
||||
return sortField.field() + ":" + order;
|
||||
return sortField.field() + ':' + order;
|
||||
})
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
@ -1790,7 +1790,6 @@ class RequestConverter extends AbstractQueryProcessor {
|
||||
return getEsQuery(query, (q) -> elasticsearchConverter.updateQuery(q, clazz));
|
||||
}
|
||||
|
||||
@SuppressWarnings("StatementWithEmptyBody")
|
||||
private void addPostFilter(Query query, SearchRequest.Builder builder) {
|
||||
|
||||
// we only need to handle NativeQuery here. filter from a CriteriaQuery are added into the query and not as post
|
||||
|
@ -15,12 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.mapping;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.query.Query;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Immutable Value object encapsulating index alias(es).
|
||||
*
|
||||
@ -28,205 +28,191 @@ import java.util.Objects;
|
||||
* @since 5.4
|
||||
*/
|
||||
public class Alias {
|
||||
/**
|
||||
* Alias name for the index.
|
||||
*/
|
||||
private final String alias;
|
||||
/**
|
||||
* Alias name for the index.
|
||||
*/
|
||||
private final String alias;
|
||||
|
||||
/**
|
||||
* Query used to limit documents the alias can access.
|
||||
*/
|
||||
@Nullable
|
||||
private final Query filter;
|
||||
/**
|
||||
* Query used to limit documents the alias can access.
|
||||
*/
|
||||
@Nullable private final Query filter;
|
||||
|
||||
/**
|
||||
* Used to route indexing operations to a specific shard.
|
||||
*/
|
||||
@Nullable
|
||||
private final String indexRouting;
|
||||
/**
|
||||
* Used to route indexing operations to a specific shard.
|
||||
*/
|
||||
@Nullable private final String indexRouting;
|
||||
|
||||
/**
|
||||
* Used to route search operations to a specific shard.
|
||||
*/
|
||||
@Nullable
|
||||
private final String searchRouting;
|
||||
/**
|
||||
* Used to route search operations to a specific shard.
|
||||
*/
|
||||
@Nullable private final String searchRouting;
|
||||
|
||||
/**
|
||||
* Used to route indexing and search operations to a specific shard.
|
||||
*/
|
||||
@Nullable
|
||||
private final String routing;
|
||||
/**
|
||||
* Used to route indexing and search operations to a specific shard.
|
||||
*/
|
||||
@Nullable private final String routing;
|
||||
|
||||
/**
|
||||
* The alias is hidden?
|
||||
* By default, this is set to {@code false}.
|
||||
*/
|
||||
@Nullable
|
||||
private final Boolean isHidden;
|
||||
/**
|
||||
* The alias is hidden? By default, this is set to {@code false}.
|
||||
*/
|
||||
@Nullable private final Boolean isHidden;
|
||||
|
||||
/**
|
||||
* The index is the 'write index' for the alias?
|
||||
* By default, this is set to {@code false}.
|
||||
*/
|
||||
@Nullable
|
||||
private final Boolean isWriteIndex;
|
||||
/**
|
||||
* The index is the 'write index' for the alias? By default, this is set to {@code false}.
|
||||
*/
|
||||
@Nullable private final Boolean isWriteIndex;
|
||||
|
||||
private Alias(Builder builder) {
|
||||
this.alias = builder.alias;
|
||||
private Alias(Builder builder) {
|
||||
this.alias = builder.alias;
|
||||
|
||||
this.filter = builder.filter;
|
||||
this.filter = builder.filter;
|
||||
|
||||
this.indexRouting = builder.indexRouting;
|
||||
this.searchRouting = builder.searchRouting;
|
||||
this.routing = builder.routing;
|
||||
this.indexRouting = builder.indexRouting;
|
||||
this.searchRouting = builder.searchRouting;
|
||||
this.routing = builder.routing;
|
||||
|
||||
this.isHidden = builder.isHidden;
|
||||
this.isWriteIndex = builder.isWriteIndex;
|
||||
}
|
||||
this.isHidden = builder.isHidden;
|
||||
this.isWriteIndex = builder.isWriteIndex;
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Query getFilter() {
|
||||
return filter;
|
||||
}
|
||||
@Nullable
|
||||
public Query getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getIndexRouting() {
|
||||
return indexRouting;
|
||||
}
|
||||
@Nullable
|
||||
public String getIndexRouting() {
|
||||
return indexRouting;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getSearchRouting() {
|
||||
return searchRouting;
|
||||
}
|
||||
@Nullable
|
||||
public String getSearchRouting() {
|
||||
return searchRouting;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getRouting() {
|
||||
return routing;
|
||||
}
|
||||
@Nullable
|
||||
public String getRouting() {
|
||||
return routing;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Boolean getHidden() {
|
||||
return isHidden;
|
||||
}
|
||||
@Nullable
|
||||
public Boolean getHidden() {
|
||||
return isHidden;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Boolean getWriteIndex() {
|
||||
return isWriteIndex;
|
||||
}
|
||||
@Nullable
|
||||
public Boolean getWriteIndex() {
|
||||
return isWriteIndex;
|
||||
}
|
||||
|
||||
public static Builder builder(String alias) {
|
||||
return new Builder(alias);
|
||||
}
|
||||
public static Builder builder(String alias) {
|
||||
return new Builder(alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Alias that)) return false;
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof Alias that))
|
||||
return false;
|
||||
|
||||
return Objects.equals(alias, that.alias) && Objects.equals(filter, that.filter)
|
||||
&& Objects.equals(indexRouting, that.indexRouting)
|
||||
&& Objects.equals(searchRouting, that.searchRouting)
|
||||
&& Objects.equals(routing, that.routing)
|
||||
&& Objects.equals(isHidden, that.isHidden)
|
||||
&& Objects.equals(isWriteIndex, that.isWriteIndex);
|
||||
}
|
||||
return Objects.equals(alias, that.alias) && Objects.equals(filter, that.filter)
|
||||
&& Objects.equals(indexRouting, that.indexRouting)
|
||||
&& Objects.equals(searchRouting, that.searchRouting)
|
||||
&& Objects.equals(routing, that.routing)
|
||||
&& Objects.equals(isHidden, that.isHidden)
|
||||
&& Objects.equals(isWriteIndex, that.isWriteIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(alias, filter, indexRouting, searchRouting, routing, isHidden, isWriteIndex);
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(alias, filter, indexRouting, searchRouting, routing, isHidden, isWriteIndex);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final String alias;
|
||||
public static class Builder {
|
||||
private final String alias;
|
||||
|
||||
@Nullable
|
||||
private Query filter;
|
||||
@Nullable private Query filter;
|
||||
|
||||
@Nullable
|
||||
private String indexRouting;
|
||||
@Nullable
|
||||
private String searchRouting;
|
||||
@Nullable
|
||||
private String routing;
|
||||
@Nullable private String indexRouting;
|
||||
@Nullable private String searchRouting;
|
||||
@Nullable private String routing;
|
||||
|
||||
@Nullable
|
||||
private Boolean isHidden;
|
||||
@Nullable
|
||||
private Boolean isWriteIndex;
|
||||
@Nullable private Boolean isHidden;
|
||||
@Nullable private Boolean isWriteIndex;
|
||||
|
||||
public Builder(String alias) {
|
||||
Assert.notNull(alias, "alias must not be null");
|
||||
this.alias = alias;
|
||||
}
|
||||
public Builder(String alias) {
|
||||
Assert.notNull(alias, "alias must not be null");
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query used to limit documents the alias can access.
|
||||
*/
|
||||
public Builder withFilter(@Nullable Query filter) {
|
||||
this.filter = filter;
|
||||
/**
|
||||
* Query used to limit documents the alias can access.
|
||||
*/
|
||||
public Builder withFilter(@Nullable Query filter) {
|
||||
this.filter = filter;
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to route indexing operations to a specific shard.
|
||||
*/
|
||||
public Builder withIndexRouting(@Nullable String indexRouting) {
|
||||
if (indexRouting != null && !indexRouting.trim().isEmpty()) {
|
||||
this.indexRouting = indexRouting;
|
||||
}
|
||||
/**
|
||||
* Used to route indexing operations to a specific shard.
|
||||
*/
|
||||
public Builder withIndexRouting(@Nullable String indexRouting) {
|
||||
if (indexRouting != null && !indexRouting.trim().isEmpty()) {
|
||||
this.indexRouting = indexRouting;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to route search operations to a specific shard.
|
||||
*/
|
||||
public Builder withSearchRouting(@Nullable String searchRouting) {
|
||||
if (searchRouting != null && !searchRouting.trim().isEmpty()) {
|
||||
this.searchRouting = searchRouting;
|
||||
}
|
||||
/**
|
||||
* Used to route search operations to a specific shard.
|
||||
*/
|
||||
public Builder withSearchRouting(@Nullable String searchRouting) {
|
||||
if (searchRouting != null && !searchRouting.trim().isEmpty()) {
|
||||
this.searchRouting = searchRouting;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to route indexing and search operations to a specific shard.
|
||||
*/
|
||||
public Builder withRouting(@Nullable String routing) {
|
||||
if (routing != null && !routing.trim().isEmpty()) {
|
||||
this.routing = routing;
|
||||
}
|
||||
/**
|
||||
* Used to route indexing and search operations to a specific shard.
|
||||
*/
|
||||
public Builder withRouting(@Nullable String routing) {
|
||||
if (routing != null && !routing.trim().isEmpty()) {
|
||||
this.routing = routing;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The alias is hidden?
|
||||
* By default, this is set to {@code false}.
|
||||
*/
|
||||
public Builder withHidden(@Nullable Boolean hidden) {
|
||||
isHidden = hidden;
|
||||
/**
|
||||
* The alias is hidden? By default, this is set to {@code false}.
|
||||
*/
|
||||
public Builder withHidden(@Nullable Boolean hidden) {
|
||||
isHidden = hidden;
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The index is the 'write index' for the alias?
|
||||
* By default, this is set to {@code false}.
|
||||
*/
|
||||
public Builder withWriteIndex(@Nullable Boolean writeIndex) {
|
||||
isWriteIndex = writeIndex;
|
||||
/**
|
||||
* The index is the 'write index' for the alias? By default, this is set to {@code false}.
|
||||
*/
|
||||
public Builder withWriteIndex(@Nullable Boolean writeIndex) {
|
||||
isWriteIndex = writeIndex;
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Alias build() {
|
||||
return new Alias(this);
|
||||
}
|
||||
}
|
||||
public Alias build() {
|
||||
return new Alias(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,14 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.mapping;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.document.Document;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.document.Document;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Encapsulating index mapping fields, settings, and index alias(es).
|
||||
*
|
||||
@ -30,88 +30,85 @@ import java.util.Set;
|
||||
* @since 5.3
|
||||
*/
|
||||
public class CreateIndexSettings {
|
||||
private final IndexCoordinates indexCoordinates;
|
||||
private final Set<Alias> aliases;
|
||||
private final IndexCoordinates indexCoordinates;
|
||||
private final Set<Alias> aliases;
|
||||
|
||||
@Nullable
|
||||
private final Map<String, Object> settings;
|
||||
@Nullable private final Map<String, Object> settings;
|
||||
|
||||
@Nullable
|
||||
private final Document mapping;
|
||||
@Nullable private final Document mapping;
|
||||
|
||||
private CreateIndexSettings(Builder builder) {
|
||||
this.indexCoordinates = builder.indexCoordinates;
|
||||
this.aliases = builder.aliases;
|
||||
private CreateIndexSettings(Builder builder) {
|
||||
this.indexCoordinates = builder.indexCoordinates;
|
||||
this.aliases = builder.aliases;
|
||||
|
||||
this.settings = builder.settings;
|
||||
this.mapping = builder.mapping;
|
||||
}
|
||||
this.settings = builder.settings;
|
||||
this.mapping = builder.mapping;
|
||||
}
|
||||
|
||||
public static Builder builder(IndexCoordinates indexCoordinates) {
|
||||
return new Builder(indexCoordinates);
|
||||
}
|
||||
public static Builder builder(IndexCoordinates indexCoordinates) {
|
||||
return new Builder(indexCoordinates);
|
||||
}
|
||||
|
||||
public IndexCoordinates getIndexCoordinates() {
|
||||
return indexCoordinates;
|
||||
}
|
||||
public IndexCoordinates getIndexCoordinates() {
|
||||
return indexCoordinates;
|
||||
}
|
||||
|
||||
public Alias[] getAliases() {
|
||||
return aliases.toArray(Alias[]::new);
|
||||
}
|
||||
public Alias[] getAliases() {
|
||||
return aliases.toArray(Alias[]::new);
|
||||
}
|
||||
|
||||
public Map<String, Object> getSettings() {
|
||||
return settings;
|
||||
}
|
||||
@Nullable
|
||||
public Map<String, Object> getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Document getMapping() {
|
||||
return mapping;
|
||||
}
|
||||
@Nullable
|
||||
public Document getMapping() {
|
||||
return mapping;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private IndexCoordinates indexCoordinates;
|
||||
private final Set<Alias> aliases = new HashSet<>();
|
||||
public static class Builder {
|
||||
private final IndexCoordinates indexCoordinates;
|
||||
private final Set<Alias> aliases = new HashSet<>();
|
||||
|
||||
@Nullable
|
||||
private Map<String, Object> settings;
|
||||
@Nullable private Map<String, Object> settings;
|
||||
|
||||
@Nullable
|
||||
private Document mapping;
|
||||
@Nullable private Document mapping;
|
||||
|
||||
public Builder(IndexCoordinates indexCoordinates) {
|
||||
Assert.notNull(indexCoordinates, "indexCoordinates must not be null");
|
||||
this.indexCoordinates = indexCoordinates;
|
||||
}
|
||||
public Builder(IndexCoordinates indexCoordinates) {
|
||||
Assert.notNull(indexCoordinates, "indexCoordinates must not be null");
|
||||
this.indexCoordinates = indexCoordinates;
|
||||
}
|
||||
|
||||
public Builder withAlias(Alias alias) {
|
||||
Assert.notNull(alias, "alias must not be null");
|
||||
this.aliases.add(alias);
|
||||
public Builder withAlias(Alias alias) {
|
||||
Assert.notNull(alias, "alias must not be null");
|
||||
this.aliases.add(alias);
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withAliases(Set<Alias> aliases) {
|
||||
Assert.notNull(aliases, "aliases must not be null");
|
||||
this.aliases.addAll(aliases);
|
||||
public Builder withAliases(Set<Alias> aliases) {
|
||||
Assert.notNull(aliases, "aliases must not be null");
|
||||
this.aliases.addAll(aliases);
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withSettings(Map<String, Object> settings) {
|
||||
Assert.notNull(settings, "settings must not be null");
|
||||
this.settings = settings;
|
||||
public Builder withSettings(Map<String, Object> settings) {
|
||||
Assert.notNull(settings, "settings must not be null");
|
||||
this.settings = settings;
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withMapping(@Nullable Document mapping) {
|
||||
this.mapping = mapping;
|
||||
public Builder withMapping(@Nullable Document mapping) {
|
||||
this.mapping = mapping;
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public CreateIndexSettings build() {
|
||||
return new CreateIndexSettings(this);
|
||||
}
|
||||
}
|
||||
public CreateIndexSettings build() {
|
||||
return new CreateIndexSettings(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.mapping;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Dynamic;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
@ -25,8 +27,6 @@ import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.model.FieldNamingStrategy;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* ElasticsearchPersistentEntity
|
||||
*
|
||||
@ -76,7 +76,7 @@ public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, El
|
||||
boolean isCreateIndexAndMapping();
|
||||
|
||||
/**
|
||||
* returns the {@link ElasticsearchPersistentProperty} with the given fieldName (may be set by the {@link Field}
|
||||
* returns the {@link ElasticsearchPersistentProperty} with the given fieldName (can be set by the {@link Field})
|
||||
* annotation.
|
||||
*
|
||||
* @param fieldName to field name for the search, must not be {@literal null}
|
||||
@ -199,7 +199,7 @@ public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, El
|
||||
boolean storeVersionInSource();
|
||||
|
||||
/**
|
||||
* @return if the mapping should be written to the index on repositry bootstrap even if the index already exists.
|
||||
* @return if the mapping should be written to the index on repository bootstrap even if the index already exists.
|
||||
* @since 5.2
|
||||
*/
|
||||
boolean isAlwaysWriteMapping();
|
||||
|
@ -258,12 +258,12 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
||||
if (property.isIndexedIndexNameProperty()) {
|
||||
|
||||
if (!property.getActualType().isAssignableFrom(String.class)) {
|
||||
throw new MappingException(String.format("@IndexedIndexName annotation must be put on String property"));
|
||||
throw new MappingException("@IndexedIndexName annotation must be put on String property");
|
||||
}
|
||||
|
||||
if (indexedIndexNameProperty != null) {
|
||||
throw new MappingException(
|
||||
String.format("@IndexedIndexName annotation can only be put on one property in an entity"));
|
||||
"@IndexedIndexName annotation can only be put on one property in an entity");
|
||||
}
|
||||
|
||||
this.indexedIndexNameProperty = property;
|
||||
@ -653,8 +653,7 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
||||
.withRouting(alias.routing())
|
||||
.withHidden(alias.isHidden())
|
||||
.withWriteIndex(alias.isWriteIndex())
|
||||
.build()
|
||||
);
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.index;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.Text;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@ -71,7 +71,7 @@ public abstract class IndexOperationsIntegrationTests {
|
||||
@Test
|
||||
@Order(java.lang.Integer.MAX_VALUE)
|
||||
void cleanup() {
|
||||
operations.indexOps(IndexCoordinates.of(indexNameProvider.getPrefix() + "*")).delete();
|
||||
operations.indexOps(IndexCoordinates.of(indexNameProvider.getPrefix() + '*')).delete();
|
||||
}
|
||||
|
||||
@Test // #1646, #1718
|
||||
@ -198,8 +198,8 @@ public abstract class IndexOperationsIntegrationTests {
|
||||
.extracting(StringQuery::getSource)
|
||||
.asString()
|
||||
.contains(Queries.wrapperQuery("""
|
||||
{"bool" : {"must" : {"term" : {"type" : "abc"}}}}
|
||||
""").query());
|
||||
{"bool" : {"must" : {"term" : {"type" : "abc"}}}}
|
||||
""").query());
|
||||
}
|
||||
|
||||
@Document(indexName = "#{@indexNameProvider.indexName()}")
|
||||
@ -219,12 +219,13 @@ public abstract class IndexOperationsIntegrationTests {
|
||||
}
|
||||
|
||||
@Document(indexName = "#{@indexNameProvider.indexName()}", aliases = {
|
||||
@Alias(value = "first_alias", filter =@Filter("""
|
||||
@Alias(value = "first_alias", filter = @Filter("""
|
||||
{"bool" : {"must" : {"term" : {"type" : "abc"}}}}
|
||||
"""))
|
||||
})
|
||||
private static class EntityWithAliases {
|
||||
@Nullable private @Id String id;
|
||||
@Nullable
|
||||
@Field(type = Text) private String type;
|
||||
|
||||
@Nullable
|
||||
@ -236,6 +237,7 @@ public abstract class IndexOperationsIntegrationTests {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
@ -17,14 +17,9 @@ package org.springframework.data.elasticsearch.core.index;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.skyscreamer.jsonassert.JSONAssert.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.Text;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
import static org.springframework.data.elasticsearch.core.IndexOperationsAdapter.*;
|
||||
|
||||
import org.assertj.core.api.InstanceOfAssertFactories;
|
||||
import org.springframework.data.elasticsearch.annotations.Alias;
|
||||
import org.springframework.data.elasticsearch.annotations.Filter;
|
||||
import org.springframework.data.elasticsearch.client.elc.Queries;
|
||||
import org.springframework.data.elasticsearch.core.query.StringQuery;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
@ -32,22 +27,27 @@ import java.time.LocalDate;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.assertj.core.api.InstanceOfAssertFactories;
|
||||
import org.json.JSONException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Alias;
|
||||
import org.springframework.data.elasticsearch.annotations.DateFormat;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
import org.springframework.data.elasticsearch.annotations.Filter;
|
||||
import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||
import org.springframework.data.elasticsearch.annotations.Setting;
|
||||
import org.springframework.data.elasticsearch.client.elc.Queries;
|
||||
import org.springframework.data.elasticsearch.core.IndexOperations;
|
||||
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.ReactiveIndexOperations;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.StringQuery;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
|
||||
import org.springframework.lang.Nullable;
|
||||
@ -367,7 +367,8 @@ public abstract class ReactiveIndexOperationsIntegrationTests {
|
||||
indexOperations.getAliasesForIndex(indexName)
|
||||
.as(StepVerifier::create)
|
||||
.assertNext(aliases -> {
|
||||
AliasData result = aliases.values().stream().findFirst().orElse(new HashSet<>()).stream().findFirst().orElse(null);
|
||||
AliasData result = aliases.values().stream().findFirst().orElse(new HashSet<>()).stream().findFirst()
|
||||
.orElse(null);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getAlias()).isEqualTo("first_alias");
|
||||
@ -375,8 +376,8 @@ public abstract class ReactiveIndexOperationsIntegrationTests {
|
||||
.extracting(StringQuery::getSource)
|
||||
.asString()
|
||||
.contains(Queries.wrapperQuery("""
|
||||
{"bool" : {"must" : {"term" : {"type" : "abc"}}}}
|
||||
""").query());
|
||||
{"bool" : {"must" : {"term" : {"type" : "abc"}}}}
|
||||
""").query());
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@ -437,7 +438,7 @@ public abstract class ReactiveIndexOperationsIntegrationTests {
|
||||
}
|
||||
|
||||
@Document(indexName = "#{@indexNameProvider.indexName()}", aliases = {
|
||||
@Alias(value = "first_alias", filter =@Filter("""
|
||||
@Alias(value = "first_alias", filter = @Filter("""
|
||||
{"bool" : {"must" : {"term" : {"type" : "abc"}}}}
|
||||
"""))
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user