Skip to content

Commit 44f9b29

Browse files
committed
Polishing.
1 parent a22419c commit 44f9b29

File tree

6 files changed

+46
-27
lines changed

6 files changed

+46
-27
lines changed

Diff for: src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/query/NativeSearchQueryBuilder.java

+8
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ public NativeSearchQueryBuilder withFields(String... fields) {
244244
return this;
245245
}
246246

247+
/**
248+
* @since 4.4
249+
*/
247250
public NativeSearchQueryBuilder withStoredFields(Collection<String> storedFields) {
251+
248252
if (this.storedFields == null) {
249253
this.storedFields = new ArrayList<>(storedFields);
250254
} else {
@@ -253,7 +257,11 @@ public NativeSearchQueryBuilder withStoredFields(Collection<String> storedFields
253257
return this;
254258
}
255259

260+
/**
261+
* @since 4.4
262+
*/
256263
public NativeSearchQueryBuilder withStoredFields(String... storedFields) {
264+
257265
if (this.storedFields == null) {
258266
this.storedFields = new ArrayList<>(storedFields.length);
259267
}

Diff for: src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,7 @@
5151
import org.springframework.data.mapping.PersistentPropertyAccessor;
5252
import org.springframework.data.mapping.PreferredConstructor;
5353
import org.springframework.data.mapping.context.MappingContext;
54-
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
55-
import org.springframework.data.mapping.model.DefaultSpELExpressionEvaluator;
56-
import org.springframework.data.mapping.model.EntityInstantiator;
57-
import org.springframework.data.mapping.model.EntityInstantiators;
58-
import org.springframework.data.mapping.model.ParameterValueProvider;
59-
import org.springframework.data.mapping.model.PersistentEntityParameterValueProvider;
60-
import org.springframework.data.mapping.model.PropertyValueProvider;
61-
import org.springframework.data.mapping.model.SpELContext;
62-
import org.springframework.data.mapping.model.SpELExpressionEvaluator;
63-
import org.springframework.data.mapping.model.SpELExpressionParameterValueProvider;
54+
import org.springframework.data.mapping.model.*;
6455
import org.springframework.data.util.ClassTypeInformation;
6556
import org.springframework.data.util.TypeInformation;
6657
import org.springframework.format.datetime.DateFormatterRegistrar;

Diff for: src/main/java/org/springframework/data/elasticsearch/core/query/BaseQuery.java

+2
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ public void setFields(List<String> fields) {
113113

114114
@Override
115115
public void addStoredFields(String... storedFields) {
116+
116117
if (storedFields.length == 0) {
117118
return;
118119
}
120+
119121
if (this.storedFields == null) {
120122
this.storedFields = new ArrayList<>(storedFields.length);
121123
}

Diff for: src/main/java/org/springframework/data/elasticsearch/core/query/Query.java

+3
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,15 @@ static Query findAll() {
113113
* Add stored fields to be added as part of search request
114114
*
115115
* @param storedFields
116+
* @since 4.4
116117
*/
117118
void addStoredFields(String... storedFields);
118119

119120
/**
120121
* Get stored fields to be returned as part of search request
121122
*
122123
* @return null if not set
124+
* @since 4.4
123125
*/
124126
@Nullable
125127
List<String> getStoredFields();
@@ -128,6 +130,7 @@ static Query findAll() {
128130
* Set stored fields to be returned as part of search request
129131
*
130132
* @param storedFields
133+
* @since 4.4
131134
*/
132135
void setStoredFields(@Nullable List<String> storedFields);
133136

Diff for: src/test/java/org/springframework/data/elasticsearch/backend/elasticsearch7/CriteriaQueryMappingUnitTests.java

+22-12
Original file line numberDiff line numberDiff line change
@@ -474,28 +474,38 @@ private String getBase64EncodedGeoShapeQuery(GeoJson<?> geoJson, String elasticF
474474

475475
// region test entities
476476
static class Person {
477-
@Nullable @Id String id;
478-
@Nullable @Field(name = "first-name") String firstName;
479-
@Nullable @Field(name = "last-name") String lastName;
480-
@Nullable @MultiField(mainField = @Field(name = "nick-name"),
477+
@Nullable
478+
@Id String id;
479+
@Nullable
480+
@Field(name = "first-name") String firstName;
481+
@Nullable
482+
@Field(name = "last-name") String lastName;
483+
@Nullable
484+
@MultiField(mainField = @Field(name = "nick-name"),
481485
otherFields = { @InnerField(suffix = "keyword", type = FieldType.Keyword) }) String nickName;
482-
@Nullable @Field(name = "created-date", type = FieldType.Date, format = DateFormat.epoch_millis) Date createdDate;
483-
@Nullable @Field(name = "birth-date", type = FieldType.Date, format = {},
484-
pattern = "dd.MM.uuuu") LocalDate birthDate;
486+
@Nullable
487+
@Field(name = "created-date", type = FieldType.Date, format = DateFormat.epoch_millis) Date createdDate;
488+
@Nullable
489+
@Field(name = "birth-date", type = FieldType.Date, format = {}, pattern = "dd.MM.uuuu") LocalDate birthDate;
485490
}
486491

487492
static class House {
488-
@Nullable @Id String id;
489-
@Nullable @Field(name = "per-sons", type = FieldType.Nested) List<Person> persons;
493+
@Nullable
494+
@Id String id;
495+
@Nullable
496+
@Field(name = "per-sons", type = FieldType.Nested) List<Person> persons;
490497
}
491498

492499
static class ObjectWithPerson {
493-
@Nullable @Id String id;
494-
@Nullable @Field(name = "per-sons", type = FieldType.Object) List<Person> persons;
500+
@Nullable
501+
@Id String id;
502+
@Nullable
503+
@Field(name = "per-sons", type = FieldType.Object) List<Person> persons;
495504
}
496505

497506
static class GeoShapeEntity {
498-
@Nullable @Field(name = "geo-shape-field") GeoJson<?> geoShapeField;
507+
@Nullable
508+
@Field(name = "geo-shape-field") GeoJson<?> geoShapeField;
499509
}
500510
// endregion
501511
}

Diff for: src/test/java/org/springframework/data/elasticsearch/backend/elasticsearch7/RequestFactoryTests.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -552,19 +552,24 @@ void shouldSetRequestCacheFalseOnSearchRequest() {
552552
@DisplayName("should set stored fields on SearchRequest")
553553
void shouldSetStoredFieldsOnSearchRequest() {
554554

555-
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withStoredFields("lastName", "location").build();
555+
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withStoredFields("lastName", "location")
556+
.build();
556557

557558
SearchRequest searchRequest = requestFactory.searchRequest(query, Person.class, IndexCoordinates.of("persons"));
558559

559560
assertThat(searchRequest.source().storedFields()).isNotNull();
560-
assertThat(searchRequest.source().storedFields().fieldNames()).isEqualTo(Arrays.asList("last-name", "current-location"));
561+
assertThat(searchRequest.source().storedFields().fieldNames())
562+
.isEqualTo(Arrays.asList("last-name", "current-location"));
561563
}
562564

563565
// region entities
564566
static class Person {
565-
@Nullable @Id String id;
566-
@Nullable @Field(name = "last-name") String lastName;
567-
@Nullable @Field(name = "current-location") GeoPoint location;
567+
@Nullable
568+
@Id String id;
569+
@Nullable
570+
@Field(name = "last-name") String lastName;
571+
@Nullable
572+
@Field(name = "current-location") GeoPoint location;
568573

569574
public Person() {}
570575

0 commit comments

Comments
 (0)