DATAES-828 - Fields of type date need to have a format defined.
Original PR: #457
This commit is contained in:
committed by
GitHub
parent
c7339dc248
commit
aaef626684
@@ -34,6 +34,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
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.core.mapping.IndexCoordinates;
|
||||
@@ -146,7 +147,7 @@ public class LogEntityTests {
|
||||
|
||||
@Field(type = Ip) private String ip;
|
||||
|
||||
@Field(type = Date) private java.util.Date date;
|
||||
@Field(type = Date, format = DateFormat.date_time) private java.util.Date date;
|
||||
|
||||
private LogEntity() {}
|
||||
|
||||
|
||||
@@ -859,7 +859,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
|
||||
@Nullable @Id private String id;
|
||||
|
||||
@Nullable @Field(type = FieldType.Date, index = false) private Date createdDate;
|
||||
@Nullable @Field(type = FieldType.Date, format = DateFormat.date_time, index = false) private Date createdDate;
|
||||
|
||||
@Nullable
|
||||
public String getId() {
|
||||
|
||||
@@ -41,10 +41,10 @@ public class SimpleElasticsearchDateMappingTests extends MappingContextBaseTests
|
||||
|
||||
private static final String EXPECTED_MAPPING = "{\"properties\":{\"message\":{\"store\":true,"
|
||||
+ "\"type\":\"text\",\"index\":false,\"analyzer\":\"standard\"},\"customFormatDate\":{\"type\":\"date\",\"format\":\"dd.MM.uuuu hh:mm\"},"
|
||||
+ "\"defaultFormatDate\":{\"type\":\"date\"},\"basicFormatDate\":{\""
|
||||
+ "\"basicFormatDate\":{\""
|
||||
+ "type\":\"date\",\"format\":\"basic_date\"}}}";
|
||||
|
||||
@Test // DATAES-568
|
||||
@Test // DATAES-568, DATAES-828
|
||||
public void testCorrectDateMappings() {
|
||||
|
||||
String mapping = getMappingBuilder().buildPropertyMapping(SampleDateMappingEntity.class);
|
||||
@@ -67,8 +67,6 @@ public class SimpleElasticsearchDateMappingTests extends MappingContextBaseTests
|
||||
@Field(type = Date, format = DateFormat.custom,
|
||||
pattern = "dd.MM.uuuu hh:mm") private LocalDateTime customFormatDate;
|
||||
|
||||
@Field(type = FieldType.Date) private LocalDateTime defaultFormatDate;
|
||||
|
||||
@Field(type = FieldType.Date, format = DateFormat.basic_date) private LocalDateTime basicFormatDate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,6 +173,20 @@ public class SimpleElasticsearchPersistentPropertyUnitTests {
|
||||
assertThat(seqNoProperty.isReadable()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAES-828
|
||||
void shouldRequireFormatForDateField() {
|
||||
assertThatExceptionOfType(MappingException.class) //
|
||||
.isThrownBy(() -> context.getRequiredPersistentEntity(DateFieldWithNoFormat.class)) //
|
||||
.withMessageContaining("date");
|
||||
}
|
||||
|
||||
@Test // DATAES-828
|
||||
void shouldRequireFormatForDateNanosField() {
|
||||
assertThatExceptionOfType(MappingException.class) //
|
||||
.isThrownBy(() -> context.getRequiredPersistentEntity(DateNanosFieldWithNoFormat.class)) //
|
||||
.withMessageContaining("date");
|
||||
}
|
||||
|
||||
static class InvalidScoreProperty {
|
||||
@Nullable @Score String scoreProperty;
|
||||
}
|
||||
@@ -195,4 +209,12 @@ public class SimpleElasticsearchPersistentPropertyUnitTests {
|
||||
SeqNoPrimaryTerm seqNoPrimaryTerm;
|
||||
String string;
|
||||
}
|
||||
|
||||
static class DateFieldWithNoFormat {
|
||||
@Field(type = FieldType.Date) LocalDateTime datetime;
|
||||
}
|
||||
|
||||
static class DateNanosFieldWithNoFormat {
|
||||
@Field(type = FieldType.Date_Nanos) LocalDateTime datetime;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user