|
42 | 42 | import org.springframework.data.annotation.Transient;
|
43 | 43 | import org.springframework.data.elasticsearch.annotations.*;
|
44 | 44 | import org.springframework.data.elasticsearch.core.MappingContextBaseTests;
|
| 45 | +import org.springframework.data.elasticsearch.core.Range; |
45 | 46 | import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
46 | 47 | import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
47 | 48 | import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm;
|
@@ -721,6 +722,29 @@ void shouldMapAccordingToTheAnnotatedProperties() throws JSONException {
|
721 | 722 | assertEquals(expected, mapping, false);
|
722 | 723 | }
|
723 | 724 |
|
| 725 | + @Test // #2102 |
| 726 | + @DisplayName("should write date formats for date range fields") |
| 727 | + void shouldWriteDateFormatsForDateRangeFields() throws JSONException { |
| 728 | + |
| 729 | + String expected = "{\n" + // |
| 730 | + " \"properties\": {\n" + // |
| 731 | + " \"_class\": {\n" + // |
| 732 | + " \"type\": \"keyword\",\n" + // |
| 733 | + " \"index\": false,\n" + // |
| 734 | + " \"doc_values\": false\n" + // |
| 735 | + " },\n" + // |
| 736 | + " \"field2\": {\n" + // |
| 737 | + " \"type\": \"date_range\",\n" + // |
| 738 | + " \"format\": \"date\"\n" + // |
| 739 | + " }\n" + // |
| 740 | + " }\n" + // |
| 741 | + "}\n"; // |
| 742 | + |
| 743 | + String mapping = getMappingBuilder().buildPropertyMapping(DateRangeEntity.class); |
| 744 | + |
| 745 | + assertEquals(expected, mapping, false); |
| 746 | + } |
| 747 | + |
724 | 748 | @Test // #1454
|
725 | 749 | @DisplayName("should write type hints when context is configured to do so")
|
726 | 750 | void shouldWriteTypeHintsWhenContextIsConfiguredToDoSo() throws JSONException {
|
@@ -2045,6 +2069,31 @@ public void setField5(@Nullable LocalDateTime field5) {
|
2045 | 2069 | }
|
2046 | 2070 | }
|
2047 | 2071 |
|
| 2072 | + private static class DateRangeEntity { |
| 2073 | + @Nullable |
| 2074 | + @Id private String id; |
| 2075 | + @Nullable |
| 2076 | + @Field(type = Date_Range, format = DateFormat.date) private Range<LocalDateTime> field2; |
| 2077 | + |
| 2078 | + @Nullable |
| 2079 | + public String getId() { |
| 2080 | + return id; |
| 2081 | + } |
| 2082 | + |
| 2083 | + public void setId(@Nullable String id) { |
| 2084 | + this.id = id; |
| 2085 | + } |
| 2086 | + |
| 2087 | + @Nullable |
| 2088 | + public Range<LocalDateTime> getField2() { |
| 2089 | + return field2; |
| 2090 | + } |
| 2091 | + |
| 2092 | + public void setField2(@Nullable Range<LocalDateTime> field2) { |
| 2093 | + this.field2 = field2; |
| 2094 | + } |
| 2095 | + } |
| 2096 | + |
2048 | 2097 | @Document(indexName = "magazine")
|
2049 | 2098 | private static class Magazine {
|
2050 | 2099 | @Id
|
|
0 commit comments