mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-01 09:42:11 +00:00
DATAES-433 - Polishing.
This commit is contained in:
parent
68bdc93a0b
commit
99ed967b71
@ -17,7 +17,6 @@ package org.springframework.data.elasticsearch.annotations;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
@ -39,8 +39,6 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.data.convert.EntityReader;
|
||||
import org.springframework.data.elasticsearch.BulkFailureException;
|
||||
import org.springframework.data.elasticsearch.core.join.JoinField;
|
||||
import org.springframework.data.elasticsearch.annotations.JoinTypeRelations;
|
||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.document.Document;
|
||||
@ -48,6 +46,7 @@ import org.springframework.data.elasticsearch.core.document.SearchDocumentRespon
|
||||
import org.springframework.data.elasticsearch.core.event.AfterConvertCallback;
|
||||
import org.springframework.data.elasticsearch.core.event.AfterSaveCallback;
|
||||
import org.springframework.data.elasticsearch.core.event.BeforeConvertCallback;
|
||||
import org.springframework.data.elasticsearch.core.join.JoinField;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
@ -76,6 +75,7 @@ import org.springframework.util.Assert;
|
||||
* @author Sascha Woo
|
||||
* @author Peter-Josef Meisch
|
||||
* @author Roman Puchkovskiy
|
||||
* @author Subhobrata Dey
|
||||
*/
|
||||
public abstract class AbstractElasticsearchTemplate implements ElasticsearchOperations, ApplicationContextAware {
|
||||
|
||||
|
@ -121,6 +121,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Peter-Josef Meisch
|
||||
* @author Sascha Woo
|
||||
* @author Roman Puchkovskiy
|
||||
* @author Subhobrata Dey
|
||||
* @since 4.0
|
||||
*/
|
||||
class RequestFactory {
|
||||
|
@ -77,6 +77,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Mark Paluch
|
||||
* @author Roman Puchkovskiy
|
||||
* @author Konrad Kurdej
|
||||
* @author Subhobrata Dey
|
||||
* @since 3.2
|
||||
*/
|
||||
public class MappingElasticsearchConverter
|
||||
|
@ -32,18 +32,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.annotations.CompletionContext;
|
||||
import org.springframework.data.elasticsearch.annotations.CompletionField;
|
||||
import org.springframework.data.elasticsearch.annotations.DynamicMapping;
|
||||
import org.springframework.data.elasticsearch.annotations.DynamicTemplates;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
import org.springframework.data.elasticsearch.annotations.GeoPointField;
|
||||
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||
import org.springframework.data.elasticsearch.annotations.JoinTypeRelation;
|
||||
import org.springframework.data.elasticsearch.annotations.JoinTypeRelations;
|
||||
import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.core.ResourceUtil;
|
||||
import org.springframework.data.elasticsearch.core.completion.Completion;
|
||||
@ -347,8 +336,8 @@ public class MappingBuilder {
|
||||
builder.endObject();
|
||||
}
|
||||
|
||||
private void addJoinFieldMapping(XContentBuilder builder,
|
||||
ElasticsearchPersistentProperty property) throws IOException {
|
||||
private void addJoinFieldMapping(XContentBuilder builder, ElasticsearchPersistentProperty property)
|
||||
throws IOException {
|
||||
JoinTypeRelation[] joinTypeRelations = property.getRequiredAnnotation(JoinTypeRelations.class).relations();
|
||||
|
||||
if (joinTypeRelations.length == 0) {
|
||||
|
@ -15,12 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.join;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* @author Subhobrata Dey
|
||||
* @since 4.1
|
||||
|
@ -122,8 +122,8 @@ public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, El
|
||||
boolean hasSeqNoPrimaryTermProperty();
|
||||
|
||||
/**
|
||||
* Returns whether the {@link ElasticsearchPersistentEntity} has a {@link JoinField} property. If this call
|
||||
* returns {@literal true}, {@link #getJoinFieldProperty()} will return a non-{@literal null} value.
|
||||
* Returns whether the {@link ElasticsearchPersistentEntity} has a {@link JoinField} property. If this call returns
|
||||
* {@literal true}, {@link #getJoinFieldProperty()} will return a non-{@literal null} value.
|
||||
*
|
||||
* @return false when {@link ElasticsearchPersistentEntity} does not define a JoinField property.
|
||||
* @since 4.1
|
||||
@ -142,8 +142,8 @@ public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, El
|
||||
ElasticsearchPersistentProperty getSeqNoPrimaryTermProperty();
|
||||
|
||||
/**
|
||||
* Returns the {@link JoinField} property of the {@link ElasticsearchPersistentEntity}. Can be {@literal null}
|
||||
* in case no such property is available on the entity.
|
||||
* Returns the {@link JoinField} property of the {@link ElasticsearchPersistentEntity}. Can be {@literal null} in case
|
||||
* no such property is available on the entity.
|
||||
*
|
||||
* @return the {@link JoinField} {@link ElasticsearchPersistentProperty} of the {@link PersistentEntity} or
|
||||
* {@literal null} if not defined.
|
||||
|
@ -51,6 +51,7 @@ import org.springframework.util.Assert;
|
||||
* @author Ivan Greene
|
||||
* @author Peter-Josef Meisch
|
||||
* @author Roman Puchkovskiy
|
||||
* @author Subhobrata Dey
|
||||
*/
|
||||
public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntity<T, ElasticsearchPersistentProperty>
|
||||
implements ElasticsearchPersistentEntity<T> {
|
||||
@ -237,7 +238,8 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
||||
ElasticsearchPersistentProperty joinProperty = this.joinFieldProperty;
|
||||
|
||||
if (joinProperty != null) {
|
||||
throw new MappingException(String.format(
|
||||
throw new MappingException(
|
||||
String.format(
|
||||
"Attempt to add Join property %s but already have property %s registered "
|
||||
+ "as Join property. Check your entity configuration!",
|
||||
property.getField(), joinProperty.getField()));
|
||||
|
@ -24,6 +24,7 @@ import org.springframework.lang.Nullable;
|
||||
* @author Mohsin Husen
|
||||
* @author Peter-Josef Meisch
|
||||
* @author Roman Puchkovskiy
|
||||
* @author Subhobrata Dey
|
||||
*/
|
||||
public class IndexQuery {
|
||||
|
||||
|
@ -24,6 +24,7 @@ import org.springframework.lang.Nullable;
|
||||
* @author Mohsin Husen
|
||||
* @author Peter-Josef Meisch
|
||||
* @author Roman Puchkovskiy
|
||||
* @author Subhobrata Dey
|
||||
*/
|
||||
public class IndexQueryBuilder {
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
package org.springframework.data.elasticsearch;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
@ -33,6 +32,7 @@ import org.springframework.data.elasticsearch.client.NodeClientFactoryBean;
|
||||
* @author Ilkang Na
|
||||
* @author Peter-Josef Meisch
|
||||
* @author Roman Puchkovskiy
|
||||
* @author Subhobrata Dey
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
|
@ -19,28 +19,25 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
import static org.springframework.data.elasticsearch.utils.IdGenerator.*;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.val;
|
||||
|
||||
import java.lang.Object;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.action.support.ActiveShardCount;
|
||||
import org.elasticsearch.action.support.WriteRequest;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.query.SimpleQueryStringBuilder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.UncategorizedElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.JoinTypeRelation;
|
||||
import org.springframework.data.elasticsearch.annotations.JoinTypeRelations;
|
||||
import org.springframework.data.elasticsearch.core.join.JoinField;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
|
@ -50,7 +50,6 @@ import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.cluster.metadata.AliasMetadata;
|
||||
import org.elasticsearch.index.VersionType;
|
||||
import org.elasticsearch.index.query.SimpleQueryStringBuilder;
|
||||
import org.elasticsearch.join.query.ParentIdQueryBuilder;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
@ -71,8 +70,15 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
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.InnerField;
|
||||
import org.springframework.data.elasticsearch.annotations.JoinTypeRelation;
|
||||
import org.springframework.data.elasticsearch.annotations.JoinTypeRelations;
|
||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
import org.springframework.data.elasticsearch.core.index.AliasAction;
|
||||
import org.springframework.data.elasticsearch.core.index.AliasActionParameters;
|
||||
@ -81,7 +87,6 @@ import org.springframework.data.elasticsearch.core.index.AliasData;
|
||||
import org.springframework.data.elasticsearch.core.join.JoinField;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.*;
|
||||
import org.springframework.data.elasticsearch.core.query.Query;
|
||||
import org.springframework.data.util.StreamUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@ -108,6 +113,7 @@ import org.springframework.lang.Nullable;
|
||||
* @author Farid Azaza
|
||||
* @author Gyula Attila Csorogi
|
||||
* @author Roman Puchkovskiy
|
||||
* @author Subhobrata Dey
|
||||
*/
|
||||
public abstract class ElasticsearchTemplateTests {
|
||||
|
||||
@ -138,9 +144,9 @@ public abstract class ElasticsearchTemplateTests {
|
||||
indexOpsSearchHitsEntity.create();
|
||||
indexOpsSearchHitsEntity.putMapping(SearchHitsEntity.class);
|
||||
|
||||
IndexOperations indexOpsJoinEntity = operations.indexOps(ElasticsearchRestTemplateTests.SampleJoinEntity.class);
|
||||
IndexOperations indexOpsJoinEntity = operations.indexOps(SampleJoinEntity.class);
|
||||
indexOpsJoinEntity.create();
|
||||
indexOpsJoinEntity.putMapping(ElasticsearchRestTemplateTests.SampleJoinEntity.class);
|
||||
indexOpsJoinEntity.putMapping(SampleJoinEntity.class);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@ -3350,14 +3356,14 @@ public abstract class ElasticsearchTemplateTests {
|
||||
myAJoinField2.setParent(qId1);
|
||||
sampleAnswerEntity2.setMyJoinField(myAJoinField2);
|
||||
|
||||
operations.save(Arrays.asList(sampleQuestionEntity1, sampleQuestionEntity2,
|
||||
sampleAnswerEntity1, sampleAnswerEntity2), IndexCoordinates.of(INDEX_NAME_JOIN_SAMPLE_ENTITY));
|
||||
indexOperations.refresh();
|
||||
Thread.sleep(5000);
|
||||
operations.save(
|
||||
Arrays.asList(sampleQuestionEntity1, sampleQuestionEntity2, sampleAnswerEntity1, sampleAnswerEntity2),
|
||||
IndexCoordinates.of(INDEX_NAME_JOIN_SAMPLE_ENTITY));
|
||||
operations.indexOps(IndexCoordinates.of(INDEX_NAME_JOIN_SAMPLE_ENTITY)).refresh();
|
||||
|
||||
SearchHits<SampleJoinEntity> hits = operations.search(new NativeSearchQueryBuilder().withQuery(
|
||||
new ParentIdQueryBuilder("answer", qId1))
|
||||
.build(), SampleJoinEntity.class);
|
||||
SearchHits<SampleJoinEntity> hits = operations.search(
|
||||
new NativeSearchQueryBuilder().withQuery(new ParentIdQueryBuilder("answer", qId1)).build(),
|
||||
SampleJoinEntity.class);
|
||||
|
||||
List<String> hitIds = hits.getSearchHits().stream().map(new Function<SearchHit<SampleJoinEntity>, String>() {
|
||||
@Override
|
||||
@ -3376,8 +3382,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
document.put("myJoinField", new JoinField<>("answer", qId2).getAsMap());
|
||||
UpdateQuery updateQuery = UpdateQuery.builder(aId2) //
|
||||
.withDocument(document) //
|
||||
.withRouting(qId2)
|
||||
.build();
|
||||
.withRouting(qId2).build();
|
||||
|
||||
List<UpdateQuery> queries = new ArrayList<>();
|
||||
queries.add(updateQuery);
|
||||
@ -3387,9 +3392,9 @@ public abstract class ElasticsearchTemplateTests {
|
||||
indexOperations.refresh();
|
||||
Thread.sleep(5000);
|
||||
|
||||
SearchHits<SampleJoinEntity> updatedHits = operations.search(new NativeSearchQueryBuilder().withQuery(
|
||||
new ParentIdQueryBuilder("answer", qId2))
|
||||
.build(), SampleJoinEntity.class);
|
||||
SearchHits<SampleJoinEntity> updatedHits = operations.search(
|
||||
new NativeSearchQueryBuilder().withQuery(new ParentIdQueryBuilder("answer", qId2)).build(),
|
||||
SampleJoinEntity.class);
|
||||
|
||||
List<String> hitIds = updatedHits.getSearchHits().stream().map(new Function<SearchHit<SampleJoinEntity>, String>() {
|
||||
@Override
|
||||
@ -3400,9 +3405,9 @@ public abstract class ElasticsearchTemplateTests {
|
||||
assertThat(hitIds.size()).isEqualTo(1);
|
||||
assertThat(hitIds.get(0)).isEqualTo(aId2);
|
||||
|
||||
updatedHits = operations.search(new NativeSearchQueryBuilder().withQuery(
|
||||
new ParentIdQueryBuilder("answer", qId1))
|
||||
.build(), SampleJoinEntity.class);
|
||||
updatedHits = operations.search(
|
||||
new NativeSearchQueryBuilder().withQuery(new ParentIdQueryBuilder("answer", qId1)).build(),
|
||||
SampleJoinEntity.class);
|
||||
|
||||
hitIds = updatedHits.getSearchHits().stream().map(new Function<SearchHit<SampleJoinEntity>, String>() {
|
||||
@Override
|
||||
@ -3415,17 +3420,15 @@ public abstract class ElasticsearchTemplateTests {
|
||||
}
|
||||
|
||||
void shouldDeleteEntityWithJoinFields(String qId2, String aId2) throws Exception {
|
||||
Query query = new NativeSearchQueryBuilder()
|
||||
.withQuery(new ParentIdQueryBuilder("answer", qId2))
|
||||
.withRoute(qId2)
|
||||
Query query = new NativeSearchQueryBuilder().withQuery(new ParentIdQueryBuilder("answer", qId2)).withRoute(qId2)
|
||||
.build();
|
||||
operations.delete(query, SampleJoinEntity.class, IndexCoordinates.of(INDEX_NAME_JOIN_SAMPLE_ENTITY));
|
||||
indexOperations.refresh();
|
||||
Thread.sleep(5000);
|
||||
|
||||
SearchHits<SampleJoinEntity> deletedHits = operations.search(new NativeSearchQueryBuilder().withQuery(
|
||||
new ParentIdQueryBuilder("answer", qId2))
|
||||
.build(), SampleJoinEntity.class);
|
||||
SearchHits<SampleJoinEntity> deletedHits = operations.search(
|
||||
new NativeSearchQueryBuilder().withQuery(new ParentIdQueryBuilder("answer", qId2)).build(),
|
||||
SampleJoinEntity.class);
|
||||
|
||||
List<String> hitIds = deletedHits.getSearchHits().stream().map(new Function<SearchHit<SampleJoinEntity>, String>() {
|
||||
@Override
|
||||
@ -3625,9 +3628,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
static class SampleJoinEntity {
|
||||
@Id @Field(type = Keyword) private String uuid;
|
||||
@JoinTypeRelations(relations = {
|
||||
@JoinTypeRelation(parent = "question", children = {"answer"})
|
||||
})
|
||||
private JoinField<String> myJoinField;
|
||||
@JoinTypeRelation(parent = "question", children = { "answer" }) }) private JoinField<String> myJoinField;
|
||||
@Field(type = Text) private String text;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user