DATAES-433 - Polishing.

This commit is contained in:
Peter-Josef Meisch 2020-08-07 16:07:54 +02:00
parent 68bdc93a0b
commit 99ed967b71
14 changed files with 95 additions and 103 deletions

View File

@ -17,7 +17,6 @@ package org.springframework.data.elasticsearch.annotations;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
@ -31,7 +30,7 @@ import java.lang.annotation.Target;
@Target(ElementType.ANNOTATION_TYPE) @Target(ElementType.ANNOTATION_TYPE)
public @interface JoinTypeRelation { public @interface JoinTypeRelation {
String parent(); String parent();
String[] children(); String[] children();
} }

View File

@ -32,5 +32,5 @@ import java.lang.annotation.Target;
@Inherited @Inherited
public @interface JoinTypeRelations { public @interface JoinTypeRelations {
JoinTypeRelation[] relations(); JoinTypeRelation[] relations();
} }

View File

@ -39,8 +39,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import org.springframework.data.convert.EntityReader; import org.springframework.data.convert.EntityReader;
import org.springframework.data.elasticsearch.BulkFailureException; 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.ElasticsearchConverter;
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter; import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
import org.springframework.data.elasticsearch.core.document.Document; 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.AfterConvertCallback;
import org.springframework.data.elasticsearch.core.event.AfterSaveCallback; import org.springframework.data.elasticsearch.core.event.AfterSaveCallback;
import org.springframework.data.elasticsearch.core.event.BeforeConvertCallback; 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.ElasticsearchPersistentEntity;
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty; import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
@ -76,6 +75,7 @@ import org.springframework.util.Assert;
* @author Sascha Woo * @author Sascha Woo
* @author Peter-Josef Meisch * @author Peter-Josef Meisch
* @author Roman Puchkovskiy * @author Roman Puchkovskiy
* @author Subhobrata Dey
*/ */
public abstract class AbstractElasticsearchTemplate implements ElasticsearchOperations, ApplicationContextAware { public abstract class AbstractElasticsearchTemplate implements ElasticsearchOperations, ApplicationContextAware {
@ -542,7 +542,7 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper
if (joinProperty != null) { if (joinProperty != null) {
Object joinField = persistentEntity.getPropertyAccessor(entity).getProperty(joinProperty); Object joinField = persistentEntity.getPropertyAccessor(entity).getProperty(joinProperty);
if (joinField != null && JoinField.class.isAssignableFrom(joinField.getClass()) if (joinField != null && JoinField.class.isAssignableFrom(joinField.getClass())
&& ((JoinField<?>) joinField).getParent() != null) { && ((JoinField<?>) joinField).getParent() != null) {
return elasticsearchConverter.convertId(((JoinField<?>) joinField).getParent()); return elasticsearchConverter.convertId(((JoinField<?>) joinField).getParent());
} }
} }

View File

@ -121,6 +121,7 @@ import org.springframework.util.StringUtils;
* @author Peter-Josef Meisch * @author Peter-Josef Meisch
* @author Sascha Woo * @author Sascha Woo
* @author Roman Puchkovskiy * @author Roman Puchkovskiy
* @author Subhobrata Dey
* @since 4.0 * @since 4.0
*/ */
class RequestFactory { class RequestFactory {

View File

@ -77,6 +77,7 @@ import org.springframework.util.ObjectUtils;
* @author Mark Paluch * @author Mark Paluch
* @author Roman Puchkovskiy * @author Roman Puchkovskiy
* @author Konrad Kurdej * @author Konrad Kurdej
* @author Subhobrata Dey
* @since 3.2 * @since 3.2
*/ */
public class MappingElasticsearchConverter public class MappingElasticsearchConverter

View File

@ -32,18 +32,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.data.annotation.Transient; import org.springframework.data.annotation.Transient;
import org.springframework.data.elasticsearch.ElasticsearchException; import org.springframework.data.elasticsearch.ElasticsearchException;
import org.springframework.data.elasticsearch.annotations.CompletionContext; import org.springframework.data.elasticsearch.annotations.*;
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.core.ElasticsearchRestTemplate; import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ResourceUtil; import org.springframework.data.elasticsearch.core.ResourceUtil;
import org.springframework.data.elasticsearch.core.completion.Completion; import org.springframework.data.elasticsearch.core.completion.Completion;
@ -347,13 +336,13 @@ public class MappingBuilder {
builder.endObject(); builder.endObject();
} }
private void addJoinFieldMapping(XContentBuilder builder, private void addJoinFieldMapping(XContentBuilder builder, ElasticsearchPersistentProperty property)
ElasticsearchPersistentProperty property) throws IOException { throws IOException {
JoinTypeRelation[] joinTypeRelations = property.getRequiredAnnotation(JoinTypeRelations.class).relations(); JoinTypeRelation[] joinTypeRelations = property.getRequiredAnnotation(JoinTypeRelations.class).relations();
if (joinTypeRelations.length == 0) { if (joinTypeRelations.length == 0) {
logger.warn("Property {}s type is JoinField but its annotation JoinTypeRelation is " + // logger.warn("Property {}s type is JoinField but its annotation JoinTypeRelation is " + //
"not properly maintained", // "not properly maintained", //
property.getFieldName()); property.getFieldName());
return; return;
} }
@ -363,7 +352,7 @@ public class MappingBuilder {
builder.startObject(JOIN_TYPE_RELATIONS); builder.startObject(JOIN_TYPE_RELATIONS);
for (JoinTypeRelation joinTypeRelation: joinTypeRelations) { for (JoinTypeRelation joinTypeRelation : joinTypeRelations) {
String parent = joinTypeRelation.parent(); String parent = joinTypeRelation.parent();
String[] children = joinTypeRelation.children(); String[] children = joinTypeRelation.children();

View File

@ -15,53 +15,53 @@
*/ */
package org.springframework.data.elasticsearch.core.join; package org.springframework.data.elasticsearch.core.join;
import org.springframework.lang.Nullable;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.springframework.lang.Nullable;
/** /**
* @author Subhobrata Dey * @author Subhobrata Dey
* @since 4.1 * @since 4.1
*/ */
public class JoinField<ID> { public class JoinField<ID> {
private final String name; private final String name;
@Nullable private ID parent; @Nullable private ID parent;
public JoinField() { public JoinField() {
this("default", null); this("default", null);
} }
public JoinField(String name) { public JoinField(String name) {
this(name, null); this(name, null);
} }
public JoinField(String name, @Nullable ID parent) { public JoinField(String name, @Nullable ID parent) {
this.name = name; this.name = name;
this.parent = parent; this.parent = parent;
} }
public void setParent(@Nullable ID parent) { public void setParent(@Nullable ID parent) {
this.parent = parent; this.parent = parent;
} }
@Nullable @Nullable
public ID getParent() { public ID getParent() {
return parent; return parent;
} }
public String getName() { public String getName() {
return name; return name;
} }
public Map<String, Object> getAsMap() { public Map<String, Object> getAsMap() {
Map<String, Object> joinMap = new HashMap<>(); Map<String, Object> joinMap = new HashMap<>();
joinMap.put("name", getName()); joinMap.put("name", getName());
joinMap.put("parent", getParent()); joinMap.put("parent", getParent());
return Collections.unmodifiableMap(joinMap); return Collections.unmodifiableMap(joinMap);
} }
} }

View File

@ -122,8 +122,8 @@ public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, El
boolean hasSeqNoPrimaryTermProperty(); boolean hasSeqNoPrimaryTermProperty();
/** /**
* Returns whether the {@link ElasticsearchPersistentEntity} has a {@link JoinField} property. If this call * Returns whether the {@link ElasticsearchPersistentEntity} has a {@link JoinField} property. If this call returns
* returns {@literal true}, {@link #getJoinFieldProperty()} will return a non-{@literal null} value. * {@literal true}, {@link #getJoinFieldProperty()} will return a non-{@literal null} value.
* *
* @return false when {@link ElasticsearchPersistentEntity} does not define a JoinField property. * @return false when {@link ElasticsearchPersistentEntity} does not define a JoinField property.
* @since 4.1 * @since 4.1
@ -142,8 +142,8 @@ public interface ElasticsearchPersistentEntity<T> extends PersistentEntity<T, El
ElasticsearchPersistentProperty getSeqNoPrimaryTermProperty(); ElasticsearchPersistentProperty getSeqNoPrimaryTermProperty();
/** /**
* Returns the {@link JoinField} property of the {@link ElasticsearchPersistentEntity}. Can be {@literal null} * Returns the {@link JoinField} property of the {@link ElasticsearchPersistentEntity}. Can be {@literal null} in case
* in case no such property is available on the entity. * no such property is available on the entity.
* *
* @return the {@link JoinField} {@link ElasticsearchPersistentProperty} of the {@link PersistentEntity} or * @return the {@link JoinField} {@link ElasticsearchPersistentProperty} of the {@link PersistentEntity} or
* {@literal null} if not defined. * {@literal null} if not defined.

View File

@ -51,6 +51,7 @@ import org.springframework.util.Assert;
* @author Ivan Greene * @author Ivan Greene
* @author Peter-Josef Meisch * @author Peter-Josef Meisch
* @author Roman Puchkovskiy * @author Roman Puchkovskiy
* @author Subhobrata Dey
*/ */
public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntity<T, ElasticsearchPersistentProperty> public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntity<T, ElasticsearchPersistentProperty>
implements ElasticsearchPersistentEntity<T> { implements ElasticsearchPersistentEntity<T> {
@ -237,10 +238,11 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
ElasticsearchPersistentProperty joinProperty = this.joinFieldProperty; ElasticsearchPersistentProperty joinProperty = this.joinFieldProperty;
if (joinProperty != null) { if (joinProperty != null) {
throw new MappingException(String.format( throw new MappingException(
"Attempt to add Join property %s but already have property %s registered " String.format(
+ "as Join property. Check your entity configuration!", "Attempt to add Join property %s but already have property %s registered "
property.getField(), joinProperty.getField())); + "as Join property. Check your entity configuration!",
property.getField(), joinProperty.getField()));
} }
this.joinFieldProperty = property; this.joinFieldProperty = property;

View File

@ -24,6 +24,7 @@ import org.springframework.lang.Nullable;
* @author Mohsin Husen * @author Mohsin Husen
* @author Peter-Josef Meisch * @author Peter-Josef Meisch
* @author Roman Puchkovskiy * @author Roman Puchkovskiy
* @author Subhobrata Dey
*/ */
public class IndexQuery { public class IndexQuery {

View File

@ -24,6 +24,7 @@ import org.springframework.lang.Nullable;
* @author Mohsin Husen * @author Mohsin Husen
* @author Peter-Josef Meisch * @author Peter-Josef Meisch
* @author Roman Puchkovskiy * @author Roman Puchkovskiy
* @author Subhobrata Dey
*/ */
public class IndexQueryBuilder { public class IndexQueryBuilder {

View File

@ -16,7 +16,6 @@
package org.springframework.data.elasticsearch; package org.springframework.data.elasticsearch;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.UUID; import java.util.UUID;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
@ -33,6 +32,7 @@ import org.springframework.data.elasticsearch.client.NodeClientFactoryBean;
* @author Ilkang Na * @author Ilkang Na
* @author Peter-Josef Meisch * @author Peter-Josef Meisch
* @author Roman Puchkovskiy * @author Roman Puchkovskiy
* @author Subhobrata Dey
*/ */
public class Utils { public class Utils {

View File

@ -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.annotations.FieldType.*;
import static org.springframework.data.elasticsearch.utils.IdGenerator.*; 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.lang.Object;
import java.util.*; import java.util.Collections;
import java.util.function.Function; import java.util.HashMap;
import java.util.stream.Collectors; import java.util.Map;
import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.SimpleQueryStringBuilder;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.UncategorizedElasticsearchException; import org.springframework.data.elasticsearch.UncategorizedElasticsearchException;
import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field; 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.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.UpdateQuery; import org.springframework.data.elasticsearch.core.query.UpdateQuery;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration; import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest; import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;

View File

@ -50,7 +50,6 @@ import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.cluster.metadata.AliasMetadata; import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.index.VersionType; import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.query.SimpleQueryStringBuilder;
import org.elasticsearch.join.query.ParentIdQueryBuilder; import org.elasticsearch.join.query.ParentIdQueryBuilder;
import org.elasticsearch.script.Script; import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType; 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;
import org.springframework.data.domain.Sort.Order; import org.springframework.data.domain.Sort.Order;
import org.springframework.data.elasticsearch.ElasticsearchException; 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.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.geo.GeoPoint;
import org.springframework.data.elasticsearch.core.index.AliasAction; import org.springframework.data.elasticsearch.core.index.AliasAction;
import org.springframework.data.elasticsearch.core.index.AliasActionParameters; 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.join.JoinField;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.*; import org.springframework.data.elasticsearch.core.query.*;
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.data.util.StreamUtils; import org.springframework.data.util.StreamUtils;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
@ -108,6 +113,7 @@ import org.springframework.lang.Nullable;
* @author Farid Azaza * @author Farid Azaza
* @author Gyula Attila Csorogi * @author Gyula Attila Csorogi
* @author Roman Puchkovskiy * @author Roman Puchkovskiy
* @author Subhobrata Dey
*/ */
public abstract class ElasticsearchTemplateTests { public abstract class ElasticsearchTemplateTests {
@ -138,9 +144,9 @@ public abstract class ElasticsearchTemplateTests {
indexOpsSearchHitsEntity.create(); indexOpsSearchHitsEntity.create();
indexOpsSearchHitsEntity.putMapping(SearchHitsEntity.class); indexOpsSearchHitsEntity.putMapping(SearchHitsEntity.class);
IndexOperations indexOpsJoinEntity = operations.indexOps(ElasticsearchRestTemplateTests.SampleJoinEntity.class); IndexOperations indexOpsJoinEntity = operations.indexOps(SampleJoinEntity.class);
indexOpsJoinEntity.create(); indexOpsJoinEntity.create();
indexOpsJoinEntity.putMapping(ElasticsearchRestTemplateTests.SampleJoinEntity.class); indexOpsJoinEntity.putMapping(SampleJoinEntity.class);
} }
@AfterEach @AfterEach
@ -3350,14 +3356,14 @@ public abstract class ElasticsearchTemplateTests {
myAJoinField2.setParent(qId1); myAJoinField2.setParent(qId1);
sampleAnswerEntity2.setMyJoinField(myAJoinField2); sampleAnswerEntity2.setMyJoinField(myAJoinField2);
operations.save(Arrays.asList(sampleQuestionEntity1, sampleQuestionEntity2, operations.save(
sampleAnswerEntity1, sampleAnswerEntity2), IndexCoordinates.of(INDEX_NAME_JOIN_SAMPLE_ENTITY)); Arrays.asList(sampleQuestionEntity1, sampleQuestionEntity2, sampleAnswerEntity1, sampleAnswerEntity2),
indexOperations.refresh(); IndexCoordinates.of(INDEX_NAME_JOIN_SAMPLE_ENTITY));
Thread.sleep(5000); operations.indexOps(IndexCoordinates.of(INDEX_NAME_JOIN_SAMPLE_ENTITY)).refresh();
SearchHits<SampleJoinEntity> hits = operations.search(new NativeSearchQueryBuilder().withQuery( SearchHits<SampleJoinEntity> hits = operations.search(
new ParentIdQueryBuilder("answer", qId1)) new NativeSearchQueryBuilder().withQuery(new ParentIdQueryBuilder("answer", qId1)).build(),
.build(), SampleJoinEntity.class); SampleJoinEntity.class);
List<String> hitIds = hits.getSearchHits().stream().map(new Function<SearchHit<SampleJoinEntity>, String>() { List<String> hitIds = hits.getSearchHits().stream().map(new Function<SearchHit<SampleJoinEntity>, String>() {
@Override @Override
@ -3376,8 +3382,7 @@ public abstract class ElasticsearchTemplateTests {
document.put("myJoinField", new JoinField<>("answer", qId2).getAsMap()); document.put("myJoinField", new JoinField<>("answer", qId2).getAsMap());
UpdateQuery updateQuery = UpdateQuery.builder(aId2) // UpdateQuery updateQuery = UpdateQuery.builder(aId2) //
.withDocument(document) // .withDocument(document) //
.withRouting(qId2) .withRouting(qId2).build();
.build();
List<UpdateQuery> queries = new ArrayList<>(); List<UpdateQuery> queries = new ArrayList<>();
queries.add(updateQuery); queries.add(updateQuery);
@ -3387,9 +3392,9 @@ public abstract class ElasticsearchTemplateTests {
indexOperations.refresh(); indexOperations.refresh();
Thread.sleep(5000); Thread.sleep(5000);
SearchHits<SampleJoinEntity> updatedHits = operations.search(new NativeSearchQueryBuilder().withQuery( SearchHits<SampleJoinEntity> updatedHits = operations.search(
new ParentIdQueryBuilder("answer", qId2)) new NativeSearchQueryBuilder().withQuery(new ParentIdQueryBuilder("answer", qId2)).build(),
.build(), SampleJoinEntity.class); SampleJoinEntity.class);
List<String> hitIds = updatedHits.getSearchHits().stream().map(new Function<SearchHit<SampleJoinEntity>, String>() { List<String> hitIds = updatedHits.getSearchHits().stream().map(new Function<SearchHit<SampleJoinEntity>, String>() {
@Override @Override
@ -3400,9 +3405,9 @@ public abstract class ElasticsearchTemplateTests {
assertThat(hitIds.size()).isEqualTo(1); assertThat(hitIds.size()).isEqualTo(1);
assertThat(hitIds.get(0)).isEqualTo(aId2); assertThat(hitIds.get(0)).isEqualTo(aId2);
updatedHits = operations.search(new NativeSearchQueryBuilder().withQuery( updatedHits = operations.search(
new ParentIdQueryBuilder("answer", qId1)) new NativeSearchQueryBuilder().withQuery(new ParentIdQueryBuilder("answer", qId1)).build(),
.build(), SampleJoinEntity.class); SampleJoinEntity.class);
hitIds = updatedHits.getSearchHits().stream().map(new Function<SearchHit<SampleJoinEntity>, String>() { hitIds = updatedHits.getSearchHits().stream().map(new Function<SearchHit<SampleJoinEntity>, String>() {
@Override @Override
@ -3415,17 +3420,15 @@ public abstract class ElasticsearchTemplateTests {
} }
void shouldDeleteEntityWithJoinFields(String qId2, String aId2) throws Exception { void shouldDeleteEntityWithJoinFields(String qId2, String aId2) throws Exception {
Query query = new NativeSearchQueryBuilder() Query query = new NativeSearchQueryBuilder().withQuery(new ParentIdQueryBuilder("answer", qId2)).withRoute(qId2)
.withQuery(new ParentIdQueryBuilder("answer", qId2))
.withRoute(qId2)
.build(); .build();
operations.delete(query, SampleJoinEntity.class, IndexCoordinates.of(INDEX_NAME_JOIN_SAMPLE_ENTITY)); operations.delete(query, SampleJoinEntity.class, IndexCoordinates.of(INDEX_NAME_JOIN_SAMPLE_ENTITY));
indexOperations.refresh(); indexOperations.refresh();
Thread.sleep(5000); Thread.sleep(5000);
SearchHits<SampleJoinEntity> deletedHits = operations.search(new NativeSearchQueryBuilder().withQuery( SearchHits<SampleJoinEntity> deletedHits = operations.search(
new ParentIdQueryBuilder("answer", qId2)) new NativeSearchQueryBuilder().withQuery(new ParentIdQueryBuilder("answer", qId2)).build(),
.build(), SampleJoinEntity.class); SampleJoinEntity.class);
List<String> hitIds = deletedHits.getSearchHits().stream().map(new Function<SearchHit<SampleJoinEntity>, String>() { List<String> hitIds = deletedHits.getSearchHits().stream().map(new Function<SearchHit<SampleJoinEntity>, String>() {
@Override @Override
@ -3625,9 +3628,7 @@ public abstract class ElasticsearchTemplateTests {
static class SampleJoinEntity { static class SampleJoinEntity {
@Id @Field(type = Keyword) private String uuid; @Id @Field(type = Keyword) private String uuid;
@JoinTypeRelations(relations = { @JoinTypeRelations(relations = {
@JoinTypeRelation(parent = "question", children = {"answer"}) @JoinTypeRelation(parent = "question", children = { "answer" }) }) private JoinField<String> myJoinField;
})
private JoinField<String> myJoinField;
@Field(type = Text) private String text; @Field(type = Text) private String text;
} }
} }