|
23 | 23 |
|
24 | 24 | import java.time.Instant;
|
25 | 25 | import java.time.LocalDate;
|
26 |
| -import java.util.Collection; |
27 |
| -import java.util.Collections; |
28 |
| -import java.util.Date; |
29 |
| -import java.util.HashMap; |
30 |
| -import java.util.HashSet; |
31 |
| -import java.util.List; |
32 |
| -import java.util.Map; |
33 |
| -import java.util.Set; |
| 26 | +import java.util.*; |
34 | 27 |
|
35 | 28 | import org.junit.jupiter.api.BeforeEach;
|
36 | 29 | import org.junit.jupiter.api.DisplayName;
|
@@ -293,15 +286,24 @@ void shouldMapDynamicFields() {
|
293 | 286 |
|
294 | 287 | DynamicFieldDocument document = new DynamicFieldDocument();
|
295 | 288 | document.dynamicFields = Map.of("a_str", randomUUID().toString(), "b_str", randomUUID().toString());
|
| 289 | + document.value = new DynamicFieldDocument.Value(1L, new Date()); |
296 | 290 | operations.save(document);
|
297 | 291 |
|
298 | 292 | // When
|
299 |
| - SearchHits<DynamicFieldDocument> results = operations.search(new StringQuery(MATCH_ALL), DynamicFieldDocument.class); |
| 293 | + SearchHits<DynamicFieldDocument> results = operations.search(new StringQuery(MATCH_ALL), |
| 294 | + DynamicFieldDocument.class); |
300 | 295 |
|
301 | 296 | // Then
|
302 | 297 | assertThat(results.getTotalHits()).isEqualTo(1);
|
303 |
| - assertThat(results.getSearchHits()).first().extracting(SearchHit::getContent).extracting(doc -> doc.dynamicFields) |
| 298 | + assertThat(results.getSearchHits()).first() |
| 299 | + .extracting(SearchHit::getContent) |
| 300 | + .extracting(doc -> doc.dynamicFields) |
304 | 301 | .isEqualTo(document.dynamicFields);
|
| 302 | + assertThat(results.getSearchHits()).first() |
| 303 | + .extracting(SearchHit::getContent) |
| 304 | + .extracting(doc -> doc.value) |
| 305 | + .isEqualTo(document.value); |
| 306 | + |
305 | 307 | documentOperations.delete();
|
306 | 308 | }
|
307 | 309 |
|
@@ -966,6 +968,39 @@ private static class DynamicFieldDocument {
|
966 | 968 | @Id String id;
|
967 | 969 |
|
968 | 970 | @Field(name = "_str", dynamicTemplate = true) private Map<String, String> dynamicFields = new HashMap<>();
|
| 971 | + |
| 972 | + @Nullable |
| 973 | + @Field(name = "obj", dynamicTemplate = true) private Value value; |
| 974 | + |
| 975 | + static class Value { |
| 976 | + @Nullable |
| 977 | + @Field(name = "value_sum", type = FieldType.Long) |
| 978 | + private Long sum; |
| 979 | + |
| 980 | + @Nullable |
| 981 | + @Field(name = "value_date", type = FieldType.Long) |
| 982 | + private Date date; |
| 983 | + |
| 984 | + public Value() { |
| 985 | + } |
| 986 | + |
| 987 | + public Value(Long sum, Date date) { |
| 988 | + this.sum = sum; |
| 989 | + this.date = date; |
| 990 | + } |
| 991 | + |
| 992 | + @Override |
| 993 | + public boolean equals(Object o) { |
| 994 | + if (this == o) return true; |
| 995 | + if (!(o instanceof Value value)) return false; |
| 996 | + return Objects.equals(sum, value.sum) && Objects.equals(date, value.date); |
| 997 | + } |
| 998 | + |
| 999 | + @Override |
| 1000 | + public int hashCode() { |
| 1001 | + return Objects.hash(sum, date); |
| 1002 | + } |
| 1003 | + } |
969 | 1004 | }
|
970 | 1005 | // endregion
|
971 | 1006 | }
|
0 commit comments