mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-22 20:12:11 +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.
|
||||
*
|
||||
|
@ -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;
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.annotations;
|
||||
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
@ -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))
|
||||
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())
|
||||
);
|
||||
.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).
|
||||
*
|
||||
@ -36,40 +36,32 @@ public class Alias {
|
||||
/**
|
||||
* Query used to limit documents the alias can access.
|
||||
*/
|
||||
@Nullable
|
||||
private final Query filter;
|
||||
@Nullable private final Query filter;
|
||||
|
||||
/**
|
||||
* Used to route indexing operations to a specific shard.
|
||||
*/
|
||||
@Nullable
|
||||
private final String indexRouting;
|
||||
@Nullable private final String indexRouting;
|
||||
|
||||
/**
|
||||
* Used to route search operations to a specific shard.
|
||||
*/
|
||||
@Nullable
|
||||
private final String searchRouting;
|
||||
@Nullable private final String searchRouting;
|
||||
|
||||
/**
|
||||
* Used to route indexing and search operations to a specific shard.
|
||||
*/
|
||||
@Nullable
|
||||
private final String routing;
|
||||
@Nullable private final String routing;
|
||||
|
||||
/**
|
||||
* The alias is hidden?
|
||||
* By default, this is set to {@code false}.
|
||||
* The alias is hidden? By default, this is set to {@code false}.
|
||||
*/
|
||||
@Nullable
|
||||
private final Boolean isHidden;
|
||||
@Nullable private final Boolean isHidden;
|
||||
|
||||
/**
|
||||
* The index is the 'write index' for the alias?
|
||||
* By default, this is set to {@code false}.
|
||||
* The index is the 'write index' for the alias? By default, this is set to {@code false}.
|
||||
*/
|
||||
@Nullable
|
||||
private final Boolean isWriteIndex;
|
||||
@Nullable private final Boolean isWriteIndex;
|
||||
|
||||
private Alias(Builder builder) {
|
||||
this.alias = builder.alias;
|
||||
@ -124,8 +116,10 @@ public class Alias {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Alias that)) return false;
|
||||
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)
|
||||
@ -143,20 +137,14 @@ public class 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");
|
||||
@ -206,8 +194,7 @@ public class Alias {
|
||||
}
|
||||
|
||||
/**
|
||||
* The alias is hidden?
|
||||
* By default, this is set to {@code false}.
|
||||
* The alias is hidden? By default, this is set to {@code false}.
|
||||
*/
|
||||
public Builder withHidden(@Nullable Boolean hidden) {
|
||||
isHidden = hidden;
|
||||
@ -216,8 +203,7 @@ public class Alias {
|
||||
}
|
||||
|
||||
/**
|
||||
* The index is the 'write index' for the alias?
|
||||
* By default, this is set to {@code false}.
|
||||
* 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;
|
||||
|
@ -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).
|
||||
*
|
||||
@ -33,11 +33,9 @@ public class CreateIndexSettings {
|
||||
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;
|
||||
@ -59,6 +57,7 @@ public class CreateIndexSettings {
|
||||
return aliases.toArray(Alias[]::new);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Map<String, Object> getSettings() {
|
||||
return settings;
|
||||
}
|
||||
@ -69,14 +68,12 @@ public class CreateIndexSettings {
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private IndexCoordinates indexCoordinates;
|
||||
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");
|
||||
|
@ -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
|
||||
@ -225,6 +225,7 @@ public abstract class IndexOperationsIntegrationTests {
|
||||
})
|
||||
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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user