mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-24 21:12:12 +00:00
Polishing.
This commit is contained in:
parent
a22419c418
commit
44f9b29b66
@ -244,7 +244,11 @@ public class NativeSearchQueryBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
public NativeSearchQueryBuilder withStoredFields(Collection<String> storedFields) {
|
public NativeSearchQueryBuilder withStoredFields(Collection<String> storedFields) {
|
||||||
|
|
||||||
if (this.storedFields == null) {
|
if (this.storedFields == null) {
|
||||||
this.storedFields = new ArrayList<>(storedFields);
|
this.storedFields = new ArrayList<>(storedFields);
|
||||||
} else {
|
} else {
|
||||||
@ -253,7 +257,11 @@ public class NativeSearchQueryBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
public NativeSearchQueryBuilder withStoredFields(String... storedFields) {
|
public NativeSearchQueryBuilder withStoredFields(String... storedFields) {
|
||||||
|
|
||||||
if (this.storedFields == null) {
|
if (this.storedFields == null) {
|
||||||
this.storedFields = new ArrayList<>(storedFields.length);
|
this.storedFields = new ArrayList<>(storedFields.length);
|
||||||
}
|
}
|
||||||
|
@ -51,16 +51,7 @@ import org.springframework.data.mapping.MappingException;
|
|||||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||||
import org.springframework.data.mapping.PreferredConstructor;
|
import org.springframework.data.mapping.PreferredConstructor;
|
||||||
import org.springframework.data.mapping.context.MappingContext;
|
import org.springframework.data.mapping.context.MappingContext;
|
||||||
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
|
import org.springframework.data.mapping.model.*;
|
||||||
import org.springframework.data.mapping.model.DefaultSpELExpressionEvaluator;
|
|
||||||
import org.springframework.data.mapping.model.EntityInstantiator;
|
|
||||||
import org.springframework.data.mapping.model.EntityInstantiators;
|
|
||||||
import org.springframework.data.mapping.model.ParameterValueProvider;
|
|
||||||
import org.springframework.data.mapping.model.PersistentEntityParameterValueProvider;
|
|
||||||
import org.springframework.data.mapping.model.PropertyValueProvider;
|
|
||||||
import org.springframework.data.mapping.model.SpELContext;
|
|
||||||
import org.springframework.data.mapping.model.SpELExpressionEvaluator;
|
|
||||||
import org.springframework.data.mapping.model.SpELExpressionParameterValueProvider;
|
|
||||||
import org.springframework.data.util.ClassTypeInformation;
|
import org.springframework.data.util.ClassTypeInformation;
|
||||||
import org.springframework.data.util.TypeInformation;
|
import org.springframework.data.util.TypeInformation;
|
||||||
import org.springframework.format.datetime.DateFormatterRegistrar;
|
import org.springframework.format.datetime.DateFormatterRegistrar;
|
||||||
|
@ -113,9 +113,11 @@ public class BaseQuery implements Query {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addStoredFields(String... storedFields) {
|
public void addStoredFields(String... storedFields) {
|
||||||
|
|
||||||
if (storedFields.length == 0) {
|
if (storedFields.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.storedFields == null) {
|
if (this.storedFields == null) {
|
||||||
this.storedFields = new ArrayList<>(storedFields.length);
|
this.storedFields = new ArrayList<>(storedFields.length);
|
||||||
}
|
}
|
||||||
|
@ -113,6 +113,7 @@ public interface Query {
|
|||||||
* Add stored fields to be added as part of search request
|
* Add stored fields to be added as part of search request
|
||||||
*
|
*
|
||||||
* @param storedFields
|
* @param storedFields
|
||||||
|
* @since 4.4
|
||||||
*/
|
*/
|
||||||
void addStoredFields(String... storedFields);
|
void addStoredFields(String... storedFields);
|
||||||
|
|
||||||
@ -120,6 +121,7 @@ public interface Query {
|
|||||||
* Get stored fields to be returned as part of search request
|
* Get stored fields to be returned as part of search request
|
||||||
*
|
*
|
||||||
* @return null if not set
|
* @return null if not set
|
||||||
|
* @since 4.4
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
List<String> getStoredFields();
|
List<String> getStoredFields();
|
||||||
@ -128,6 +130,7 @@ public interface Query {
|
|||||||
* Set stored fields to be returned as part of search request
|
* Set stored fields to be returned as part of search request
|
||||||
*
|
*
|
||||||
* @param storedFields
|
* @param storedFields
|
||||||
|
* @since 4.4
|
||||||
*/
|
*/
|
||||||
void setStoredFields(@Nullable List<String> storedFields);
|
void setStoredFields(@Nullable List<String> storedFields);
|
||||||
|
|
||||||
|
@ -474,28 +474,38 @@ public class CriteriaQueryMappingUnitTests {
|
|||||||
|
|
||||||
// region test entities
|
// region test entities
|
||||||
static class Person {
|
static class Person {
|
||||||
@Nullable @Id String id;
|
@Nullable
|
||||||
@Nullable @Field(name = "first-name") String firstName;
|
@Id String id;
|
||||||
@Nullable @Field(name = "last-name") String lastName;
|
@Nullable
|
||||||
@Nullable @MultiField(mainField = @Field(name = "nick-name"),
|
@Field(name = "first-name") String firstName;
|
||||||
|
@Nullable
|
||||||
|
@Field(name = "last-name") String lastName;
|
||||||
|
@Nullable
|
||||||
|
@MultiField(mainField = @Field(name = "nick-name"),
|
||||||
otherFields = { @InnerField(suffix = "keyword", type = FieldType.Keyword) }) String nickName;
|
otherFields = { @InnerField(suffix = "keyword", type = FieldType.Keyword) }) String nickName;
|
||||||
@Nullable @Field(name = "created-date", type = FieldType.Date, format = DateFormat.epoch_millis) Date createdDate;
|
@Nullable
|
||||||
@Nullable @Field(name = "birth-date", type = FieldType.Date, format = {},
|
@Field(name = "created-date", type = FieldType.Date, format = DateFormat.epoch_millis) Date createdDate;
|
||||||
pattern = "dd.MM.uuuu") LocalDate birthDate;
|
@Nullable
|
||||||
|
@Field(name = "birth-date", type = FieldType.Date, format = {}, pattern = "dd.MM.uuuu") LocalDate birthDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class House {
|
static class House {
|
||||||
@Nullable @Id String id;
|
@Nullable
|
||||||
@Nullable @Field(name = "per-sons", type = FieldType.Nested) List<Person> persons;
|
@Id String id;
|
||||||
|
@Nullable
|
||||||
|
@Field(name = "per-sons", type = FieldType.Nested) List<Person> persons;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ObjectWithPerson {
|
static class ObjectWithPerson {
|
||||||
@Nullable @Id String id;
|
@Nullable
|
||||||
@Nullable @Field(name = "per-sons", type = FieldType.Object) List<Person> persons;
|
@Id String id;
|
||||||
|
@Nullable
|
||||||
|
@Field(name = "per-sons", type = FieldType.Object) List<Person> persons;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class GeoShapeEntity {
|
static class GeoShapeEntity {
|
||||||
@Nullable @Field(name = "geo-shape-field") GeoJson<?> geoShapeField;
|
@Nullable
|
||||||
|
@Field(name = "geo-shape-field") GeoJson<?> geoShapeField;
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
||||||
|
@ -552,19 +552,24 @@ class RequestFactoryTests {
|
|||||||
@DisplayName("should set stored fields on SearchRequest")
|
@DisplayName("should set stored fields on SearchRequest")
|
||||||
void shouldSetStoredFieldsOnSearchRequest() {
|
void shouldSetStoredFieldsOnSearchRequest() {
|
||||||
|
|
||||||
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withStoredFields("lastName", "location").build();
|
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withStoredFields("lastName", "location")
|
||||||
|
.build();
|
||||||
|
|
||||||
SearchRequest searchRequest = requestFactory.searchRequest(query, Person.class, IndexCoordinates.of("persons"));
|
SearchRequest searchRequest = requestFactory.searchRequest(query, Person.class, IndexCoordinates.of("persons"));
|
||||||
|
|
||||||
assertThat(searchRequest.source().storedFields()).isNotNull();
|
assertThat(searchRequest.source().storedFields()).isNotNull();
|
||||||
assertThat(searchRequest.source().storedFields().fieldNames()).isEqualTo(Arrays.asList("last-name", "current-location"));
|
assertThat(searchRequest.source().storedFields().fieldNames())
|
||||||
|
.isEqualTo(Arrays.asList("last-name", "current-location"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// region entities
|
// region entities
|
||||||
static class Person {
|
static class Person {
|
||||||
@Nullable @Id String id;
|
@Nullable
|
||||||
@Nullable @Field(name = "last-name") String lastName;
|
@Id String id;
|
||||||
@Nullable @Field(name = "current-location") GeoPoint location;
|
@Nullable
|
||||||
|
@Field(name = "last-name") String lastName;
|
||||||
|
@Nullable
|
||||||
|
@Field(name = "current-location") GeoPoint location;
|
||||||
|
|
||||||
public Person() {}
|
public Person() {}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user