|
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 { |
@@ -1911,6 +1935,31 @@ public void setField5(@Nullable LocalDateTime field5) { |
1911 | 1935 | } |
1912 | 1936 | } |
1913 | 1937 |
|
| 1938 | + private static class DateRangeEntity { |
| 1939 | + @Nullable |
| 1940 | + @Id private String id; |
| 1941 | + @Nullable |
| 1942 | + @Field(type = Date_Range, format = DateFormat.date) private Range<LocalDateTime> field2; |
| 1943 | + |
| 1944 | + @Nullable |
| 1945 | + public String getId() { |
| 1946 | + return id; |
| 1947 | + } |
| 1948 | + |
| 1949 | + public void setId(@Nullable String id) { |
| 1950 | + this.id = id; |
| 1951 | + } |
| 1952 | + |
| 1953 | + @Nullable |
| 1954 | + public Range<LocalDateTime> getField2() { |
| 1955 | + return field2; |
| 1956 | + } |
| 1957 | + |
| 1958 | + public void setField2(@Nullable Range<LocalDateTime> field2) { |
| 1959 | + this.field2 = field2; |
| 1960 | + } |
| 1961 | + } |
| 1962 | + |
1914 | 1963 | @Document(indexName = "magazine") |
1915 | 1964 | private static class Magazine { |
1916 | 1965 | @Id @Nullable private String id; |
|
0 commit comments